Author: hardy.ferentschik
Date: 2009-04-09 12:07:22 -0400 (Thu, 09 Apr 2009)
New Revision: 16287
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorDefinitionsCache.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml
Log:
HV-112
Added support for constraint validator configuration.
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-04-09
12:23:07 UTC (rev 16286)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -279,13 +279,13 @@
return propertyDescriptor;
}
- private <A extends Annotation> void initClassConstraints(Class clazz,
AnnotationIgnores annotationIgnores) {
+ private <A extends Annotation> void initClassConstraints(Class<?> clazz,
AnnotationIgnores annotationIgnores) {
if ( annotationIgnores.isIgnoreAnnotations( clazz ) ) {
return;
}
List<ConstraintDescriptorImpl> classMetadata = findClassLevelConstraints( clazz
);
for ( ConstraintDescriptorImpl constraintDescription : classMetadata ) {
- MetaConstraint<T, A> metaConstraint = new MetaConstraint<T, A>( clazz,
constraintDescription );
+ MetaConstraint<T, A> metaConstraint = new MetaConstraint<T, A>( beanClass,
constraintDescription );
metaConstraintList.add( metaConstraint );
}
}
@@ -304,7 +304,7 @@
List<Annotation> constraints = new ArrayList<Annotation>();
if ( constraintHelper.isConstraintAnnotation( annotation ) ||
- constraintHelper.isBuiltinConstraint( annotation ) ) {
+ constraintHelper.isBuiltinConstraint( annotation.annotationType() ) ) {
constraints.add( annotation );
}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-04-09
12:23:07 UTC (rev 16286)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -265,9 +265,21 @@
xmlParameters.constraintValidatorFactory = clazz.newInstance();
log.info( "Using {} as constraint factory.", constraintFactoryClass );
}
- catch ( Exception e ) {
- throw new ValidationException( "Unable to instantiate message interpolator class
" + constraintFactoryClass + "." );
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException(
+ "Unable to instantiate constraint factory class " +
constraintFactoryClass + ".", e
+ );
}
+ catch ( InstantiationException e ) {
+ throw new ValidationException(
+ "Unable to instantiate constraint factory class " +
constraintFactoryClass + ".", e
+ );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException(
+ "Unable to instantiate constraint factory class " +
constraintFactoryClass + ".", e
+ );
+ }
}
}
@@ -310,9 +322,21 @@
xmlParameters.messageInterpolator = clazz.newInstance();
log.info( "Using {} as message interpolator.", messageInterpolatorClass );
}
- catch ( Exception e ) {
- throw new ValidationException( "Unable to instantiate message interpolator class
" + messageInterpolatorClass + "." );
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException(
+ "Unable to instantiate message interpolator class " +
messageInterpolatorClass + ".", e
+ );
}
+ catch ( InstantiationException e ) {
+ throw new ValidationException(
+ "Unable to instantiate message interpolator class " +
messageInterpolatorClass + ".", e
+ );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException(
+ "Unable to instantiate message interpolator class " +
messageInterpolatorClass + ".", e
+ );
+ }
}
}
@@ -327,9 +351,21 @@
xmlParameters.traversableResolver = clazz.newInstance();
log.info( "Using {} as traversable resolver.", traversableResolverClass );
}
- catch ( Exception e ) {
- throw new ValidationException( "Unable to instantiate message interpolator class
" + traversableResolverClass + "." );
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException(
+ "Unable to instantiate traversable resolver class " +
traversableResolverClass + ".", e
+ );
}
+ catch ( InstantiationException e ) {
+ throw new ValidationException(
+ "Unable to instantiate traversable resolver class " +
traversableResolverClass + ".", e
+ );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException(
+ "Unable to instantiate traversable resolver class " +
traversableResolverClass + ".", e
+ );
+ }
}
}
@@ -398,7 +434,7 @@
return schema;
}
- private class ParameterHolder {
+ private static class ParameterHolder {
ConstraintValidatorFactory constraintValidatorFactory;
MessageInterpolator messageInterpolator;
TraversableResolver traversableResolver;
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-04-09
12:23:07 UTC (rev 16286)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -113,28 +113,43 @@
ReportAsSingleViolation.class
);
- findConstraintClasses();
+ findConstraintValidatorClasses();
Map<ClassIndexWrapper, Map<String, Object>> overrideParameters =
parseOverrideParameters();
parseComposingConstraints( overrideParameters );
}
- private void findConstraintClasses() {
- if ( constraintHelper.isBuiltinConstraint( annotation ) ) {
- constraintValidatorDefinitonClasses.addAll( constraintHelper.getBuiltInConstraints(
annotation ) );
+ private void findConstraintValidatorClasses() {
+ if ( ConstraintValidatorDefinitionsCache.containsConstraintValidatorDefinition(
annotation.annotationType())) {
+ for ( Class<? extends ConstraintValidator<? extends Annotation, ?>>
validator : ConstraintValidatorDefinitionsCache
+ .getConstraintValidatorDefinition(
+ annotation.annotationType()
+ ) ) {
+ constraintValidatorDefinitonClasses.add( ( Class<? extends
ConstraintValidator<T, ?>> ) validator );
+ }
+ return;
}
+
+ List<Class<? extends ConstraintValidator<? extends Annotation, ?>>>
constraintDefinitonClasses = new ArrayList<Class<? extends ConstraintValidator<?
extends Annotation, ?>>>();
+ if ( constraintHelper.isBuiltinConstraint( annotation.annotationType() ) ) {
+ constraintDefinitonClasses.addAll( constraintHelper.getBuiltInConstraints(
annotation.annotationType() ) );
+ }
else {
final Class<? extends Annotation> annotationType = annotation.annotationType();
Class<? extends ConstraintValidator<?, ?>>[] validatedBy = annotationType
.getAnnotation( Constraint.class )
.validatedBy();
- for ( Class<? extends ConstraintValidator<?, ?>> validator : validatedBy )
{
- //FIXME does this create a CCE at runtime?
- //FIXME if yes wrap into VE, if no we need to test the type here
- //Once resolved,we can @SuppressWarning("unchecked") on the cast
- Class<? extends ConstraintValidator<T, ?>> safeValidator = ( Class<?
extends ConstraintValidator<T, ?>> ) validator;
- constraintValidatorDefinitonClasses.add( safeValidator );
- }
+ constraintDefinitonClasses.addAll( Arrays.asList( validatedBy ) );
}
+
+ ConstraintValidatorDefinitionsCache.addConstraintValidatorDefinition(
+ annotation.annotationType(), constraintDefinitonClasses
+ );
+
+ for ( Class<? extends ConstraintValidator<? extends Annotation, ?>>
validator : constraintDefinitonClasses ) {
+ @SuppressWarnings("unchecked")
+ Class<? extends ConstraintValidator<T, ?>> safeValidator = ( Class<?
extends ConstraintValidator<T, ?>> ) validator;
+ constraintValidatorDefinitonClasses.add( safeValidator );
+ }
}
public T getAnnotation() {
@@ -239,7 +254,7 @@
private void parseComposingConstraints(Map<ClassIndexWrapper, Map<String,
Object>> overrideParameters) {
for ( Annotation declaredAnnotation :
annotation.annotationType().getDeclaredAnnotations() ) {
if ( constraintHelper.isConstraintAnnotation( declaredAnnotation )
- || constraintHelper.isBuiltinConstraint( declaredAnnotation ) ) {
+ || constraintHelper.isBuiltinConstraint( declaredAnnotation.annotationType() ) ) {
ConstraintDescriptorImpl<?> descriptor = createComposingConstraintDescriptor(
declaredAnnotation, overrideParameters, OVERRIDES_PARAMETER_DEFAULT_INDEX
);
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java 2009-04-09
12:23:07 UTC (rev 16286)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -132,30 +132,32 @@
builtinConstraints.put( Pattern.class, constraintList );
}
- public <T extends Annotation> List<Class<? extends ConstraintValidator<T,
?>>> getBuiltInConstraints(T annotation) {
- final List<Class<? extends ConstraintValidator<?, ?>>> builtInList =
getBuiltInFromAnnotationType( annotation.annotationType() );
+ public List<Class<? extends ConstraintValidator<? extends Annotation,
?>>> getBuiltInConstraints(Class<? extends Annotation> annotationType) {
+ final List<Class<? extends ConstraintValidator<?, ?>>> builtInList =
getBuiltInFromAnnotationType(
+ annotationType
+ );
- if (builtInList == null || builtInList.size() == 0) {
- throw new ValidationException( "Unable to find constraints for " +
annotation.annotationType() );
+ if ( builtInList == null || builtInList.size() == 0 ) {
+ throw new ValidationException( "Unable to find constraints for " +
annotationType );
}
- List<Class<? extends ConstraintValidator<T, ?>>> constraints =
- new ArrayList<Class<? extends ConstraintValidator<T, ?>>>(
builtInList.size() );
- for (Class<? extends ConstraintValidator<?, ?>> validatorClass :
builtInList) {
+ List<Class<? extends ConstraintValidator<? extends Annotation, ?>>>
constraints =
+ new ArrayList<Class<? extends ConstraintValidator<? extends Annotation,
?>>>( builtInList.size() );
+ for ( Class<? extends ConstraintValidator<?, ?>> validatorClass :
builtInList ) {
//safe cause all CV for a given annotation A are CV<A, ?>
- @SuppressWarnings( "unchecked" )
- Class<ConstraintValidator<T, ?>> safeValdiatorClass =
(Class<ConstraintValidator<T, ?>>) validatorClass;
+ @SuppressWarnings("unchecked")
+ Class<ConstraintValidator<? extends Annotation, ?>> safeValdiatorClass = (
Class<ConstraintValidator<? extends Annotation, ?>> ) validatorClass;
constraints.add( safeValdiatorClass );
}
return constraints;
}
- private List<Class<? extends ConstraintValidator<?, ?>>>
getBuiltInFromAnnotationType(Class<?> annotationType) {
+ private List<Class<? extends ConstraintValidator<? , ?>>>
getBuiltInFromAnnotationType(Class<? extends Annotation> annotationType) {
return builtinConstraints.get( annotationType );
}
- public boolean isBuiltinConstraint(Annotation annotation) {
- return builtinConstraints.containsKey( annotation.annotationType() );
+ public boolean isBuiltinConstraint(Class<? extends Annotation> annotationType) {
+ return builtinConstraints.containsKey( annotationType );
}
/**
@@ -174,7 +176,7 @@
if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
Annotation[] annotations = ( Annotation[] ) m.invoke( annotation );
for ( Annotation a : annotations ) {
- if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a ) ) {
+ if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a.annotationType() ) ) {
isMultiValueConstraint = true;
}
else {
@@ -213,7 +215,7 @@
if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
Annotation[] annotations = ( Annotation[] ) m.invoke( annotation );
for ( Annotation a : annotations ) {
- if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a ) ) {
+ if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a.annotationType() ) ) {
annotationList.add( a );
}
}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java 2009-04-09
12:23:07 UTC (rev 16286)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorDefinitionsCache.java
(from rev 16270,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataCache.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorDefinitionsCache.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorDefinitionsCache.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -0,0 +1,48 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.engine;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.validation.ConstraintValidator;
+
+/**
+ * Caches the constraint classes for a given annotation.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ConstraintValidatorDefinitionsCache {
+ private static final Map<Class<? extends Annotation>, List<Class<?
extends ConstraintValidator<? extends Annotation, ?>>>>
constraintValidatorDefinitons = new HashMap<Class<? extends Annotation>,
List<Class<? extends ConstraintValidator<? extends Annotation,
?>>>>();
+
+ public static List<Class<? extends ConstraintValidator<? extends Annotation,
?>>> getConstraintValidatorDefinition(Class<? extends Annotation>
annotationClass) {
+ if ( annotationClass == null ) {
+ throw new IllegalArgumentException( "Class cannot be null" );
+ }
+ return constraintValidatorDefinitons.get( annotationClass );
+ }
+
+ public static <A extends Annotation> void
addConstraintValidatorDefinition(Class<A> annotationClass, List<Class<?
extends ConstraintValidator<? extends Annotation, ?>>> definitionClasses) {
+ constraintValidatorDefinitons.put( annotationClass, definitionClasses );
+ }
+
+ public static boolean containsConstraintValidatorDefinition(Class<? extends
Annotation> annotationClass) {
+ return constraintValidatorDefinitons.containsKey( annotationClass );
+ }
+}
\ No newline at end of file
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java 2009-04-09
12:23:07 UTC (rev 16286)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -57,8 +57,8 @@
while ( providerDefinitions.hasMoreElements() ) {
URL url = providerDefinitions.nextElement();
InputStream stream = url.openStream();
+ BufferedReader reader = new BufferedReader( new InputStreamReader( stream ), 100 );
try {
- BufferedReader reader = new BufferedReader( new InputStreamReader( stream ), 100
);
name = reader.readLine();
while ( name != null ) {
name = name.trim();
@@ -76,7 +76,7 @@
}
}
finally {
- stream.close();
+ reader.close();
}
}
}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java 2009-04-09
12:23:07 UTC (rev 16286)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -32,6 +32,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
@@ -58,6 +60,7 @@
import org.hibernate.validation.xml.AnnotationType;
import org.hibernate.validation.xml.BeanType;
import org.hibernate.validation.xml.ClassType;
+import org.hibernate.validation.xml.ConstraintDefinitionType;
import org.hibernate.validation.xml.ConstraintMappingsType;
import org.hibernate.validation.xml.ConstraintType;
import org.hibernate.validation.xml.ElementType;
@@ -65,6 +68,7 @@
import org.hibernate.validation.xml.GetterType;
import org.hibernate.validation.xml.GroupSequenceType;
import org.hibernate.validation.xml.GroupsType;
+import org.hibernate.validation.xml.ValidatedByType;
/**
* @author Emmanuel Bernard
@@ -76,12 +80,12 @@
private static final String VALIDATION_MAPPING_XSD =
"META-INF/validation-mapping-1.0.xsd";
private static final String MESSAGE_PARAM = "message";
private static final String GROUPS_PARAM = "groups";
+ private static final String PACKAGE_SEPERATOR = ".";
private final MessageInterpolator messageInterpolator;
private final TraversableResolver traversableResolver;
private final ConstraintValidatorFactory constraintValidatorFactory;
private final ConstraintHelper constraintHelper = new ConstraintHelper();
- private static final String PACKAGE_SEPERATOR = ".";
private final Set<Class<?>> processedClasses = new
HashSet<Class<?>>();
@@ -143,9 +147,10 @@
private void parseMappingFiles(Set<InputStream> mappingStreams) {
for ( InputStream in : mappingStreams ) {
try {
- ConstraintMappingsType mappings = getValidationConfig( in );
- String defaultPackage = mappings.getDefaultPackage();
- for ( BeanType bean : mappings.getBean() ) {
+ ConstraintMappingsType mapping = getValidationConfig( in );
+ parseConstraintDefinitions( mapping.getConstraintDefinition() );
+ String defaultPackage = mapping.getDefaultPackage();
+ for ( BeanType bean : mapping.getBean() ) {
Class<?> beanClass = getClass( bean.getClazz(), defaultPackage );
checkClassHasNotBeenProcessed( processedClasses, beanClass );
annotationIgnores.setDefaultIgnoreAnnotation( beanClass, bean.isIgnoreAnnotations()
);
@@ -166,6 +171,44 @@
}
}
+ private void parseConstraintDefinitions(List<ConstraintDefinitionType>
constraintDefinitionList) {
+ for ( ConstraintDefinitionType constraintDefinition : constraintDefinitionList ) {
+ String annotationClassName = constraintDefinition.getAnnotation();
+ Class<? extends Annotation> annotationClass;
+ try {
+ annotationClass = ( Class<? extends Annotation> )
ReflectionHelper.classForName(
+ annotationClassName, this.getClass()
+ );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException( "Unable to load class " +
annotationClassName );
+ }
+
+ ValidatedByType validatedByType = constraintDefinition.getValidatedBy();
+ List<Class<? extends ConstraintValidator<? extends Annotation, ?>>>
constraintValidatorClasses = new ArrayList<Class<? extends ConstraintValidator<?
extends Annotation, ?>>>();
+ if ( validatedByType.isIncludeExistingValidators() != null &&
validatedByType.isIncludeExistingValidators() ) {
+ constraintValidatorClasses.addAll( findConstraintValidatorClasses( annotationClass )
);
+ }
+ for ( String validatorClassName : validatedByType.getValue() ) {
+ Class<? extends ConstraintValidator<?, ?>> validatorClass;
+ try {
+ // TODO validate this class!
+ validatorClass = ( Class<? extends ConstraintValidator<?, ?>> )
ReflectionHelper.classForName(
+ validatorClassName,
+ this.getClass()
+ );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException( "Unable to load class " +
validatorClassName );
+ }
+ constraintValidatorClasses.add( validatorClass );
+ }
+ ConstraintValidatorDefinitionsCache.addConstraintValidatorDefinition(
+ annotationClass, constraintValidatorClasses
+ );
+ }
+ }
+
private void checkClassHasNotBeenProcessed(Set<Class<?>> processedClasses,
Class<?> beanClass) {
if ( processedClasses.contains( beanClass ) ) {
throw new ValidationException( beanClass.getName() + " has already be configured
in xml." );
@@ -557,4 +600,24 @@
BeanMetaDataCache.addBeanMetaData( beanClass, metaData );
}
}
+
+ private List<Class<? extends ConstraintValidator<? extends Annotation,
?>>> findConstraintValidatorClasses(Class<? extends Annotation>
annotationType) {
+ List<Class<? extends ConstraintValidator<? extends Annotation, ?>>>
constraintValidatorDefinitonClasses = new ArrayList<Class<? extends
ConstraintValidator<? extends Annotation, ?>>>();
+ if ( constraintHelper.isBuiltinConstraint( annotationType ) ) {
+ constraintValidatorDefinitonClasses.addAll( constraintHelper.getBuiltInConstraints(
annotationType ) );
+ }
+ else {
+ Class<? extends ConstraintValidator<?, ?>>[] validatedBy = annotationType
+ .getAnnotation( Constraint.class )
+ .validatedBy();
+ for ( Class<? extends ConstraintValidator<?, ?>> validator : validatedBy )
{
+ //FIXME does this create a CCE at runtime?
+ //FIXME if yes wrap into VE, if no we need to test the type here
+ //Once resolved,we can @SuppressWarning("unchecked") on the cast
+ Class<? extends ConstraintValidator<? extends Annotation, ?>>
safeValidator = validator;
+ constraintValidatorDefinitonClasses.add( safeValidator );
+ }
+ }
+ return constraintValidatorDefinitonClasses;
+ }
}
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java 2009-04-09
16:07:22 UTC (rev 16287)
@@ -0,0 +1,36 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.engine.xml;
+
+import javax.validation.ConstraintValidatorContext;
+
+import org.slf4j.Logger;
+
+import org.hibernate.validation.util.LoggerFactory;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CustomConsistentUserValidator extends ConsistentUserValidator {
+ private static final Logger log = LoggerFactory.make();
+
+ public boolean isValid(User user, ConstraintValidatorContext constraintValidatorContext)
{
+ log.debug( "is valid in CustomConsistentUserValidator is called." );
+ return super.isValid( user, constraintValidatorContext );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml 2009-04-09
12:23:07 UTC (rev 16286)
+++
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml 2009-04-09
16:07:22 UTC (rev 16287)
@@ -52,4 +52,9 @@
</constraint>
</getter>
</bean>
+ <constraint-definition
annotation="org.hibernate.validation.engine.xml.ConsistentUserInformation">
+ <validated-by include-existing-validators="false">
+
<value>org.hibernate.validation.engine.xml.CustomConsistentUserValidator</value>
+ </validated-by>
+ </constraint-definition>
</constraint-mappings>