Java Code Examples for javax.validation.metadata.BeanDescriptor

The following examples show how to use javax.validation.metadata.BeanDescriptor. These examples are extracted from open source projects. 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 Project: cuba   Source File: DesktopAbstractField.java    License: 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 Project: cuba   Source File: ValueBinder.java    License: 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 Project: lams   Source File: TypeSafeActivator.java    License: 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 Project: vraptor4   Source File: MethodValidator.java    License: 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 Project: spring-analysis-note   Source File: SpringValidatorAdapter.java    License: 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 Project: java-technology-stack   Source File: SpringValidatorAdapter.java    License: 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 Project: lams   Source File: SpringValidatorAdapter.java    License: 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 Project: lams   Source File: SerializableValidator.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public BeanDescriptor getConstraintsForClass(Class<?> clazz)
{
   return validator.getConstraintsForClass(clazz);
}
 
Example 9
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
	Assert.notNull(this.targetValidator, "No target Validator set");
	return this.targetValidator.getConstraintsForClass(clazz);
}
 
Example 10
Source Project: backstopper   Source File: NoOpJsr303Validator.java    License: 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 Project: dashbuilder   Source File: AbstractValidationTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
    return null;
}
 
Example 12
Source Project: tomee   Source File: CustomValidatorProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(final Class<?> clazz) {
    return null;
}
 
Example 13
Source Project: wisdom   Source File: WrappedValidator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> aClass) {
    return delegate.getConstraintsForClass(aClass);
}
 
Example 14
Source Project: druid-api   Source File: JsonConfiguratorTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz)
{
  return null;
}