本文整理汇总了Java中javax.validation.metadata.PropertyDescriptor.getConstraintDescriptors方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyDescriptor.getConstraintDescriptors方法的具体用法?Java PropertyDescriptor.getConstraintDescriptors怎么用?Java PropertyDescriptor.getConstraintDescriptors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.metadata.PropertyDescriptor
的用法示例。
在下文中一共展示了PropertyDescriptor.getConstraintDescriptors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: describe
import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
/**
* Return the validation descriptors of given bean.
*
* @param className
* the class to describe.
* @return the validation descriptors of given bean.
* @throws ClassNotFoundException
* when the bean is not found.
*/
@GET
public Map<String, List<String>> describe(final String className) throws ClassNotFoundException {
final Class<?> beanClass = Class.forName(className);
final Map<String, List<String>> result = new HashMap<>();
for (final PropertyDescriptor property : validator.getValidator().getConstraintsForClass(beanClass).getConstrainedProperties()) {
final List<String> list = new ArrayList<>();
result.put(property.getPropertyName(), list);
for (final ConstraintDescriptor<?> constraint : property.getConstraintDescriptors()) {
// Since constraints are annotation, get the annotation class (interface)
list.add(constraint.getAnnotation().getClass().getInterfaces()[0].getName());
}
}
return result;
}
示例2: isPropertyConstrained
import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
private boolean isPropertyConstrained(final PropertyDescriptor ppropertyDescription,
final boolean useField) {
// cascaded counts as constrained
// we must know if the @Valid annotation is on a field or a getter
final JClassType jClass = this.beanHelper.getJClass();
if (useField && jClass.findField(ppropertyDescription.getPropertyName())
.isAnnotationPresent(Valid.class)) {
return true;
} else if (!useField && jClass.findMethod(asGetter(ppropertyDescription), NO_ARGS)
.isAnnotationPresent(Valid.class)) {
return true;
}
// for non-cascaded properties
for (final ConstraintDescriptor<?> constraint : ppropertyDescription
.getConstraintDescriptors()) {
final org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?> constraintHibernate =
(org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?>) constraint;
if (constraintHibernate
.getElementType() == (useField ? ElementType.FIELD : ElementType.METHOD)) {
return true;
}
}
return false;
}
示例3: validatePropertyConstraints
import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T> void validatePropertyConstraints(
final MinijaxConstraintValidatorContext<T> context,
final PropertyDescriptor property,
final Object value) {
for (final ConstraintDescriptor constraint : property.getConstraintDescriptors()) {
final ConstraintValidator validator = ((MinijaxConstraintDescriptor) constraint).getValidator();
if (!validator.isValid(value, context)) {
context.buildViolation(constraint, value);
}
}
}
示例4: collectConstraints
import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
private void collectConstraints(List<Constraint> constraints,
PropertyDescriptor propertyDescriptor) {
for (ConstraintDescriptor<?> constraintDescriptor : propertyDescriptor
.getConstraintDescriptors()) {
constraints.add(new Constraint(constraintDescriptor.getAnnotation()
.annotationType()
.getName(), constraintDescriptor.getAttributes()));
}
}
示例5: constrainteByAnnotationType
import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
private Map<Class<? extends Annotation>, ConstraintDescriptor<?>> constrainteByAnnotationType(
PropertyDescriptor propertyDescriptor) {
Map<Class<? extends Annotation>, ConstraintDescriptor<?>> annotationMap = new HashMap<Class<? extends Annotation>, ConstraintDescriptor<?>>();
Set<ConstraintDescriptor<?>> constraintDescriptors = propertyDescriptor.getConstraintDescriptors();
for (ConstraintDescriptor<?> constraintDescriptor : constraintDescriptors) {
annotationMap.put(constraintDescriptor.getAnnotation().annotationType(), constraintDescriptor);
}
return annotationMap;
}
示例6: getConstraintDescriptors
import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
@Override
public Set<ConstraintDescriptor<?>> getConstraintDescriptors(final Object keyObj) {
String key = String.valueOf(keyObj);
final Validator validator = Validation.byDefaultProvider().configure().buildValidatorFactory().getValidator();
BeanDescriptor beanDesc = validator.getConstraintsForClass(getClass());
for(PropertyDescriptor prop : beanDesc.getConstrainedProperties()) {
if(prop.getPropertyName().equalsIgnoreCase(key)) {
return prop.getConstraintDescriptors();
}
}
return new HashSet<ConstraintDescriptor<?>>();
}
示例7: writePropertyDescriptor
import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
private void writePropertyDescriptor(final SourceWriter sw,
final PropertyDescriptor ppropertyDescription) {
// private final PropertyDescriptor myProperty_pd =
sw.print("private final ");
sw.print(PropertyDescriptorImpl.class.getCanonicalName());
sw.print(" ");
sw.print(ppropertyDescription.getPropertyName());
sw.println("_pd =");
sw.indent();
sw.indent();
// new PropertyDescriptorImpl(
sw.println("new " + PropertyDescriptorImpl.class.getCanonicalName() + "(");
sw.indent();
sw.indent();
// "myProperty",
sw.println("\"" + ppropertyDescription.getPropertyName() + "\",");
// MyType.class,
sw.println(ppropertyDescription.getElementClass().getCanonicalName() + ".class,");
// isCascaded,
sw.print(Boolean.toString(ppropertyDescription.isCascaded()) + ",");
// beanMetadata,
sw.print("beanMetadata");
// myProperty_c0,
// myProperty_c1 );
int count = 0;
for (final ConstraintDescriptor<?> constraint : ppropertyDescription
.getConstraintDescriptors()) {
if (this.areConstraintDescriptorGroupsValid(constraint)) {
sw.println(","); // Print the , for the previous line
sw.print(this.constraintDescriptorVar(ppropertyDescription.getPropertyName(), count));
count++;
}
}
sw.println(");");
sw.outdent();
sw.outdent();
sw.outdent();
sw.outdent();
}