Hibernate SVN: r15892 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-04 13:15:18 -0500 (Wed, 04 Feb 2009)
New Revision: 15892
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
Log:
Fixed typo.
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-02-04 17:16:57 UTC (rev 15891)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-02-04 18:15:18 UTC (rev 15892)
@@ -298,7 +298,7 @@
for ( ConstraintDescriptorImpl constraintDescriptor : metadata ) {
if ( methodName == null ) {
throw new ValidationException(
- "Annoated methods must follow the JavaBeans naming convention. " + method.getName() + "() does not."
+ "Annotated methods must follow the JavaBeans naming convention. " + method.getName() + "() does not."
);
}
ElementDescriptorImpl elementDescriptor = ( ElementDescriptorImpl ) propertyDescriptors.get( methodName );
15 years, 2 months
Hibernate SVN: r15891 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-04 12:16:57 -0500 (Wed, 04 Feb 2009)
New Revision: 15891
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidationContext.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
Log:
Renaming ValidationContext into ExecutionContext. See how this goes. An laternative would be ValidatorExectutionContext, but I would like to avoid 'Validator' or 'Validation'
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-02-04 16:44:02 UTC (rev 15890)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-02-04 17:16:57 UTC (rev 15891)
@@ -80,31 +80,31 @@
return descriptor;
}
- public void validateConstraints(Object value, Class beanClass, ValidationContext validationContext) {
+ public void validateConstraints(Object value, Class beanClass, ExecutionContext executionContext) {
for ( ConstraintTree tree : getChildren() ) {
- tree.validateConstraints( value, beanClass, validationContext );
+ tree.validateConstraints( value, beanClass, executionContext );
}
- final Object leafBeanInstance = validationContext.peekValidatedObject();
+ final Object leafBeanInstance = executionContext.peekValidatedObject();
ConstraintValidatorContextImpl constraintContext = new ConstraintValidatorContextImpl( descriptor );
if ( log.isTraceEnabled() ) {
log.trace( "Validating value {} against constraint defined by {}", value, descriptor );
}
ConstraintValidator validator = getInitalizedValidator(
- value, validationContext.getConstraintValidatorFactory()
+ value, executionContext.getConstraintValidatorFactory()
);
if ( !validator.isValid( value, constraintContext ) ) {
for ( ConstraintValidatorContextImpl.ErrorMessage error : constraintContext.getErrorMessages() ) {
final String message = error.getMessage();
- createConstraintViolation( value, beanClass, validationContext, leafBeanInstance, message, descriptor );
+ createConstraintViolation( value, beanClass, executionContext, leafBeanInstance, message, descriptor );
}
}
if ( reportAsSingleViolation()
- && validationContext.getFailingConstraints().size() > 0 ) {
- validationContext.clearFailingConstraints();
+ && executionContext.getFailingConstraints().size() > 0 ) {
+ executionContext.clearFailingConstraints();
final String message = ( String ) getParent().getDescriptor().getParameters().get( "message" );
createConstraintViolation(
- value, beanClass, validationContext, leafBeanInstance, message, getParent().descriptor
+ value, beanClass, executionContext, leafBeanInstance, message, getParent().descriptor
);
}
}
@@ -114,8 +114,8 @@
&& getParent().getDescriptor().isReportAsSingleViolation();
}
- private <T> void createConstraintViolation(Object value, Class<T> beanClass, ValidationContext<T> validationContext, Object leafBeanInstance, String message, ConstraintDescriptor descriptor) {
- String interpolatedMessage = validationContext.getMessageResolver().interpolate(
+ private <T> void createConstraintViolation(Object value, Class<T> beanClass, ExecutionContext<T> executionContext, Object leafBeanInstance, String message, ConstraintDescriptor descriptor) {
+ String interpolatedMessage = executionContext.getMessageResolver().interpolate(
message,
descriptor,
leafBeanInstance
@@ -123,15 +123,15 @@
ConstraintViolationImpl<T> failingConstraintViolation = new ConstraintViolationImpl<T>(
message,
interpolatedMessage,
- validationContext.getRootBean(),
+ executionContext.getRootBean(),
beanClass,
leafBeanInstance,
value,
- validationContext.peekPropertyPath(), //FIXME use error.getProperty()
- validationContext.getCurrentGroup(),
+ executionContext.peekPropertyPath(), //FIXME use error.getProperty()
+ executionContext.getCurrentGroup(),
descriptor
);
- validationContext.addConstraintFailure( failingConstraintViolation );
+ executionContext.addConstraintFailure( failingConstraintViolation );
}
/**
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java (from rev 15883, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidationContext.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-02-04 17:16:57 UTC (rev 15891)
@@ -0,0 +1,232 @@
+// $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.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+
+import org.hibernate.validation.util.IdentitySet;
+
+/**
+ * Context object keeping track of all processed objects and all failing constraints.
+ * At the same time it keeps track of the currently validated object, the current group and property path.
+ * The way the validation works at the moment the validated object and the property path have to be processed
+ * in a stack fashion.
+ * <p/>
+ * all sort of information needed Introduced to reduce the parameters passed around between the different
+ * validate methdods in <code>ValidatorImpl</code>.
+ *
+ * @author Hardy Ferentschik
+ * @author Emmanuel Bernard
+ */
+public class ExecutionContext<T> {
+
+ /**
+ * The root bean of the validation.
+ */
+ private final T rootBean;
+
+ /**
+ * Maps for each group to an identity set to keep track of already validated objects. We have to make sure
+ * that each object gets only validated once (per group).
+ */
+ private final Map<Class<?>, IdentitySet> processedObjects;
+
+ /**
+ * A list of all failing constraints so far.
+ */
+ private final List<ConstraintViolationImpl<T>> failingConstraintViolations;
+
+ /**
+ * The current property path.
+ */
+ private String propertyPath;
+
+ /**
+ * The current group which is getting processed.
+ */
+ private Class<?> currentGroup;
+
+ /**
+ * Stack for keeping track of the currently validated object.
+ */
+ private Stack<ValidatedBean> validatedObjectStack = new Stack<ValidatedBean>();
+
+ /**
+ * The message resolver which should be used in this context.
+ */
+ private final MessageInterpolator messageResolver;
+
+ /**
+ * The constraint factory which should be used in this context.
+ */
+ ConstraintValidatorFactory constraintValidatorFactory;
+
+
+ public ExecutionContext(T object, MessageInterpolator messageResolver, ConstraintValidatorFactory constraintValidatorFactory) {
+ this( object, object, messageResolver, constraintValidatorFactory );
+ }
+
+ public ExecutionContext(T rootBean, Object object, MessageInterpolator messageResolver, ConstraintValidatorFactory constraintValidatorFactory) {
+ this.rootBean = rootBean;
+ this.messageResolver = messageResolver;
+ this.constraintValidatorFactory = constraintValidatorFactory;
+ validatedObjectStack.push( new ValidatedBean( object ) );
+ processedObjects = new HashMap<Class<?>, IdentitySet>();
+ propertyPath = "";
+ failingConstraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
+ }
+
+ public MessageInterpolator getMessageResolver() {
+ return messageResolver;
+ }
+
+ public ConstraintValidatorFactory getConstraintValidatorFactory() {
+ return constraintValidatorFactory;
+ }
+
+ public Object peekValidatedObject() {
+ return validatedObjectStack.peek().bean;
+ }
+
+ public Class<?> peekValidatedObjectType() {
+ return validatedObjectStack.peek().beanType;
+ }
+
+ public void pushValidatedObject(Object validatedObject) {
+ validatedObjectStack.push( new ValidatedBean( validatedObject ) );
+ }
+
+ public void popValidatedObject() {
+ validatedObjectStack.pop();
+ }
+
+ public T getRootBean() {
+ return rootBean;
+ }
+
+ public Class<?> getCurrentGroup() {
+ return currentGroup;
+ }
+
+ public void setCurrentGroup(Class<?> currentGroup) {
+ this.currentGroup = currentGroup;
+ }
+
+ public void markProcessedForCurrentGroup() {
+ if ( processedObjects.containsKey( currentGroup ) ) {
+ processedObjects.get( currentGroup ).add( validatedObjectStack.peek().bean );
+ }
+ else {
+ IdentitySet set = new IdentitySet();
+ set.add( validatedObjectStack.peek().bean );
+ processedObjects.put( currentGroup, set );
+ }
+ }
+
+ public boolean isProcessedForCurrentGroup(Object value) {
+ final IdentitySet objectsProcessedInCurrentGroups = processedObjects.get( currentGroup );
+ return objectsProcessedInCurrentGroups != null && objectsProcessedInCurrentGroups.contains( value );
+ }
+
+ public void addConstraintFailure(ConstraintViolationImpl<T> failingConstraintViolation) {
+ int i = failingConstraintViolations.indexOf( failingConstraintViolation );
+ if ( i == -1 ) {
+ failingConstraintViolations.add( failingConstraintViolation );
+ }
+ else {
+ failingConstraintViolations.get( i ).addGroups( failingConstraintViolation.getGroups() );
+ }
+ }
+
+ public List<ConstraintViolationImpl<T>> getFailingConstraints() {
+ return failingConstraintViolations;
+ }
+
+ public void clearFailingConstraints() {
+ failingConstraintViolations.clear();
+ }
+
+ /**
+ * Adds a new level to the current property path of this context.
+ *
+ * @param property the new property to add to the current path.
+ */
+ public void pushProperty(String property) {
+ if ( propertyPath.length() == 0 ) {
+ propertyPath = property;
+ }
+ else {
+ propertyPath = propertyPath + "." + property;
+ }
+ }
+
+ /**
+ * Drops the last level of the current property path of this context.
+ */
+ public void popProperty() {
+ int lastIndex = propertyPath.lastIndexOf( '.' );
+ if ( lastIndex != -1 ) {
+ propertyPath = propertyPath.substring( 0, lastIndex );
+ }
+ else {
+ propertyPath = "";
+ }
+ }
+
+ public void appendIndexToPropertyPath(String index) {
+ propertyPath += index;
+ }
+
+ public void replacePropertyIndex(String index) {
+ propertyPath = propertyPath.replaceAll( "\\{0\\}", index );
+ }
+
+ public String peekPropertyPath() {
+ return propertyPath;
+ }
+
+ public boolean needsValidation(Set<Class<?>> groups) {
+ return groups.contains( currentGroup );
+ }
+
+ /**
+ * @todo Is it useful to cache the object class?
+ */
+ private static class ValidatedBean {
+
+ final Object bean;
+ final Class<?> beanType;
+
+ private ValidatedBean(Object bean) {
+ this.bean = bean;
+ if ( bean == null ) {
+ this.beanType = null;
+ }
+ else {
+ this.beanType = bean.getClass();
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-02-04 16:44:02 UTC (rev 15890)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-02-04 17:16:57 UTC (rev 15891)
@@ -167,14 +167,14 @@
return constraintTree;
}
- public <T> void validateConstraint(Class beanClass, ValidationContext<T> validationContext) {
- final Object leafBeanInstance = validationContext.peekValidatedObject();
+ public <T> void validateConstraint(Class beanClass, ExecutionContext<T> executionContext) {
+ final Object leafBeanInstance = executionContext.peekValidatedObject();
Object value = getValue( leafBeanInstance );
- constraintTree.validateConstraints( value, beanClass, validationContext );
+ constraintTree.validateConstraints( value, beanClass, executionContext );
}
- public <T> void validateConstraint(Class beanClass, Object value, ValidationContext<T> validationContext) {
- constraintTree.validateConstraints( value, beanClass, validationContext );
+ public <T> void validateConstraint(Class beanClass, Object value, ExecutionContext<T> executionContext) {
+ constraintTree.validateConstraints( value, beanClass, executionContext );
}
private Type typeOfAnnoatedElement() {
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidationContext.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidationContext.java 2009-02-04 16:44:02 UTC (rev 15890)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidationContext.java 2009-02-04 17:16:57 UTC (rev 15891)
@@ -1,232 +0,0 @@
-// $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.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.MessageInterpolator;
-
-import org.hibernate.validation.util.IdentitySet;
-
-/**
- * Context object keeping track of all processed objects and all failing constraints.
- * At the same time it keeps track of the currently validated object, the current group and property path.
- * The way the validation works at the moment the validated object and the property path have to be processed
- * in a stack fashion.
- * <p/>
- * all sort of information needed Introduced to reduce the parameters passed around between the different
- * validate methdods in <code>ValidatorImpl</code>.
- *
- * @author Hardy Ferentschik
- * @author Emmanuel Bernard
- */
-public class ValidationContext<T> {
-
- /**
- * The root bean of the validation.
- */
- private final T rootBean;
-
- /**
- * Maps for each group to an identity set to keep track of already validated objects. We have to make sure
- * that each object gets only validated once (per group).
- */
- private final Map<Class<?>, IdentitySet> processedObjects;
-
- /**
- * A list of all failing constraints so far.
- */
- private final List<ConstraintViolationImpl<T>> failingConstraintViolations;
-
- /**
- * The current property path.
- */
- private String propertyPath;
-
- /**
- * The current group which is getting processed.
- */
- private Class<?> currentGroup;
-
- /**
- * Stack for keeping track of the currently validated object.
- */
- private Stack<ValidatedBean> validatedObjectStack = new Stack<ValidatedBean>();
-
- /**
- * The message resolver which should be used in this context.
- */
- private final MessageInterpolator messageResolver;
-
- /**
- * The constraint factory which should be used in this context.
- */
- ConstraintValidatorFactory constraintValidatorFactory;
-
-
- public ValidationContext(T object, MessageInterpolator messageResolver, ConstraintValidatorFactory constraintValidatorFactory) {
- this( object, object, messageResolver, constraintValidatorFactory );
- }
-
- public ValidationContext(T rootBean, Object object, MessageInterpolator messageResolver, ConstraintValidatorFactory constraintValidatorFactory) {
- this.rootBean = rootBean;
- this.messageResolver = messageResolver;
- this.constraintValidatorFactory = constraintValidatorFactory;
- validatedObjectStack.push( new ValidatedBean( object ) );
- processedObjects = new HashMap<Class<?>, IdentitySet>();
- propertyPath = "";
- failingConstraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
- }
-
- public MessageInterpolator getMessageResolver() {
- return messageResolver;
- }
-
- public ConstraintValidatorFactory getConstraintValidatorFactory() {
- return constraintValidatorFactory;
- }
-
- public Object peekValidatedObject() {
- return validatedObjectStack.peek().bean;
- }
-
- public Class<?> peekValidatedObjectType() {
- return validatedObjectStack.peek().beanType;
- }
-
- public void pushValidatedObject(Object validatedObject) {
- validatedObjectStack.push( new ValidatedBean( validatedObject ) );
- }
-
- public void popValidatedObject() {
- validatedObjectStack.pop();
- }
-
- public T getRootBean() {
- return rootBean;
- }
-
- public Class<?> getCurrentGroup() {
- return currentGroup;
- }
-
- public void setCurrentGroup(Class<?> currentGroup) {
- this.currentGroup = currentGroup;
- }
-
- public void markProcessedForCurrentGroup() {
- if ( processedObjects.containsKey( currentGroup ) ) {
- processedObjects.get( currentGroup ).add( validatedObjectStack.peek().bean );
- }
- else {
- IdentitySet set = new IdentitySet();
- set.add( validatedObjectStack.peek().bean );
- processedObjects.put( currentGroup, set );
- }
- }
-
- public boolean isProcessedForCurrentGroup(Object value) {
- final IdentitySet objectsProcessedInCurrentGroups = processedObjects.get( currentGroup );
- return objectsProcessedInCurrentGroups != null && objectsProcessedInCurrentGroups.contains( value );
- }
-
- public void addConstraintFailure(ConstraintViolationImpl<T> failingConstraintViolation) {
- int i = failingConstraintViolations.indexOf( failingConstraintViolation );
- if ( i == -1 ) {
- failingConstraintViolations.add( failingConstraintViolation );
- }
- else {
- failingConstraintViolations.get( i ).addGroups( failingConstraintViolation.getGroups() );
- }
- }
-
- public List<ConstraintViolationImpl<T>> getFailingConstraints() {
- return failingConstraintViolations;
- }
-
- public void clearFailingConstraints() {
- failingConstraintViolations.clear();
- }
-
- /**
- * Adds a new level to the current property path of this context.
- *
- * @param property the new property to add to the current path.
- */
- public void pushProperty(String property) {
- if ( propertyPath.length() == 0 ) {
- propertyPath = property;
- }
- else {
- propertyPath = propertyPath + "." + property;
- }
- }
-
- /**
- * Drops the last level of the current property path of this context.
- */
- public void popProperty() {
- int lastIndex = propertyPath.lastIndexOf( '.' );
- if ( lastIndex != -1 ) {
- propertyPath = propertyPath.substring( 0, lastIndex );
- }
- else {
- propertyPath = "";
- }
- }
-
- public void appendIndexToPropertyPath(String index) {
- propertyPath += index;
- }
-
- public void replacePropertyIndex(String index) {
- propertyPath = propertyPath.replaceAll( "\\{0\\}", index );
- }
-
- public String peekPropertyPath() {
- return propertyPath;
- }
-
- public boolean needsValidation(Set<Class<?>> groups) {
- return groups.contains( currentGroup );
- }
-
- /**
- * @todo Is it useful to cache the object class?
- */
- private static class ValidatedBean {
-
- final Object bean;
- final Class<?> beanType;
-
- private ValidatedBean(Object bean) {
- this.bean = bean;
- if ( bean == null ) {
- this.beanType = null;
- }
- else {
- this.beanType = bean.getClass();
- }
- }
- }
-}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-02-04 16:44:02 UTC (rev 15890)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-02-04 17:16:57 UTC (rev 15891)
@@ -81,7 +81,7 @@
throw new IllegalArgumentException( "Validation of a null object" );
}
- ValidationContext<T> context = new ValidationContext<T>(
+ ExecutionContext<T> context = new ExecutionContext<T>(
object, messageInterpolator, constraintValidatorFactory
);
List<ConstraintViolationImpl<T>> list = validateInContext( context, Arrays.asList( groups ) );
@@ -100,7 +100,7 @@
* @todo Currently we iterate the cascaded fields multiple times. Maybe we should change to an approach where we iterate the object graph only once.
* @todo Context root bean can be a different object than the current Validator<T> hence two different generics variables
*/
- private <T> List<ConstraintViolationImpl<T>> validateInContext(ValidationContext<T> context, List<Class<?>> groups) {
+ private <T> List<ConstraintViolationImpl<T>> validateInContext(ExecutionContext<T> context, List<Class<?>> groups) {
if ( context.peekValidatedObject() == null ) {
return Collections.emptyList();
}
@@ -133,30 +133,30 @@
/**
* Validates the non-cascaded constraints.
*
- * @param validationContext The current validation context.
+ * @param executionContext The current validation context.
*/
- private <T> void validateConstraints(ValidationContext<T> validationContext) {
+ private <T> void validateConstraints(ExecutionContext<T> executionContext) {
//casting rely on the fact that root object is at the top of the stack
@SuppressWarnings("unchecked")
BeanMetaData<T> beanMetaData =
- ( BeanMetaData<T> ) getBeanMetaData( validationContext.peekValidatedObjectType() );
+ ( BeanMetaData<T> ) getBeanMetaData( executionContext.peekValidatedObjectType() );
for ( MetaConstraint metaConstraint : beanMetaData.geMetaConstraintList() ) {
ConstraintDescriptor mainConstraintDescriptor = metaConstraint.getDescriptor();
- validationContext.pushProperty( metaConstraint.getPropertyName() );
+ executionContext.pushProperty( metaConstraint.getPropertyName() );
- if ( !validationContext.needsValidation( mainConstraintDescriptor.getGroups() ) ) {
- validationContext.popProperty();
+ if ( !executionContext.needsValidation( mainConstraintDescriptor.getGroups() ) ) {
+ executionContext.popProperty();
continue;
}
- metaConstraint.validateConstraint( beanMetaData.getBeanClass(), validationContext );
- validationContext.popProperty();
+ metaConstraint.validateConstraint( beanMetaData.getBeanClass(), executionContext );
+ executionContext.popProperty();
}
- validationContext.markProcessedForCurrentGroup();
+ executionContext.markProcessedForCurrentGroup();
}
- private <T> void validateCascadedConstraints(ValidationContext<T> context) {
+ private <T> void validateCascadedConstraints(ExecutionContext<T> context) {
List<Member> cascadedMembers = getBeanMetaData( context.peekValidatedObjectType() )
.getCascadedMembers();
for ( Member member : cascadedMembers ) {
@@ -181,7 +181,7 @@
* @param value the actual value.
* @return An iterator over the value of a cascaded property.
*/
- private <T> Iterator<?> createIteratorForCascadedValue(ValidationContext<T> context, Type type, Object value) {
+ private <T> Iterator<?> createIteratorForCascadedValue(ExecutionContext<T> context, Type type, Object value) {
Iterator<?> iter;
if ( ReflectionHelper.isCollection( type ) ) {
boolean isIterable = value instanceof Iterable;
@@ -205,7 +205,7 @@
return iter;
}
- private <T> void validateCascadedConstraint(ValidationContext<T> context, Iterator<?> iter) {
+ private <T> void validateCascadedConstraint(ExecutionContext<T> context, Iterator<?> iter) {
Object actualValue;
String propertyIndex;
int i = 0;
@@ -275,7 +275,7 @@
continue;
}
- ValidationContext<T> context = new ValidationContext<T>(
+ ExecutionContext<T> context = new ExecutionContext<T>(
object, messageInterpolator, constraintValidatorFactory
);
metaConstraint.validateConstraint( object.getClass(), context );
@@ -328,7 +328,7 @@
continue;
}
- ValidationContext<T> context = new ValidationContext<T>(
+ ExecutionContext<T> context = new ExecutionContext<T>(
( T ) value, messageInterpolator, constraintValidatorFactory
);
context.pushProperty( propertyIter.getOriginalProperty() );
15 years, 2 months
Hibernate SVN: r15890 - in validator/trunk: hibernate-validator/src/test/java/org/hibernate/validation/eg and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-04 11:44:02 -0500 (Wed, 04 Feb 2009)
New Revision: 15890
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/UnconstraintEntity.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Ambigious.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForBar.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForSerializable.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Bar.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Foo.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/SerializableBar.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java
Removed:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Unconstraint.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/constraint/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.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/ConstraintTree.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
validator/trunk/validation-api/src/main/java/javax/validation/Configuration.java
Log:
BVAL-99 added some test for ambigious validator resolution.
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-02-04 12:41:32 UTC (rev 15889)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -268,8 +268,6 @@
* @param beanClass The class to check for constraints annotations.
*
* @return A list of constraint descriptors for all constraint specified on the given class.
- *
- * @todo inject XML data here, probably externalizing the process
*/
private List<ConstraintDescriptorImpl> findClassLevelConstraints(Class beanClass) {
List<ConstraintDescriptorImpl> metadata = new ArrayList<ConstraintDescriptorImpl>();
@@ -289,8 +287,6 @@
* @param method The method to check for constraints annotations.
*
* @return A list of constraint descriptors for all constraint specified for the given method.
- *
- * @todo inject XML data here, probably externalizing the process
*/
private List<ConstraintDescriptorImpl> findMethodLevelConstraints(Method method) {
List<ConstraintDescriptorImpl> metadata = new ArrayList<ConstraintDescriptorImpl>();
@@ -326,8 +322,6 @@
* @param field The field to check for constraints annotations.
*
* @return A list of constraint descriptors for all constraint specified on the given field.
- *
- * @todo inject XML data here, probably externalizing the process
*/
private List<ConstraintDescriptorImpl> findFieldLevelConstraints(Field field) {
List<ConstraintDescriptorImpl> metadata = new ArrayList<ConstraintDescriptorImpl>();
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-02-04 12:41:32 UTC (rev 15889)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -206,7 +206,7 @@
do {
classesToRemove.clear();
Class clazz = assignableClasses.get( 0 );
- for ( int i = 1; i <= assignableClasses.size(); i++ ) {
+ for ( int i = 1; i < assignableClasses.size(); i++ ) {
if ( clazz.isAssignableFrom( assignableClasses.get( i ) ) ) {
classesToRemove.add( clazz );
}
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Unconstraint.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Unconstraint.java 2009-02-04 12:41:32 UTC (rev 15889)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Unconstraint.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -1,26 +0,0 @@
-// : Person.java 69 2008-09-08 11:05:07Z hardy.ferentschik $
-/*
-* 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.eg;
-
-/**
- * Empty un-constraint test class.
- *
- * @author Hardy Ferentschik
- */
-public class Unconstraint {
-}
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/UnconstraintEntity.java (from rev 15883, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Unconstraint.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/UnconstraintEntity.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/UnconstraintEntity.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -0,0 +1,26 @@
+// : Person.java 69 2008-09-08 11:05:07Z hardy.ferentschik $
+/*
+* 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.eg;
+
+/**
+ * Empty un-constraint test class.
+ *
+ * @author Hardy Ferentschik
+ */
+public class UnconstraintEntity {
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/UnconstraintEntity.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-02-04 12:41:32 UTC (rev 15889)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -42,7 +42,7 @@
import org.hibernate.validation.eg.Engine;
import org.hibernate.validation.eg.EnglishDictonary;
import org.hibernate.validation.eg.Order;
-import org.hibernate.validation.eg.Unconstraint;
+import org.hibernate.validation.eg.UnconstraintEntity;
import org.hibernate.validation.eg.groups.First;
import org.hibernate.validation.eg.groups.Last;
import org.hibernate.validation.eg.groups.Second;
@@ -80,7 +80,7 @@
@Test
public void testUnconstraintClass() {
Validator validator = TestUtil.getValidator();
- assertTrue( "There should be no constraints", !validator.getConstraintsForClass( Unconstraint.class ).hasConstraints() );
+ assertTrue( "There should be no constraints", !validator.getConstraintsForClass( UnconstraintEntity.class ).hasConstraints() );
}
@Test
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.java 2009-02-04 12:41:32 UTC (rev 15889)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -1,45 +0,0 @@
-// $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.util.Set;
-import javax.validation.ConstraintViolation;
-import javax.validation.Validator;
-
-import org.junit.Test;
-
-import org.hibernate.validation.eg.MultipleMinMax;
-import static org.hibernate.validation.util.TestUtil.assertNumberOfViolations;
-import static org.hibernate.validation.util.TestUtil.getValidator;
-
-/**
- * Tests for constraint validator resolution.
- *
- * @author Hardy Ferentschik
- */
-public class ValidatorResolutionTest {
-
- @Test
- public void testValidatorResolutionForMinMax() {
- Validator validator = getValidator();
-
- MultipleMinMax minMax = new MultipleMinMax( "5", 5 );
- Set<ConstraintViolation<MultipleMinMax>> constraintViolations = validator.validate( minMax );
- assertNumberOfViolations( constraintViolations, 2 );
- }
-}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Ambigious.java (from rev 15883, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/composition/FrenchZipcode.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Ambigious.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Ambigious.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -0,0 +1,42 @@
+// $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.validatorresolution;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+
+/**
+ * A test constraint which can lead to a error when trying to reslove the validator.
+ *
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = { AmbigiousValidatorForBar.class, AmbigiousValidatorForSerializable.class })
+@Documented
+@Target({ METHOD, FIELD, TYPE })
+@Retention(RUNTIME)
+public @interface Ambigious {
+ public abstract String message() default "foobar";
+
+ public abstract Class<?>[] groups() default { };
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Ambigious.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForBar.java (from rev 15883, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/composition/FrenchZipcodeConstraintValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForBar.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForBar.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -0,0 +1,34 @@
+// $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.validatorresolution;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class AmbigiousValidatorForBar implements ConstraintValidator<Ambigious, Bar> {
+
+ public void initialize(Ambigious parameters) {
+ }
+
+ public boolean isValid(Bar b, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForBar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForSerializable.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForSerializable.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForSerializable.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -0,0 +1,35 @@
+// $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.validatorresolution;
+
+import java.io.Serializable;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class AmbigiousValidatorForSerializable implements ConstraintValidator<Ambigious, Serializable> {
+
+ public void initialize(Ambigious parameters) {
+ }
+
+ public boolean isValid(Serializable o, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/AmbigiousValidatorForSerializable.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Bar.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Bar.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Bar.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -0,0 +1,25 @@
+// : Person.java 69 2008-09-08 11:05:07Z hardy.ferentschik $
+/*
+* 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.validatorresolution;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Bar {
+
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Bar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Foo.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Foo.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Foo.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -0,0 +1,35 @@
+// : Person.java 69 2008-09-08 11:05:07Z hardy.ferentschik $
+/*
+* 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.validatorresolution;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Foo {
+
+ @Ambigious
+ private Bar bar;
+
+ public Foo(Bar bar) {
+ this.bar = bar;
+ }
+
+ public Bar getBar() {
+ return bar;
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/Foo.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/SerializableBar.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/SerializableBar.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/SerializableBar.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -0,0 +1,27 @@
+// : Person.java 69 2008-09-08 11:05:07Z hardy.ferentschik $
+/*
+* 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.validatorresolution;
+
+import java.io.Serializable;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SerializableBar extends Bar implements Serializable {
+
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/SerializableBar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java (from rev 15889, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -0,0 +1,62 @@
+// $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.validatorresolution;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+
+import org.hibernate.validation.eg.MultipleMinMax;
+import static org.hibernate.validation.util.TestUtil.assertNumberOfViolations;
+import static org.hibernate.validation.util.TestUtil.getValidator;
+
+/**
+ * Tests for constraint validator resolution.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ValidatorResolutionTest {
+
+ @Test
+ public void testValidatorResolutionForMinMax() {
+ Validator validator = getValidator();
+
+ MultipleMinMax minMax = new MultipleMinMax( "5", 5 );
+ Set<ConstraintViolation<MultipleMinMax>> constraintViolations = validator.validate( minMax );
+ assertNumberOfViolations( constraintViolations, 2 );
+ }
+
+ @Test
+ public void testAmbigiousValidatorResolution() {
+ Validator validator = getValidator();
+
+ Foo foo = new Foo( new SerializableBar() );
+ try {
+ validator.validate( foo );
+ fail();
+ }
+ catch ( ValidationException e ) {
+ assertTrue( e.getMessage().startsWith( "There are multiple validators" ) );
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Modified: validator/trunk/validation-api/src/main/java/javax/validation/Configuration.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/Configuration.java 2009-02-04 12:41:32 UTC (rev 15889)
+++ validator/trunk/validation-api/src/main/java/javax/validation/Configuration.java 2009-02-04 16:44:02 UTC (rev 15890)
@@ -32,12 +32,12 @@
* .buildValidatorFactory();
* </pre>
* <p/>
- *
+ * <p/>
* By default, the configuration information is retrieved from
* META-INF/validation.xml
* It is possible to override the configuration retrieved from the XML file
* by using one or more of the Configuration methods.
- *
+ * <p/>
* The ValidationProviderResolver is specified at Configuration time
* (see {@link javax.validation.spi.ValidationProvider}).
* If none is explicitely requested, the default ValidationProviderResolver is used.
@@ -61,8 +61,11 @@
* This method is typically useful for containers that parse
* META-INF/validation.xml themselves and pass the information
* via the Configuration methods.
+ *
+ * @return <code>this</code> following the chaining method pattern.
*/
T ignoreXmlConfiguration();
+
/**
* Defines the message interpolator used. Has priority over the configuration
* based message interpolator.
@@ -94,11 +97,11 @@
T constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory);
/**
- * Add a stream describing constaint mapping in the Bean Validation
+ * Add a stream describing constraint mapping in the Bean Validation
* XML format.
* <p/>
* The stream should be closed by the client API after the
- * ValidatorFactory has been built. The Bean Validation provider
+ * <code>ValidatorFactory</code> has been built. The Bean Validation provider
* must not close the stream.
*
* @param stream XML mapping stream.
@@ -112,29 +115,33 @@
* XML Configuration properties.
* If the underlying provider does not know how to handle the property,
* it must silently ignore it.
- *
+ * <p/>
* Note: Using this non type-safe method is generally not recommended.
- *
+ * <p/>
* It is more appropriate to use, if available, the type-safe equivalent provided
* by a specific provider in its Configuration subclass.
* <code>ValidatorFactory factory = Validation.byProvider(ACMEConfiguration.class)
- * .configure()
- * .providerSpecificProperty(ACMEState.FAST)
- * .buildValidatorFactory();
+ * .configure()
+ * .providerSpecificProperty(ACMEState.FAST)
+ * .buildValidatorFactory();
* </code>
* This method is typically used by containers parsing META-INF/validation.xml
* themselves and injecting the state to the Configuration object.
- *
+ * <p/>
* If a property with a given name is defined both via this method and in the
* XML configuration, the value set programmatically has priority.
+ *
+ * @param name property name.
+ * @param value property value.
+ * @return <code>this</code> following the chaining method pattern.
*/
T addProperty(String name, String value);
/**
* Return an implementation of the MessageInterpolator interface following the
* default MessageInterpolator defined in the specification:
- * - use the ValidationMessages resource bundle to load keys
- * - use Locale.getDefault()
+ * - use the ValidationMessages resource bundle to load keys
+ * - use Locale.getDefault()
*
* @return default MessageInterpolator implementation compliant with the specification
*/
15 years, 2 months
Hibernate SVN: r15889 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validation/util and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-04 07:41:32 -0500 (Wed, 04 Feb 2009)
New Revision: 15889
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/MultipleMinMax.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java
Log:
BVAL-99 first cut for validator resolution. needs more tests.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-02-04 08:49:24 UTC (rev 15888)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-02-04 12:41:32 UTC (rev 15889)
@@ -17,15 +17,19 @@
*/
package org.hibernate.validation.engine;
+import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import javax.validation.ConstraintDescriptor;
import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorFactory;
import javax.validation.ValidationException;
import org.slf4j.Logger;
import org.hibernate.validation.util.LoggerFactory;
+import org.hibernate.validation.util.ValidatorTypeHelper;
/**
* Due to constraint conposition a single constraint annotation can lead to a whole constraint tree beeing validated.
@@ -76,7 +80,7 @@
return descriptor;
}
- public <T> void validateConstraints(Object value, Class<T> beanClass, ValidationContext<T> validationContext) {
+ public void validateConstraints(Object value, Class beanClass, ValidationContext validationContext) {
for ( ConstraintTree tree : getChildren() ) {
tree.validateConstraints( value, beanClass, validationContext );
}
@@ -86,7 +90,10 @@
if ( log.isTraceEnabled() ) {
log.trace( "Validating value {} against constraint defined by {}", value, descriptor );
}
- if ( !getConstraintValidator( descriptor, validationContext ).isValid( value, constraintContext ) ) {
+ ConstraintValidator validator = getInitalizedValidator(
+ value, validationContext.getConstraintValidatorFactory()
+ );
+ if ( !validator.isValid( value, constraintContext ) ) {
for ( ConstraintValidatorContextImpl.ErrorMessage error : constraintContext.getErrorMessages() ) {
final String message = error.getMessage();
createConstraintViolation( value, beanClass, validationContext, leafBeanInstance, message, descriptor );
@@ -127,25 +134,100 @@
validationContext.addConstraintFailure( failingConstraintViolation );
}
- private ConstraintValidator getConstraintValidator(ConstraintDescriptor descriptor, ValidationContext validationContext) {
+ /**
+ * @param value The value to be validated.
+ * @param constraintFactory constraint factory used to instantiate the constraint validator.
+ *
+ * @return A initalized constraint validator matching the type of the value to be validated.
+ */
+ private ConstraintValidator getInitalizedValidator(Object value, ConstraintValidatorFactory constraintFactory) {
ConstraintValidator constraintValidator;
- try {
- //FIXME do choose the right validator depending on the object validated
- constraintValidator = validationContext.getConstraintValidatorFactory().getInstance( descriptor.getConstraintValidatorClasses().get(0) );
+ Class validatorClass;
+ if ( value == null ) {
+ validatorClass = descriptor.getConstraintValidatorClasses().get( 0 );
}
- catch ( RuntimeException e ) {
- //FIXME do choose the right validator depending on the object validated
- throw new ValidationException(
- "Unable to instantiate " + descriptor.getConstraintValidatorClasses().get(0), e
- );
+ else {
+ validatorClass = findMatchingValidatorClass( value );
}
+ constraintValidator = constraintFactory.getInstance( validatorClass );
+ initializeConstraint( descriptor, constraintValidator );
+ return constraintValidator;
+ }
+ /**
+ * Runs the validator resolution algorithm.
+ *
+ * @param value the object to validate
+ *
+ * @return The class of a matching validator.
+ */
+ private Class findMatchingValidatorClass(Object value) {
+ Class valueClass = value.getClass();
+
+ Map<Class<?>, Class<? extends ConstraintValidator<? extends Annotation, ?>>> validatorsTypes = ValidatorTypeHelper
+ .getValidatorsTypes( descriptor.getConstraintValidatorClasses() );
+
+ List<Class> assignableClasses = new ArrayList<Class>();
+ for ( Class clazz : validatorsTypes.keySet() ) {
+ if ( clazz.isAssignableFrom( valueClass ) ) {
+ assignableClasses.add( clazz );
+ }
+ }
+
+ resolveAssignableClasses( assignableClasses );
+ if ( assignableClasses.size() != 1 ) {
+ StringBuilder builder = new StringBuilder();
+ builder.append( "There are multiple validators which could validate the type " );
+ builder.append( valueClass );
+ builder.append( ". The validator classes are: " );
+ for ( Class clazz : assignableClasses ) {
+ builder.append( clazz.getName() );
+ builder.append( ", " );
+ }
+ builder.delete( builder.length() - 2, builder.length() );
+ throw new ValidationException( builder.toString() );
+ }
+
+ return validatorsTypes.get( assignableClasses.get( 0 ) );
+ }
+
+ /**
+ * Tries to reduce all assignable classes down to a single class.
+ *
+ * @param assignableClasses The set of all classes which are assignable to the class of the value to be validated and
+ * which are handled by at least one of the validators for the specified constraint.
+ */
+ private void resolveAssignableClasses(List<Class> assignableClasses) {
+ if ( assignableClasses.size() == 1 ) {
+ return;
+ }
+
+ List<Class> classesToRemove = new ArrayList<Class>();
+ do {
+ classesToRemove.clear();
+ Class clazz = assignableClasses.get( 0 );
+ for ( int i = 1; i <= assignableClasses.size(); i++ ) {
+ if ( clazz.isAssignableFrom( assignableClasses.get( i ) ) ) {
+ classesToRemove.add( clazz );
+ }
+ else if ( assignableClasses.get( i ).isAssignableFrom( clazz ) ) {
+ classesToRemove.add( assignableClasses.get( i ) );
+ }
+ }
+ assignableClasses.removeAll( classesToRemove );
+ } while ( classesToRemove.size() > 0 );
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initializeConstraint
+ (ConstraintDescriptor
+ descriptor, ConstraintValidator
+ constraintValidator) {
try {
constraintValidator.initialize( descriptor.getAnnotation() );
}
catch ( RuntimeException e ) {
throw new ValidationException( "Unable to intialize " + constraintValidator.getClass().getName(), e );
}
- return constraintValidator;
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java 2009-02-04 08:49:24 UTC (rev 15888)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java 2009-02-04 12:41:32 UTC (rev 15889)
@@ -1,3 +1,20 @@
+// $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.util;
import java.lang.annotation.Annotation;
@@ -5,64 +22,68 @@
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.validation.ConstraintValidator;
import javax.validation.ValidationException;
/**
- * Helper methods around ConstraintValidator types
+ * Helper methods around <code>ConstraintValidator</code> types.
+ *
+ * @author Emmanuel Bernanrd
+ * @author Hardy Ferentschik
*/
public class ValidatorTypeHelper {
private static final int VALIDATOR_TYPE_INDEX = 1;
/**
- * for a lsit of validators, return a Map<Class, Class<? extends ConstraintValidator>>
- * The key is the type the validator accepts, the value is the validator class itself
-
+ * @param validators List of constraint validator classes (for a given constraint).
+ *
+ * @return Return a Map<Class, Class<? extends ConstraintValidator>> where the map
+ * key is the type the validator accepts and value the validator class itself.
*/
public static Map<Class<?>, Class<? extends ConstraintValidator<? extends Annotation, ?>>>
- getValidatorsTypes(Class<? extends ConstraintValidator<? extends Annotation,?>>[] validators) {
- if (validators == null || validators.length == 0) {
- //TODObe more contextually specific
- throw new ValidationException("No ConstraintValidators associated to @Constraint");
+ getValidatorsTypes(List<Class<? extends ConstraintValidator<?, ?>>> validators) {
+ if ( validators == null || validators.size() == 0 ) {
+ throw new ValidationException( "No ConstraintValidators associated to @Constraint" );
}
else {
Map<Class<?>, Class<? extends ConstraintValidator<? extends Annotation, ?>>> validatorsTypes =
new HashMap<Class<?>, Class<? extends ConstraintValidator<? extends Annotation, ?>>>();
- for (Class<? extends ConstraintValidator<? extends Annotation,?>> validator : validators) {
- validatorsTypes.put( extractType(validator), validator );
+ for ( Class<? extends ConstraintValidator<? extends Annotation, ?>> validator : validators ) {
+ validatorsTypes.put( extractType( validator ), validator );
}
return validatorsTypes;
}
}
- private static Class<?> extractType(Class<? extends ConstraintValidator<?,?>> validator) {
+ private static Class<?> extractType(Class<? extends ConstraintValidator<?, ?>> validator) {
Map<Type, Type> resolvedTypes = new HashMap<Type, Type>();
- Type constraintValidatorType = resolveTypes(resolvedTypes, validator);
+ Type constraintValidatorType = resolveTypes( resolvedTypes, validator );
//we now have all bind from a type to its resolution at one level
//FIXME throw assertion exception if constraintValidatorType == null
- Type validatorType = ( (ParameterizedType) constraintValidatorType ).getActualTypeArguments()[VALIDATOR_TYPE_INDEX];
+ Type validatorType = ( ( ParameterizedType ) constraintValidatorType ).getActualTypeArguments()[VALIDATOR_TYPE_INDEX];
while ( resolvedTypes.containsKey( validatorType ) ) {
validatorType = resolvedTypes.get( validatorType );
}
//FIXME raise an exception if validatorType is not a class
- return (Class<?>) validatorType;
+ return ( Class<?> ) validatorType;
}
//TEst method, remove
- public static Type extractTypeLoose(Class<? extends ConstraintValidator<?,?>> validator) {
+ public static Type extractTypeLoose(Class<? extends ConstraintValidator<?, ?>> validator) {
Map<Type, Type> resolvedTypes = new HashMap<Type, Type>();
- Type constraintValidatorType = resolveTypes(resolvedTypes, validator);
+ Type constraintValidatorType = resolveTypes( resolvedTypes, validator );
//we now have all bind from a type to its resolution at one level
//FIXME throw assertion exception if constraintValidatorType == null
- Type validatorType = ( (ParameterizedType) constraintValidatorType ).getActualTypeArguments()[VALIDATOR_TYPE_INDEX];
+ Type validatorType = ( ( ParameterizedType ) constraintValidatorType ).getActualTypeArguments()[VALIDATOR_TYPE_INDEX];
while ( resolvedTypes.containsKey( validatorType ) ) {
validatorType = resolvedTypes.get( validatorType );
}
@@ -71,27 +92,33 @@
}
private static Type resolveTypes(Map<Type, Type> resolvedTypes, Type type) {
- if (type == null) {
+ if ( type == null ) {
return null;
}
else if ( type instanceof Class ) {
- Class<?> clazz = ( Class<?> ) type;
- Type returnedType = resolveTypes(resolvedTypes, clazz.getGenericSuperclass() );
- if (returnedType != null) return returnedType;
- for (Type genericInterface : clazz.getGenericInterfaces() ) {
- returnedType = resolveTypes(resolvedTypes, genericInterface );
- if (returnedType != null) return returnedType;
+ Class clazz = ( Class ) type;
+ Type returnedType = resolveTypes( resolvedTypes, clazz.getGenericSuperclass() );
+ if ( returnedType != null ) {
+ return returnedType;
}
+ for ( Type genericInterface : clazz.getGenericInterfaces() ) {
+ returnedType = resolveTypes( resolvedTypes, genericInterface );
+ if ( returnedType != null ) {
+ return returnedType;
+ }
+ }
}
else if ( type instanceof ParameterizedType ) {
- ParameterizedType paramType = (ParameterizedType) type;
- if ( ! ( paramType.getRawType() instanceof Class ) ) return null; //don't know what to do here
- Class<?> rawType = (Class<?>) paramType.getRawType();
+ ParameterizedType paramType = ( ParameterizedType ) type;
+ if ( !( paramType.getRawType() instanceof Class ) ) {
+ return null; //don't know what to do here
+ }
+ Class<?> rawType = ( Class<?> ) paramType.getRawType();
TypeVariable<?>[] originalTypes = rawType.getTypeParameters();
Type[] partiallyResolvedTypes = paramType.getActualTypeArguments();
int nbrOfParams = originalTypes.length;
- for (int i = 0 ; i < nbrOfParams; i++) {
+ for ( int i = 0; i < nbrOfParams; i++ ) {
resolvedTypes.put( originalTypes[i], partiallyResolvedTypes[i] );
}
@@ -100,9 +127,9 @@
return type;
}
else {
- resolveTypes(resolvedTypes, rawType.getGenericSuperclass() );
- for (Type genericInterface : rawType.getGenericInterfaces() ) {
- resolveTypes(resolvedTypes, genericInterface );
+ resolveTypes( resolvedTypes, rawType.getGenericSuperclass() );
+ for ( Type genericInterface : rawType.getGenericInterfaces() ) {
+ resolveTypes( resolvedTypes, genericInterface );
}
}
}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/MultipleMinMax.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/MultipleMinMax.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/MultipleMinMax.java 2009-02-04 12:41:32 UTC (rev 15889)
@@ -0,0 +1,39 @@
+// $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.eg;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class MultipleMinMax {
+ @Min(10l)
+ @Max(20l)
+ Number number;
+
+ @Min(10l)
+ @Max(20l)
+ String stringNumber;
+
+ public MultipleMinMax(String stringNumber, Number number) {
+ this.stringNumber = stringNumber;
+ this.number = number;
+ }
+}
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.java (from rev 15854, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintCompositionTest.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorResolutionTest.java 2009-02-04 12:41:32 UTC (rev 15889)
@@ -0,0 +1,45 @@
+// $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.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.junit.Test;
+
+import org.hibernate.validation.eg.MultipleMinMax;
+import static org.hibernate.validation.util.TestUtil.assertNumberOfViolations;
+import static org.hibernate.validation.util.TestUtil.getValidator;
+
+/**
+ * Tests for constraint validator resolution.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ValidatorResolutionTest {
+
+ @Test
+ public void testValidatorResolutionForMinMax() {
+ Validator validator = getValidator();
+
+ MultipleMinMax minMax = new MultipleMinMax( "5", 5 );
+ Set<ConstraintViolation<MultipleMinMax>> constraintViolations = validator.validate( minMax );
+ assertNumberOfViolations( constraintViolations, 2 );
+ }
+}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java 2009-02-04 08:49:24 UTC (rev 15888)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java 2009-02-04 12:41:32 UTC (rev 15889)
@@ -19,6 +19,8 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.validation.ConstraintValidator;
@@ -29,7 +31,6 @@
import org.junit.Test;
import org.hibernate.validation.constraints.composition.FrenchZipcodeConstraintValidator;
-import org.hibernate.validation.util.ValidatorTypeHelper;
/**
* Tests for message resolution.
@@ -40,8 +41,10 @@
@Test
public void testTypeDiscovery() {
+ List<Class<? extends ConstraintValidator<?, ?>>> validators = new ArrayList<Class<? extends ConstraintValidator<?, ?>>>();
+ validators.add( FrenchZipcodeConstraintValidator.class );
Map<Class<?>, Class<? extends ConstraintValidator<? extends Annotation, ?>>> validatorsTypes = ValidatorTypeHelper
- .getValidatorsTypes( new Class[] { FrenchZipcodeConstraintValidator.class } );
+ .getValidatorsTypes( validators );
assertEquals( FrenchZipcodeConstraintValidator.class, validatorsTypes.get( String.class ) );
Type type = ValidatorTypeHelper
@@ -49,20 +52,19 @@
Type type2 = ValidatorTypeHelper
- .extractTypeLoose( TestValidator2.class );
+ .extractTypeLoose( TestValidator2.class );
assertEquals( type, type2 );
}
public static class TestValidator implements ConstraintValidator<NotNull, Set<String>> {
public void initialize(NotNull constraintAnnotation) {
- //To change body of implemented methods use File | Settings | File Templates.
}
public boolean isValid(Set<String> object, ConstraintValidatorContext constraintValidatorContext) {
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ return false;
}
-}
+ }
public static class TestValidator2 implements ConstraintValidator<NotNull, Set<String>> {
public void initialize(NotNull constraintAnnotation) {
15 years, 2 months
Hibernate SVN: r15888 - entitymanager/branches/v3_2_1_GA_CP.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-02-04 03:49:24 -0500 (Wed, 04 Feb 2009)
New Revision: 15888
Modified:
entitymanager/branches/v3_2_1_GA_CP/build.xml
Log:
EJB-410 - Fixed target junitsingle
Modified: entitymanager/branches/v3_2_1_GA_CP/build.xml
===================================================================
--- entitymanager/branches/v3_2_1_GA_CP/build.xml 2009-02-04 08:47:10 UTC (rev 15887)
+++ entitymanager/branches/v3_2_1_GA_CP/build.xml 2009-02-04 08:49:24 UTC (rev 15888)
@@ -223,22 +223,32 @@
</target>
<!-- Run a single unit test. -->
- <target name="junitsingle" depends="compiletest"
+ <target name="junitsingle" depends="compiletest,test-resources"
description="Run a single test suite (requires testname and jdbc.driver properties)">
<mkdir dir="${test.out.dir}"/>
+ <echo message="${test.dir}"/>
<junit printsummary="yes" fork="yes" haltonfailure="yes">
<classpath>
<fileset dir="${jdbc.dir}">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
</fileset>
+ <dirset dir="${build.testresources.dir}">
+ <include name="**/*.jar"/>
+ <include name="**/*.par"/>
+ </dirset>
+
+ <fileset dir="${build.testresources.dir}">
+ <include name="**/*.jar"/>
+ <include name="**/*.par"/>
+ </fileset>
<path refid="lib.class.path"/>
- <pathelement path="build/test.par"/>
- <pathelement path="target/hibernate-entitymanager/hibernate-entitymanager.jar"/>
+ <pathelement path="${classes.dir}"/>
+ <dirset dir="${testclasses.dir}">
+ <exclude name="**/pack/**.*"/>
+ </dirset>
<pathelement path="${src.dir}"/>
- <!-- pick up properties from here -->
<pathelement path="${test.dir}"/>
- <!-- pick up mappings from here -->
</classpath>
<formatter type="plain"/>
<formatter type="xml"/>
15 years, 2 months
Hibernate SVN: r15887 - core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-02-04 03:47:10 -0500 (Wed, 04 Feb 2009)
New Revision: 15887
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/AbstractTransactSQLDialect.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SQLServerDialect.java
Log:
JBPAPP-1563 - Added bit_length and mod to SybaseDialect.
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/AbstractTransactSQLDialect.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/AbstractTransactSQLDialect.java 2009-02-04 08:44:33 UTC (rev 15886)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/AbstractTransactSQLDialect.java 2009-02-04 08:47:10 UTC (rev 15887)
@@ -100,6 +100,9 @@
registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "ltrim(rtrim(?1))") );
registerFunction( "locate", new CharIndexFunction() );
+ registerFunction( "mod", new SQLFunctionTemplate( Hibernate.INTEGER, "?1 % ?2" ) );
+ registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "datalength(?1) * 8" ) );
+
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SQLServerDialect.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SQLServerDialect.java 2009-02-04 08:44:33 UTC (rev 15886)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SQLServerDialect.java 2009-02-04 08:47:10 UTC (rev 15887)
@@ -26,9 +26,6 @@
registerFunction( "locate", new StandardSQLFunction("charindex", Hibernate.INTEGER) );
registerFunction( "extract", new SQLFunctionTemplate( Hibernate.INTEGER, "datepart(?1, ?3)" ) );
- registerFunction( "mod", new SQLFunctionTemplate( Hibernate.INTEGER, "?1 % ?2" ) );
- registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "datalength(?1) * 8" ) );
-
registerFunction( "trim", new AnsiTrimEmulationFunction() );
registerKeyword("top");
15 years, 2 months
Hibernate SVN: r15886 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-02-04 03:44:33 -0500 (Wed, 04 Feb 2009)
New Revision: 15886
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect/SybaseDialect.java
Log:
HHH-3640 - Added bit_length and mod to SybaseDialect.
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect/SybaseDialect.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect/SybaseDialect.java 2009-02-04 08:42:56 UTC (rev 15885)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect/SybaseDialect.java 2009-02-04 08:44:33 UTC (rev 15886)
@@ -126,6 +126,9 @@
registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "ltrim(rtrim(?1))") );
registerFunction( "locate", new CharIndexFunction() );
+ registerFunction( "mod", new SQLFunctionTemplate( Hibernate.INTEGER, "?1 % ?2" ) );
+ registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "datalength(?1) * 8" ) );
+
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}
15 years, 2 months
Hibernate SVN: r15885 - core/branches/Branch_3_2/src/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-02-04 03:42:56 -0500 (Wed, 04 Feb 2009)
New Revision: 15885
Modified:
core/branches/Branch_3_2/src/org/hibernate/dialect/SybaseDialect.java
Log:
HHH-3640 - Added bit_length and mod to SybaseDialect.
Modified: core/branches/Branch_3_2/src/org/hibernate/dialect/SybaseDialect.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/dialect/SybaseDialect.java 2009-02-04 08:42:07 UTC (rev 15884)
+++ core/branches/Branch_3_2/src/org/hibernate/dialect/SybaseDialect.java 2009-02-04 08:42:56 UTC (rev 15885)
@@ -103,6 +103,9 @@
registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "ltrim(rtrim(?1))") );
registerFunction( "locate", new CharIndexFunction() );
+ registerFunction( "mod", new SQLFunctionTemplate( Hibernate.INTEGER, "?1 % ?2" ) );
+ registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "datalength(?1) * 8" ) );
+
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}
15 years, 2 months
Hibernate SVN: r15884 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-02-04 03:42:07 -0500 (Wed, 04 Feb 2009)
New Revision: 15884
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/SybaseDialect.java
Log:
HHH-3640 - Added bit_length and mod to SybaseDialect.
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/SybaseDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/SybaseDialect.java 2009-02-04 04:05:44 UTC (rev 15883)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/SybaseDialect.java 2009-02-04 08:42:07 UTC (rev 15884)
@@ -126,6 +126,9 @@
registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "ltrim(rtrim(?1))") );
registerFunction( "locate", new CharIndexFunction() );
+ registerFunction( "mod", new SQLFunctionTemplate( Hibernate.INTEGER, "?1 % ?2" ) );
+ registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "datalength(?1) * 8" ) );
+
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}
15 years, 2 months
Hibernate SVN: r15883 - in core/trunk: testsuite/src/test/java/org/hibernate/test/interfaceproxy and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-02-03 23:05:44 -0500 (Tue, 03 Feb 2009)
New Revision: 15883
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/SQLServerDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/SybaseDialect.java
core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/lob/SerializableTypeTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/mixed/MixedTest.java
Log:
HHH-3691 : Sybase does not support Blobs and Clobs; skip unit tests that use Blobs/Clobs
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/SQLServerDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/SQLServerDialect.java 2009-02-04 03:56:19 UTC (rev 15882)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/SQLServerDialect.java 2009-02-04 04:05:44 UTC (rev 15883)
@@ -134,9 +134,9 @@
return false;
}
- public boolean supportsCascadeDelete() {
- return true;
- }
+ public boolean supportsCascadeDelete() {
+ return true;
+ }
public boolean supportsCircularCascadeDeleteConstraints() {
// SQL Server (at least up through 2005) does not support defining
@@ -145,6 +145,10 @@
return false;
}
+ public boolean supportsExpectedLobUsagePattern() {
+ return true;
+ }
+
public boolean supportsLobValueChangePropogation() {
// note: at least my local SQL Server 2005 Express shows this not working...
return false;
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/SybaseDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/SybaseDialect.java 2009-02-04 03:56:19 UTC (rev 15882)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/SybaseDialect.java 2009-02-04 04:05:44 UTC (rev 15883)
@@ -251,6 +251,10 @@
return false;
}
+ public boolean supportsExpectedLobUsagePattern() {
+ return false;
+ }
+
public boolean supportsEmptyInList() {
return false;
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java 2009-02-04 03:56:19 UTC (rev 15882)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java 2009-02-04 04:05:44 UTC (rev 15883)
@@ -6,7 +6,6 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -33,8 +32,8 @@
public void testInterfaceProxies() {
- if ( getDialect() instanceof PostgreSQLDialect ) {
- // TODO : why?
+ if ( ! getDialect().supportsExpectedLobUsagePattern() ) {
+ reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );
return;
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java 2009-02-04 03:56:19 UTC (rev 15882)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java 2009-02-04 04:05:44 UTC (rev 15883)
@@ -27,6 +27,7 @@
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TimesTenDialect;
+import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -498,6 +499,14 @@
//s.refresh(b);
//assertTrue( b.getClob() instanceof ClobImpl );
s.flush();
+
+ // Sybase ASE does not support ResultSet.getBlob(String)
+ if ( getDialect() instanceof SybaseDialect && ! ( getDialect() instanceof SQLServerDialect ) ) {
+ s.connection().rollback();
+ s.close();
+ return;
+ }
+
s.refresh(b);
//b.getBlob().setBytes( 2, "abc".getBytes() );
b.getClob().getSubString(2, 3);
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/lob/SerializableTypeTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/lob/SerializableTypeTest.java 2009-02-04 03:56:19 UTC (rev 15882)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/lob/SerializableTypeTest.java 2009-02-04 04:05:44 UTC (rev 15883)
@@ -4,6 +4,9 @@
import junit.framework.Test;
import org.hibernate.Session;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.SybaseDialect;
+import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -26,11 +29,17 @@
return new FunctionalTestClassTestSuite( SerializableTypeTest.class );
}
+
public String getCacheConcurrencyStrategy() {
return null;
}
public void testNewSerializableType() {
+ // Sybase ASE does not support ResultSet.getBlob(String)
+ if ( getDialect() instanceof SybaseDialect && ! ( getDialect() instanceof SQLServerDialect ) ) {
+ return;
+ }
+
final String payloadText = "Initial payload";
Session s = openSession();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/mixed/MixedTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/mixed/MixedTest.java 2009-02-04 03:56:19 UTC (rev 15882)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/mixed/MixedTest.java 2009-02-04 04:05:44 UTC (rev 15883)
@@ -6,7 +6,6 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -57,7 +56,10 @@
t.commit();
s.close();
- if ( getDialect() instanceof PostgreSQLDialect ) return;
+ if ( ! getDialect().supportsExpectedLobUsagePattern() ) {
+ reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );
+ return;
+ }
s = openSession( new DocumentInterceptor() );
t = s.beginTransaction();
15 years, 2 months