javax.validation.metadata.BeanDescriptor Java Examples

The following examples show how to use javax.validation.metadata.BeanDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DesktopAbstractField.java    From cuba with Apache License 2.0 6 votes vote down vote up
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()));
        }
    }
}
 
Example #2
Source File: ValueBinder.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void initBeanValidator(Field<?> component, MetaPropertyPath metaPropertyPath) {
    MetaProperty metaProperty = metaPropertyPath.getMetaProperty();

    MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
    Class enclosingJavaClass = propertyEnclosingMetaClass.getJavaClass();

    if (enclosingJavaClass != KeyValueEntity.class
            && !DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
        javax.validation.Validator validator = beanValidation.getValidator();
        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(enclosingJavaClass);

        if (beanDescriptor.isBeanConstrained()) {
            component.addValidator(beanLocator.getPrototype(BeanPropertyValidator.NAME, enclosingJavaClass, metaProperty.getName()));
        }
    }
}
 
Example #3
Source File: TypeSafeActivator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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
		}
	}
}
 
Example #4
Source File: MethodValidator.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #5
Source File: SpringValidatorAdapter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
	Assert.state(this.targetValidator != null, "No target Validator set");
	return this.targetValidator.getConstraintsForClass(clazz);
}
 
Example #6
Source File: SpringValidatorAdapter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
	Assert.state(this.targetValidator != null, "No target Validator set");
	return this.targetValidator.getConstraintsForClass(clazz);
}
 
Example #7
Source File: SpringValidatorAdapter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
	Assert.state(this.targetValidator != null, "No target Validator set");
	return this.targetValidator.getConstraintsForClass(clazz);
}
 
Example #8
Source File: SerializableValidator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public BeanDescriptor getConstraintsForClass(Class<?> clazz)
{
   return validator.getConstraintsForClass(clazz);
}
 
Example #9
Source File: SpringValidatorAdapter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
	Assert.notNull(this.targetValidator, "No target Validator set");
	return this.targetValidator.getConstraintsForClass(clazz);
}
 
Example #10
Source File: NoOpJsr303Validator.java    From backstopper with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
    throw new ValidationException(this.getClass().getName() + " does not implement getConstraintsForClass()");
}
 
Example #11
Source File: AbstractValidationTest.java    From dashbuilder with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
    return null;
}
 
Example #12
Source File: CustomValidatorProvider.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(final Class<?> clazz) {
    return null;
}
 
Example #13
Source File: WrappedValidator.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> aClass) {
    return delegate.getConstraintsForClass(aClass);
}
 
Example #14
Source File: JsonConfiguratorTest.java    From druid-api with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz)
{
  return null;
}