本文整理汇总了Java中javax.validation.metadata.BeanDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java BeanDescriptor类的具体用法?Java BeanDescriptor怎么用?Java BeanDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BeanDescriptor类属于javax.validation.metadata包,在下文中一共展示了BeanDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveForProperty
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
@Override
public List<Constraint> resolveForProperty(String property, Class<?> clazz) {
List<Constraint> constraints = new ArrayList<>();
String[] properties = property.split("\\.");
Class<?> clazzforLoop = clazz;
for (int i = 0; i < properties.length; i++) {
String propertyForLoop = properties[i];
propertyForLoop = propertyForLoop.replace("[]", "");
BeanDescriptor beanDescriptor = this.validator.getConstraintsForClass(clazzforLoop);
PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(
propertyForLoop);
if (propertyDescriptor != null) {
if (isLastElement(properties, i)) {
collectConstraints(constraints, propertyDescriptor);
}
clazzforLoop = getFollowUpClass(propertyDescriptor, clazzforLoop);
} else {
break;
}
}
return constraints;
}
示例2: initBeanValidator
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
protected void initBeanValidator() {
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
Class enclosingJavaClass = propertyEnclosingMetaClass.getJavaClass();
if (enclosingJavaClass != KeyValueEntity.class
&& !DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
javax.validation.Validator validator = beanValidation.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(enclosingJavaClass);
if (beanDescriptor.isBeanConstrained()) {
addValidator(new BeanValidator(enclosingJavaClass, metaProperty.getName()));
}
}
}
示例3: getPropertyDescriptor
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
/**
* @return PropertyDescriptor may be null when JavaBean do not have any Bean Validation
* annotations.
*/
private PropertyDescriptor getPropertyDescriptor() throws JspException {
String path = getBindStatus().getPath();
int dotPos = path.indexOf('.');
if (dotPos == -1) {
return null;
}
String beanName = path.substring(0, dotPos);
String expression = path.substring(dotPos + 1);
Map<String, Object> model = getRequestContext().getModel();
Object bean = getBean(beanName, model);
Validator validator = getRequestContext().getWebApplicationContext().getBean(Validator.class);
BeanDescriptor constraints = validator.getConstraintsForClass(bean.getClass());
return constraints.getConstraintsForProperty(expression);
}
示例4: 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
}
}
}
示例5: 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();
}
示例6: validateProperty
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
@Override
public <T> Set<ConstraintViolation<T>> validateProperty(final T object, final String propertyName, final Class<?>... groups) {
final MinijaxConstraintValidatorContext<T> context = new MinijaxConstraintValidatorContext<>(object);
final BeanDescriptor descriptor = getConstraintsForClass(object.getClass());
final PropertyDescriptor propertyDescriptor = descriptor.getConstraintsForProperty(propertyName);
final Object value = ((MinijaxPropertyDescriptor) propertyDescriptor).getValue(object);
validateProperty(context, propertyDescriptor, value);
return context.getResult();
}
示例7: GwtValidationContext
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
private GwtValidationContext(final Class<T> rootBeanClass, final T rootBean,
final BeanDescriptor beanDescriptor, final MessageInterpolator messageInterpolator,
final TraversableResolver traversableResolver, final AbstractGwtValidator validator,
final Set<Object> validatedObjects) {
this.rootBeanClass = rootBeanClass;
this.rootBean = rootBean;
this.beanDescriptor = beanDescriptor;
this.messageInterpolator = messageInterpolator;
this.traversableResolver = traversableResolver;
this.validator = validator;
this.validatedObjects = new HashSet<>(validatedObjects);
}
示例8: compose
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
@Override
protected void compose(final ClassSourceFileComposerFactory composerFactory) {
this.addImports(composerFactory, GWT.class, GwtBeanDescriptor.class, GwtSpecificValidator.class,
GwtValidationContext.class, ValidationGroupsMetadata.class, Set.class, HashSet.class,
Map.class, HashMap.class, Default.class, ConstraintViolation.class, BeanDescriptor.class);
composerFactory.setSuperclass(AbstractGwtValidator.class.getCanonicalName());
composerFactory.addImplementedInterface(this.validatorType.getQualifiedSourceName());
}
示例9: 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;
}
示例10: BeanHelper
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
/**
* Shouldn't be created directly; instead use BeanHelperCache.
*/
BeanHelper(final JClassType pjclass, final Class<?> pclazz,
final BeanDescriptor pbeanDescriptor) {
this.beanDescriptor = pbeanDescriptor;
this.jclass = pjclass;
this.clazz = pclazz;
}
示例11: buildValidator
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
public Validator<?> buildValidator(Class<?> beanClass, String propertyName) {
javax.validation.Validator beanValidator = getDefaultValidator();
if (beanValidator != null) {
BeanDescriptor descriptor = beanValidator.getConstraintsForClass(beanClass);
PropertyDescriptor propDescriptor = descriptor.getConstraintsForProperty(propertyName);
if (propDescriptor != null && propDescriptor.hasConstraints()) {
return new JSR303BeanValidator(beanClass, propertyName);
}
}
return null;
}
示例12: hasConstraints
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
/**
* Only accepts if method isn't parameterless and have at least one constraint.
*/
private boolean hasConstraints(ControllerMethod controllerMethod) {
Method method = controllerMethod.getMethod();
if (method.getParameterTypes().length == 0) {
logger.debug("method {} has no parameters, skipping", controllerMethod);
return false;
}
BeanDescriptor bean = bvalidator.getConstraintsForClass(controllerMethod.getController().getType());
if(bean == null) {
return false;
}
MethodDescriptor descriptor = bean.getConstraintsForMethod(method.getName(), method.getParameterTypes());
return descriptor != null && descriptor.hasConstrainedParameters();
}
示例13: testPropertyDescriptorHasConstraints
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
public void testPropertyDescriptorHasConstraints() {
BeanDescriptor cons = validator.getConstraintsForClass(Book.class);
Assert.assertTrue(cons.getConstraintsForProperty("author").hasConstraints());
Assert.assertTrue(cons.getConstraintsForProperty("title").hasConstraints());
Assert.assertTrue(cons.getConstraintsForProperty("uselessField").hasConstraints());
// cons.getConstraintsForProperty("unconstraintField") == null without
// Introspector
// cons.getConstraintsForProperty("unconstraintField") != null with
// Introspector
assertTrue(cons.getConstraintsForProperty("unconstraintField") == null
|| !cons.getConstraintsForProperty("unconstraintField").hasConstraints());
assertNull(cons.getConstraintsForProperty("unknownField"));
}
示例14: testMetadataAPI_Book
import javax.validation.metadata.BeanDescriptor; //导入依赖的package包/类
public void testMetadataAPI_Book() {
Assert.assertNotNull(validator.getConstraintsForClass(Book.class));
// not necessary for implementation correctness, but we'll test
// nevertheless:
Assert.assertSame(validator.getConstraintsForClass(Book.class), validator.getConstraintsForClass(Book.class));
BeanDescriptor bc = validator.getConstraintsForClass(Book.class);
// assertEquals(ElementType.TYPE, bc.getElementType());
Assert.assertEquals(Book.class, bc.getElementClass());
// assertEquals(false, bc.isCascaded());
// assertEquals("", bc.getPropertyPath());
Assert.assertTrue(bc.getConstraintDescriptors() != null);
TestUtils.failOnModifiable(bc.getConstraintDescriptors(), "beanDescriptor constraintDescriptors");
}
示例15: 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<?>>();
}