@Override public BeanDescriptor getConstraintsForClass(Class<?> clazz) { Assert.state(this.targetValidator != null, "No target Validator set"); return this.targetValidator.getConstraintsForClass(clazz); }
@Override public BeanDescriptor getConstraintsForClass(Class<?> aClass) { return validator.getConstraintsForClass(aClass); }
@Override public BeanDescriptor getConstraintsForClass(final Class<?> clazz) { return delegate.getConstraintsForClass(clazz); }
@Override public BeanDescriptor getConstraintsForClass(Class<?> clazz) { Assert.state(this.targetValidator != null, "No target Validator set"); return this.targetValidator.getConstraintsForClass(clazz); }
public static PropertyDescriptor extractPropertyDescriptor(FacesContext context, PrimeApplicationContext applicationContext, ValueExpression ve) { if (ve != null) { ELContext elContext = context.getELContext(); ValueReference vr = ValueExpressionAnalyzer.getReference(elContext, ve); if (vr != null) { Validator validator = applicationContext.getValidator(); Object base = vr.getBase(); Object property = vr.getProperty(); if (base != null && property != null) { BeanDescriptor beanDescriptor = validator.getConstraintsForClass(base.getClass()); if (beanDescriptor != null) { return beanDescriptor.getConstraintsForProperty(property.toString()); } } } } return null; } }
boolean activateNotNull, Dialect dialect) { final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass( clazz );
private <T> Set<AnnotatedCallable<? super T>> determineConstrainedCallables(AnnotatedType<T> type) { Set<AnnotatedCallable<? super T>> callables = new HashSet<>(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( type.getJavaClass() ); determineConstrainedConstructors( type, beanDescriptor, callables ); determineConstrainedMethods( type, beanDescriptor, callables ); return callables; }
@Override public List<Constraint> resolveForProperty(String property, Class<?> clazz) { List<Constraint> constraints = new ArrayList<>(); BeanDescriptor beanDescriptor = this.validator.getConstraintsForClass(clazz); PropertyDescriptor propertyDescriptor = beanDescriptor .getConstraintsForProperty(property); if (propertyDescriptor != null) { for (ConstraintDescriptor<?> constraintDescriptor : propertyDescriptor .getConstraintDescriptors()) { constraints.add(new Constraint( constraintDescriptor.getAnnotation().annotationType().getName(), constraintDescriptor.getAttributes())); } } return constraints; }
private void configureRequired(BindingBuilder<BEAN, ?> binding, PropertyDefinition<BEAN, ?> definition, BeanValidator validator) { assert requiredConfigurator != null; Class<?> propertyHolderType = definition.getPropertyHolderType(); BeanDescriptor descriptor = validator.getJavaxBeanValidator() .getConstraintsForClass(propertyHolderType); PropertyDescriptor propertyDescriptor = descriptor .getConstraintsForProperty(definition.getTopLevelName()); if (propertyDescriptor == null) { return; } if (propertyDescriptor.getConstraintDescriptors().stream() .map(ConstraintDescriptor::getAnnotation) .anyMatch(requiredConfigurator)) { binding.getField().setRequiredIndicatorVisible(true); } }
/** * Returns the validation constraints for the specified class * * @param cls Class for which constraints to return * @return The validation bean descriptor */ public BeanDescriptor getConstraintsForClass(Class<?> cls) { return _validator.getConstraintsForClass(cls); }
private static void applyDDL(String prefix, PersistentClass persistentClass, Class<?> clazz, ValidatorFactory factory, Set<Class<?>> groups, boolean activateNotNull) { 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 = false; if ( property != null ) { hasNotNull = applyConstraints( propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull ); 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 ); } //FIXME add collection of components } } }
@Test(expectedExceptions = ValidationException.class) @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "d") public void testUnknownConstructorThrowsException() { Validator validator = TestUtil.getValidatorUnderTest(); validator.getConstraintsForClass( CustomerRepository.class ); } }
@Test(expectedExceptions = ValidationException.class) @SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_PROPERTYLEVELOVERRIDING, id = "g") }) public void testWrongPropertyNameThrowsException() { Validator validator = TestUtil.getValidatorUnderTest(); validator.getConstraintsForClass( User.class ); } }
@Test(expectedExceptions = IllegalArgumentException.class) @SpecAssertion(section = Sections.CONSTRAINTMETADATA_BEANDESCRIPTOR, id = "c") public void testGetConstraintsForNullProperty() { BeanDescriptor beanDescriptor = getValidator().getConstraintsForClass( Order.class ); beanDescriptor.getConstraintsForProperty( null ); }
@Test @SpecAssertion(section = Sections.XML_MAPPING_XSD, id = "a") public void testValidBeanValidation11Mapping() { Validator validator = TestUtil.getConfigurationUnderTest() .addMapping( Version11InMappingXmlTest.class.getResourceAsStream( MAPPING_FILE ) ) .buildValidatorFactory() .getValidator(); assertFalse( validator.getConstraintsForClass( TestEntity.class ).isBeanConstrained() ); } }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_VALIDATOR, id = "a") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_BEANDESCRIPTOR, id = "a") public void testUnconstrainedClass() { BeanDescriptor beanDescriptor = getValidator().getConstraintsForClass( UnconstrainedEntity.class ); assertFalse( beanDescriptor.hasConstraints(), "There should be no direct constraints on the specified bean." ); assertFalse( beanDescriptor.isBeanConstrained(), "Bean should be unconstrained." ); }
@Test @SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_FIELDLEVELOVERRIDING, id = "a"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_FIELDLEVELOVERRIDING, id = "c") }) public void testIgnoreAnnotations() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class ); assertNotNull( beanDescriptor ); PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstname" ); assertNull( propDescriptor, "The annotation defined constraints should be ignored." ); }
@Test @SpecAssertions({ @SpecAssertion(section="3.6", id="d") }) public void testDefaultValidatorBean() throws SystemException { Validator defaultValidator = getInstanceByType(DefaultValidatorInjectedBeanLocal.class).getDefaultValidator(); assert defaultValidator != null; // Check that the ValidatorFactory is at least queryable defaultValidator.getConstraintsForClass(BuiltInBeansTest.class); }
public boolean accepts(ResourceMethod method) { BeanDescriptor bean = methodValidator.getConstraintsForClass(method.getResource().getType()); MethodDescriptor descriptor = bean.getConstraintsForMethod(method.getMethod().getName(), method.getMethod().getParameterTypes()); return descriptor != null && descriptor.hasConstrainedParameters(); }
@Test(expectedExceptions = ConstraintDeclarationException.class) @SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_PROPERTYLEVELOVERRIDING, id = "f") }) public void testGroupConversionsAreAdditiveAndExceptionIsThrownForMultipleConversionWithSameSource() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class ); PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstCreditCard" ); propDescriptor.getGroupConversions(); } }