本文整理汇总了Java中javax.validation.metadata.BeanDescriptor.getConstrainedProperties方法的典型用法代码示例。如果您正苦于以下问题:Java BeanDescriptor.getConstrainedProperties方法的具体用法?Java BeanDescriptor.getConstrainedProperties怎么用?Java BeanDescriptor.getConstrainedProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.metadata.BeanDescriptor
的用法示例。
在下文中一共展示了BeanDescriptor.getConstrainedProperties方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyDDL
import javax.validation.metadata.BeanDescriptor; //导入方法依赖的package包/类
private static void applyDDL(
String prefix,
PersistentClass persistentClass,
Class<?> clazz,
ValidatorFactory factory,
Set<Class<?>> groups,
boolean activateNotNull,
Dialect dialect) {
final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass( clazz );
//no bean level constraints can be applied, go to the properties
for ( PropertyDescriptor propertyDesc : descriptor.getConstrainedProperties() ) {
Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() );
boolean hasNotNull;
if ( property != null ) {
hasNotNull = applyConstraints(
propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect
);
if ( property.isComposite() && propertyDesc.isCascaded() ) {
Class<?> componentClass = ( (Component) property.getValue() ).getComponentClass();
/*
* we can apply not null if the upper component let's us activate not null
* and if the property is not null.
* Otherwise, all sub columns should be left nullable
*/
final boolean canSetNotNullOnColumns = activateNotNull && hasNotNull;
applyDDL(
prefix + propertyDesc.getPropertyName() + ".",
persistentClass, componentClass, factory, groups,
canSetNotNullOnColumns,
dialect
);
}
//FIXME add collection of components
}
}
}
示例2: validate
import javax.validation.metadata.BeanDescriptor; //导入方法依赖的package包/类
@Override
public <T> Set<ConstraintViolation<T>> validate(final T object, final Class<?>... groups) {
final MinijaxConstraintValidatorContext<T> context = new MinijaxConstraintValidatorContext<>(object);
final BeanDescriptor descriptor = getConstraintsForClass(object.getClass());
for (final PropertyDescriptor propertyDescriptor : descriptor.getConstrainedProperties()) {
final Object value = ((MinijaxPropertyDescriptor) propertyDescriptor).getValue(object);
validateProperty(context, propertyDescriptor, value);
}
return context.getResult();
}
示例3: doCreateHelper
import javax.validation.metadata.BeanDescriptor; //导入方法依赖的package包/类
private BeanHelper doCreateHelper(final Class<?> clazz, final JClassType beanType,
final TreeLogger logger, final GeneratorContext context) throws UnableToCompleteException {
BeanHelper helper = this.getBean(beanType);
if (helper == null) {
BeanDescriptor bean;
try {
bean = this.serverSideValidator.getConstraintsForClass(clazz);
} catch (final ValidationException e) {
logger.log(TreeLogger.ERROR, "Unable to create a validator for " + clazz.getCanonicalName()
+ " because " + e.getMessage(), e);
throw new UnableToCompleteException(); // NOPMD
}
helper = new BeanHelper(beanType, clazz, bean);
this.cache.put(helper.getJClass(), helper);
this.writeInterface(context, logger, helper);
// now recurse on all Cascaded elements
for (final PropertyDescriptor p : bean.getConstrainedProperties()) {
// TODO(idol) only bother creating objects for properties that have constrains in the groups
// specified in @GwtValidation, but not others
if (p.isCascaded()) {
this.doCreateHelperForProp(p, helper, logger, context);
}
}
}
return helper;
}
示例4: getConstraintDescriptors
import javax.validation.metadata.BeanDescriptor; //导入方法依赖的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<?>>();
}
示例5: writeBeanDescriptor
import javax.validation.metadata.BeanDescriptor; //导入方法依赖的package包/类
private void writeBeanDescriptor(final SourceWriter sw) {
final BeanDescriptor beanDescriptor = this.beanHelper.getBeanDescriptor();
// private final GwtBeanDescriptor <MyBean> beanDescriptor =
sw.print("private final ");
sw.print(GwtBeanDescriptor.class.getCanonicalName());
sw.print("<" + this.beanHelper.getTypeCanonicalName() + ">");
sw.println(" beanDescriptor = ");
sw.indent();
sw.indent();
// GwtBeanDescriptorImpl.builder(Order.class)
sw.print(GwtBeanDescriptorImpl.class.getCanonicalName());
sw.println(".builder(" + this.beanHelper.getTypeCanonicalName() + ".class)");
sw.indent();
sw.indent();
// .setConstrained(true)
sw.println(".setConstrained(" + beanDescriptor.isBeanConstrained() + ")");
int count = 0;
for (final ConstraintDescriptor<?> constraint : beanDescriptor.getConstraintDescriptors()) {
if (this.areConstraintDescriptorGroupsValid(constraint)) {
// .add(c0)
sw.println(".add(" + this.constraintDescriptorVar("this", count) + ")");
count++;
}
}
// .put("myProperty", myProperty_pd)
for (final PropertyDescriptor p : beanDescriptor.getConstrainedProperties()) {
sw.print(".put(\"");
sw.print(p.getPropertyName());
sw.print("\", ");
sw.print(p.getPropertyName());
sw.println("_pd)");
}
// .setBeanMetadata(beanMetadata)
sw.println(".setBeanMetadata(beanMetadata)");
// .build();
sw.println(".build();");
sw.outdent();
sw.outdent();
sw.outdent();
sw.outdent();
}