[hibernate-commits] Hibernate SVN: r16056 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Mar 2 12:05:58 EST 2009


Author: hardy.ferentschik
Date: 2009-03-02 12:05:58 -0500 (Mon, 02 Mar 2009)
New Revision: 16056

Removed:
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.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/ConstraintViolationImpl.java
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.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:
- HV-114 Let the ExecutionContext take the role of ConstraintValidatorContextImpl


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-03-02 16:08:45 UTC (rev 16055)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java	2009-03-02 17:05:58 UTC (rev 16056)
@@ -89,39 +89,27 @@
 		return descriptor;
 	}
 
-	public <T, V> void validateConstraints(V value, Class<T> beanClass, ExecutionContext<T> executionContext, List<ConstraintViolationImpl<T>> constraintViolations) {
+	public <T, V> void validateConstraints(V value, ExecutionContext<T> executionContext, List<ConstraintViolationImpl<T>> constraintViolations) {
 		for ( ConstraintTree<?> tree : getChildren() ) {
-			tree.validateConstraints( value, beanClass, executionContext, constraintViolations );
+			tree.validateConstraints( value, executionContext, constraintViolations );
 		}
 
-		final Object leafBeanInstance = executionContext.peekValidatedObject();
 		if ( log.isTraceEnabled() ) {
 			log.trace( "Validating value {} against constraint defined by {}", value, descriptor );
 		}
 		ConstraintValidator<A, V> validator = getInitalizedValidator(
 				value, executionContext.getConstraintValidatorFactory()
 		);
-		ConstraintValidatorContextImpl constraintContext = new ConstraintValidatorContextImpl( descriptor );
-		if ( !validator.isValid( value, constraintContext ) ) {
-			for ( ConstraintValidatorContextImpl.ErrorMessage error : constraintContext.getErrorMessages() ) {
-				final String message = error.getMessage();
-				createConstraintViolation(
-						value, beanClass, executionContext, leafBeanInstance, message, descriptor, constraintViolations
-				);
-			}
+		executionContext.setConstraintDescriptor( descriptor );
+		if ( !validator.isValid( value, executionContext ) ) {
+			constraintViolations.addAll( executionContext.createConstraintViolations( value ) );
 		}
 		if ( reportAsSingleViolation() && constraintViolations.size() > 0 ) {
 			constraintViolations.clear();
 			final String message = ( String ) getParent().getDescriptor().getParameters().get( "message" );
-			createConstraintViolation(
-					value,
-					beanClass,
-					executionContext,
-					leafBeanInstance,
-					message,
-					getParent().descriptor,
-					constraintViolations
-			);
+			final String property = executionContext.peekPropertyPath();
+			ExecutionContext<T>.ErrorMessage error = executionContext.new ErrorMessage( message, property );
+			constraintViolations.add(executionContext.createConstraintViolation( value, error ));
 		}
 	}
 
@@ -130,25 +118,6 @@
 				&& getParent().getDescriptor().isReportAsSingleViolation();
 	}
 
-	private <T> void createConstraintViolation(Object value, Class<T> beanClass, ExecutionContext<T> executionContext, Object leafBeanInstance, String messageTemplate, ConstraintDescriptor descriptor, List<ConstraintViolationImpl<T>> constraintViolations) {
-		String interpolatedMessage = executionContext.getMessageResolver().interpolate(
-				messageTemplate,
-				descriptor,
-				leafBeanInstance
-		);
-		ConstraintViolationImpl<T> failingConstraintViolation = new ConstraintViolationImpl<T>(
-				messageTemplate,
-				interpolatedMessage,
-				executionContext.getRootBean(),
-				beanClass,
-				leafBeanInstance,
-				value,
-				executionContext.peekPropertyPath(), //FIXME use error.getProperty()
-				descriptor
-		);
-		constraintViolations.add( failingConstraintViolation );
-	}
-
 	/**
 	 * @param value The value to be validated.
 	 * @param constraintFactory constraint factory used to instantiate the constraint validator.

Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java	2009-03-02 16:08:45 UTC (rev 16055)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java	2009-03-02 17:05:58 UTC (rev 16056)
@@ -1,84 +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.Collections;
-import java.util.List;
-import javax.validation.ConstraintDescriptor;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Emmanuel Bernard
- */
-public class ConstraintValidatorContextImpl implements ConstraintValidatorContext {
-	private final ConstraintDescriptor constraintDescriptor;
-	private final List<ErrorMessage> errorMessages;
-	private boolean defaultDisabled;
-
-	public ConstraintValidatorContextImpl(ConstraintDescriptor constraintDescriptor) {
-		this.constraintDescriptor = constraintDescriptor;
-		this.errorMessages = new ArrayList<ErrorMessage>(3);
-	}
-
-	public void disableDefaultError() {
-		defaultDisabled = true;
-	}
-
-	public String getDefaultErrorMessage() {
-		return ( String ) constraintDescriptor.getParameters().get("message");
-	}
-
-	public void addError(String message) {
-		//FIXME get the default property if property-level
-		errorMessages.add( new ErrorMessage( message, null ) );
-	}
-
-	public void addError(String message, String property) {
-		//FIXME: make sure the property is valid
-		errorMessages.add( new ErrorMessage( message, property ) );
-	}
-
-	public List<ErrorMessage> getErrorMessages() {
-		List<ErrorMessage> returnedErrorMessages = new ArrayList<ErrorMessage>( errorMessages.size() + 1 );
-		Collections.copy( returnedErrorMessages, errorMessages );
-		if ( ! defaultDisabled ) {
-			//FIXME get the default property if property-level
-			returnedErrorMessages.add( new ErrorMessage( getDefaultErrorMessage(), null) );
-		}
-		return returnedErrorMessages;
-	}
-
-	public static class ErrorMessage {
-		private final String message;
-		private final String property;
-
-		private ErrorMessage(String message, String property) {
-			this.message = message;
-			this.property = property;
-		}
-
-		public String getMessage() {
-			return message;
-		}
-
-		public String getProperty() {
-			return property;
-		}
-	}
-}

Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java	2009-03-02 16:08:45 UTC (rev 16055)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java	2009-03-02 17:05:58 UTC (rev 16056)
@@ -27,7 +27,6 @@
 public class ConstraintViolationImpl<T> implements ConstraintViolation<T> {
 	private String interpolatedMessage;
 	private T rootBean;
-	private Class<T> beanClass;
 	private Object value;
 	private String propertyPath;
 	private Object leafBeanInstance;
@@ -35,13 +34,12 @@
 	private String rawMessage;
 
 
-	public ConstraintViolationImpl(String messageTemplate, String interpolatedMessage, T rootBean, Class<T> beanClass,
+	public ConstraintViolationImpl(String messageTemplate, String interpolatedMessage, T rootBean,
 								   Object leafBeanInstance, Object value,
 								   String propertyPath, ConstraintDescriptor constraintDescriptor) {
 		this.rawMessage = messageTemplate;
 		this.interpolatedMessage = interpolatedMessage;
 		this.rootBean = rootBean;
-		this.beanClass = beanClass;
 		this.value = value;
 		this.propertyPath = propertyPath;
 		this.leafBeanInstance = leafBeanInstance;
@@ -99,9 +97,6 @@
 
 		ConstraintViolationImpl that = ( ConstraintViolationImpl ) o;
 
-		if ( beanClass != null ? !beanClass.equals( that.beanClass ) : that.beanClass != null ) {
-			return false;
-		}
 		if ( interpolatedMessage != null ? !interpolatedMessage.equals( that.interpolatedMessage ) : that.interpolatedMessage != null ) {
 			return false;
 		}
@@ -122,7 +117,6 @@
 	public int hashCode() {
 		int result = interpolatedMessage != null ? interpolatedMessage.hashCode() : 0;
 		result = 31 * result + ( rootBean != null ? rootBean.hashCode() : 0 );
-		result = 31 * result + ( beanClass != null ? beanClass.hashCode() : 0 );
 		result = 31 * result + ( value != null ? value.hashCode() : 0 );
 		result = 31 * result + ( propertyPath != null ? propertyPath.hashCode() : 0 );
 		return result;

Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java	2009-03-02 16:08:45 UTC (rev 16055)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java	2009-03-02 17:05:58 UTC (rev 16056)
@@ -18,10 +18,13 @@
 package org.hibernate.validation.engine;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
+import javax.validation.ConstraintDescriptor;
+import javax.validation.ConstraintValidatorContext;
 import javax.validation.ConstraintValidatorFactory;
 import javax.validation.MessageInterpolator;
 import javax.validation.TraversableResolver;
@@ -29,15 +32,18 @@
 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.
- * Currently the validated object and the property path are processed in a stack fashion.
+ * Context object keeping track of all processed objects and failing constraints.
+ * It also keeps track of the currently validated object, group and property path.
  *
  * @author Hardy Ferentschik
  * @author Emmanuel Bernard
+ * @todo Look for ways to improve this data structure. It is quite fragile and depends on the right oder of calls
+ * in order to work.
  */
-public class ExecutionContext<T> {
+public class ExecutionContext<T> implements ConstraintValidatorContext {
 
+	private static final String PROPERTY_ROOT = "";
+
 	/**
 	 * The root bean of the validation.
 	 */
@@ -55,9 +61,9 @@
 	private final List<ConstraintViolationImpl<T>> failingConstraintViolations;
 
 	/**
-	 * The current property path.
+	 * Keep track of the property path/
 	 */
-	private String propertyPath;
+	private List<String> propertyPath;
 
 	/**
 	 * The current group which is getting processed.
@@ -65,9 +71,15 @@
 	private Class<?> currentGroup;
 
 	/**
+	 * Reference to a <code>ValidatedProperty</code> keeping track of the property we are currently validating,
+	 * together with required meta data.
+	 */
+	private ValidatedProperty currentValidatedProperty;
+
+	/**
 	 * Stack for keeping track of the currently validated object.
 	 */
-	private Stack<Object> validatedObjectStack = new Stack<Object>();
+	private Stack<Object> validatedBeanStack = new Stack<Object>();
 
 	/**
 	 * The message resolver which should be used in this context.
@@ -79,6 +91,9 @@
 	 */
 	private final ConstraintValidatorFactory constraintValidatorFactory;
 
+	/**
+	 * Allows a JPA provider to decide whether a property should be validated.
+	 */
 	private final TraversableResolver traversableResolver;
 
 	public ExecutionContext(T object, MessageInterpolator messageResolver, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
@@ -91,9 +106,9 @@
 		this.constraintValidatorFactory = constraintValidatorFactory;
 		this.traversableResolver = traversableResolver;
 
-		validatedObjectStack.push( object );
+		validatedBeanStack.push( object );
 		processedObjects = new HashMap<Class<?>, IdentitySet>();
-		propertyPath = "";
+		propertyPath = new ArrayList<String>();
 		failingConstraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
 	}
 
@@ -105,22 +120,52 @@
 		return constraintValidatorFactory;
 	}
 
-	public Object peekValidatedObject() {
-		return validatedObjectStack.peek();
+	public void disableDefaultError() {
+		assert currentValidatedProperty != null;
+		currentValidatedProperty.disableDefaultError();
 	}
 
-	public Class<?> peekValidatedObjectType() {
-		return validatedObjectStack.peek().getClass();
+	public String getDefaultErrorMessage() {
+		assert currentValidatedProperty != null;
+		return currentValidatedProperty.getDefaultErrorMessage();
 	}
 
-	public void pushValidatedObject(Object validatedObject) {
-		validatedObjectStack.push( validatedObject );
+	public void addError(String message) {
+		assert currentValidatedProperty != null;
+		currentValidatedProperty.addError( message );
 	}
 
-	public void popValidatedObject() {
-		validatedObjectStack.pop();
+	public void addError(String message, String property) {
+		assert currentValidatedProperty != null;
+		currentValidatedProperty.addError( message, property );
 	}
 
+	public List<ErrorMessage> getErrorMessages() {
+		assert currentValidatedProperty != null;
+		return currentValidatedProperty.getErrorMessages();
+	}
+
+	public void setConstraintDescriptor(ConstraintDescriptor constraintDescriptor) {
+		assert currentValidatedProperty != null;
+		currentValidatedProperty.setConstraintDescriptor( constraintDescriptor );
+	}
+
+	public Object peekValidatedBean() {
+		return validatedBeanStack.peek();
+	}
+
+	public Class<?> peekValidatedBeanType() {
+		return validatedBeanStack.peek().getClass();
+	}
+
+	public void pushValidatedBean(Object validatedBean) {
+		validatedBeanStack.push( validatedBean );
+	}
+
+	public void popValidatedBean() {
+		validatedBeanStack.pop();
+	}
+
 	public T getRootBean() {
 		return rootBean;
 	}
@@ -135,16 +180,16 @@
 
 	public void markProcessedForCurrentGroup() {
 		if ( processedObjects.containsKey( currentGroup ) ) {
-			processedObjects.get( currentGroup ).add( validatedObjectStack.peek() );
+			processedObjects.get( currentGroup ).add( validatedBeanStack.peek() );
 		}
 		else {
 			IdentitySet set = new IdentitySet();
-			set.add( validatedObjectStack.peek() );
+			set.add( validatedBeanStack.peek() );
 			processedObjects.put( currentGroup, set );
 		}
 	}
 
-	public boolean isProcessedForCurrentGroup(Object value) {
+	public boolean isValidatedAgainstCurrentGroup(Object value) {
 		final IdentitySet objectsProcessedInCurrentGroups = processedObjects.get( currentGroup );
 		return objectsProcessedInCurrentGroups != null && objectsProcessedInCurrentGroups.contains( value );
 	}
@@ -176,48 +221,49 @@
 	 * @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;
-		}
+		propertyPath.add( property );
+		currentValidatedProperty = new ValidatedProperty( peekPropertyPath(), getCurrentGroup() );
 	}
 
 	/**
 	 * 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 );
+		if ( propertyPath.size() > 0 ) {
+			propertyPath.remove( propertyPath.size() - 1 );
+			currentValidatedProperty = null;
 		}
-		else {
-			propertyPath = "";
-		}
 	}
 
-	public void appendIndexToPropertyPath(String index) {
-		propertyPath += index;
+	public void markCurrentPropertyAsIndexed() {
+		String property = peekProperty();
+		property += "[]";
+		popProperty();
+		pushProperty( property );
 	}
 
 	public void replacePropertyIndex(String index) {
-		// replace the last occurance of [<oldIndex>] with [<index>] 
-		propertyPath = propertyPath.replaceAll( "\\[[0-9]*\\]$", "[" + index + "]" );
+		// replace the last occurance of [<oldIndex>] with [<index>]
+		String property = peekProperty();
+		property = property.replaceAll( "\\[[0-9]*\\]$", "[" + index + "]" );
+		popProperty();
+		pushProperty( property );
 	}
 
 	public String peekPropertyPath() {
-		return propertyPath;
+		StringBuilder builder = new StringBuilder();
+		for ( String s : propertyPath ) {
+			builder.append( s ).append( "." );
+		}
+		builder.delete( builder.lastIndexOf( "." ), builder.length() );
+		return builder.toString();
 	}
 
 	public String peekProperty() {
-		int lastIndex = propertyPath.lastIndexOf( '.' );
-		if ( lastIndex != -1 ) {
-			return propertyPath.substring( 0, lastIndex );
+		if ( propertyPath.size() == 0 ) {
+			return PROPERTY_ROOT;
 		}
-		else {
-			return "";
-		}
+		return propertyPath.get( propertyPath.size() - 1 );
 	}
 
 	public boolean isValidationRequired(MetaConstraint metaConstraint) {
@@ -227,11 +273,107 @@
 
 		Class<?> rootBeanClass = rootBean == null ? null : rootBean.getClass();
 		return traversableResolver.isTraversable(
-				peekValidatedObject(),
+				peekValidatedBean(),
 				peekProperty(),
 				rootBeanClass,
 				peekPropertyPath(),
 				metaConstraint.getElementType()
 		);
 	}
+
+	public List<ConstraintViolationImpl<T>> createConstraintViolations(Object value) {
+		List<ConstraintViolationImpl<T>> constraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
+		for ( ErrorMessage error : currentValidatedProperty.getErrorMessages() ) {
+			constraintViolations.add( createConstraintViolation( value, error ) );
+		}
+		return constraintViolations;
+	}
+
+	public ConstraintViolationImpl<T> createConstraintViolation(Object value, ErrorMessage error) {
+		ConstraintDescriptor descriptor = currentValidatedProperty.getConstraintDescriptor();
+		String messageTemplate = error.getMessage();
+		String interpolatedMessage = getMessageResolver().interpolate(
+				messageTemplate,
+				descriptor,
+				peekValidatedBean()
+		);
+		return new ConstraintViolationImpl<T>(
+				messageTemplate,
+				interpolatedMessage,
+				getRootBean(),
+				peekValidatedBean(),
+				value,
+				error.getProperty(),
+				descriptor
+		);
+	}
+
+	class ValidatedProperty {
+
+		private final List<ErrorMessage> errorMessages = new ArrayList<ErrorMessage>( 3 );
+		private ConstraintDescriptor constraintDescriptor;
+		private boolean defaultDisabled;
+		private String property;
+		private Class<?> group;
+
+		private ValidatedProperty(String property, Class<?> group) {
+			this.property = property;
+			this.group = group;
+		}
+
+		public void setConstraintDescriptor(ConstraintDescriptor constraintDescriptor) {
+			this.constraintDescriptor = constraintDescriptor;
+		}
+
+		public ConstraintDescriptor getConstraintDescriptor() {
+			return constraintDescriptor;
+		}
+
+		void disableDefaultError() {
+			defaultDisabled = true;
+		}
+
+		public boolean isDefaultErrorDisabled() {
+			return defaultDisabled;
+		}
+
+		public String getDefaultErrorMessage() {
+			return ( String ) constraintDescriptor.getParameters().get( "message" );
+		}
+
+		public void addError(String message) {
+			errorMessages.add( new ErrorMessage( message, property ) );
+		}
+
+		public void addError(String message, String property) {
+			errorMessages.add( new ErrorMessage( message, property ) );
+		}
+
+		public List<ErrorMessage> getErrorMessages() {
+			List<ErrorMessage> returnedErrorMessages = new ArrayList<ErrorMessage>( errorMessages.size() + 1 );
+			Collections.copy( returnedErrorMessages, errorMessages );
+			if ( !defaultDisabled ) {
+				returnedErrorMessages.add( new ErrorMessage( getDefaultErrorMessage(), property ) );
+			}
+			return returnedErrorMessages;
+		}
+	}
+
+	public class ErrorMessage {
+		private final String message;
+		private final String property;
+
+		public ErrorMessage(String message, String property) {
+			this.message = message;
+			this.property = property;
+		}
+
+		public String getMessage() {
+			return message;
+		}
+
+		public String getProperty() {
+			return property;
+		}
+	}
 }
\ No newline at end of file

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-03-02 16:08:45 UTC (rev 16055)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java	2009-03-02 17:05:58 UTC (rev 16056)
@@ -191,11 +191,11 @@
 		return constraintTree;
 	}
 
-	public <T> boolean validateConstraint(Class<T> beanClass, ExecutionContext<T> executionContext) {
-		final Object leafBeanInstance = executionContext.peekValidatedObject();
+	public <T> boolean validateConstraint(ExecutionContext<T> executionContext) {
+		final Object leafBeanInstance = executionContext.peekValidatedBean();
 		Object value = getValue( leafBeanInstance );
 		List<ConstraintViolationImpl<T>> constraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
-		constraintTree.validateConstraints( value, beanClass, executionContext, constraintViolations );
+		constraintTree.validateConstraints( value, executionContext, constraintViolations );
 		if ( constraintViolations.size() > 0 ) {
 			executionContext.addConstraintFailures( constraintViolations );
 			return false;
@@ -203,9 +203,9 @@
 		return true;
 	}
 
-	public <T> boolean validateConstraint(Class<T> beanClass, Object value, ExecutionContext<T> executionContext) {
+	public <T> boolean validateConstraint(Object value, ExecutionContext<T> executionContext) {
 		List<ConstraintViolationImpl<T>> constraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
-		constraintTree.validateConstraints( value, beanClass, executionContext, constraintViolations );
+		constraintTree.validateConstraints( value, executionContext, constraintViolations );
 		if ( constraintViolations.size() > 0 ) {
 			executionContext.addConstraintFailures( constraintViolations );
 			return false;

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-03-02 16:08:45 UTC (rev 16055)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java	2009-03-02 17:05:58 UTC (rev 16056)
@@ -183,7 +183,7 @@
 	 * @return List of invalid constraints.
 	 */
 	private <T> List<ConstraintViolationImpl<T>> validateInContext(ExecutionContext<T> context, GroupChain groupChain) {
-		if ( context.peekValidatedObject() == null ) {
+		if ( context.peekValidatedBean() == null ) {
 			return Collections.emptyList();
 		}
 
@@ -228,7 +228,7 @@
 	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 = getBeanMetaData( ( Class<T> ) executionContext.peekValidatedObjectType() );
+		BeanMetaData<T> beanMetaData = getBeanMetaData( ( Class<T> ) executionContext.peekValidatedBeanType() );
 		if ( executionContext.getCurrentGroup().getName().equals( Default.class.getName() ) ) {
 			List<Class<?>> defaultGroupSequence = beanMetaData.getDefaultGroupSequence();
 			if ( log.isTraceEnabled() && defaultGroupSequence.size() > 0 && defaultGroupSequence.get( 0 ) != Default.class ) {
@@ -265,7 +265,7 @@
 		for ( MetaConstraint<T, ?> metaConstraint : beanMetaData.geMetaConstraintList() ) {
 			executionContext.pushProperty( metaConstraint.getPropertyName() );
 			if ( executionContext.isValidationRequired( metaConstraint ) ) {
-				boolean tmp = metaConstraint.validateConstraint( beanMetaData.getBeanClass(), executionContext );
+				boolean tmp = metaConstraint.validateConstraint(  executionContext );
 				validationSuccessful = validationSuccessful && tmp;
 			}
 			executionContext.popProperty();
@@ -275,12 +275,12 @@
 	}
 
 	private <T> void validateCascadedConstraints(ExecutionContext<T> context) {
-		List<Member> cascadedMembers = getBeanMetaData( context.peekValidatedObjectType() )
+		List<Member> cascadedMembers = getBeanMetaData( context.peekValidatedBeanType() )
 				.getCascadedMembers();
 		for ( Member member : cascadedMembers ) {
 			Type type = ReflectionHelper.typeOf( member );
 			context.pushProperty( ReflectionHelper.getPropertyName( member ) );
-			Object value = ReflectionHelper.getValue( member, context.peekValidatedObject() );
+			Object value = ReflectionHelper.getValue( member, context.peekValidatedBean() );
 			if ( value == null ) {
 				continue;
 			}
@@ -309,12 +309,12 @@
 					( Iterable<?> ) value :
 					map.entrySet();
 			iter = elements.iterator();
-			context.appendIndexToPropertyPath( "[]" );
+			context.markCurrentPropertyAsIndexed();
 		}
 		else if ( ReflectionHelper.isArray( type ) ) {
 			List<?> arrayList = Arrays.asList( value );
 			iter = arrayList.iterator();
-			context.appendIndexToPropertyPath( "[]" );
+			context.markCurrentPropertyAsIndexed();
 		}
 		else {
 			List<Object> list = new ArrayList<Object>();
@@ -340,15 +340,15 @@
 				actualValue = ( ( Map.Entry ) actualValue ).getValue();
 			}
 
-			if ( !context.isProcessedForCurrentGroup( actualValue ) ) {
+			if ( !context.isValidatedAgainstCurrentGroup( actualValue ) ) {
 				context.replacePropertyIndex( propertyIndex );
 
-				context.pushValidatedObject( actualValue );
+				context.pushValidatedBean( actualValue );
 				validateInContext(
 						context,
 						groupChainGenerator.getGroupChainFor( Arrays.asList( new Class<?>[] { context.getCurrentGroup() } ) )
 				);
-				context.popValidatedObject();
+				context.popValidatedBean();
 			}
 			i++;
 		}
@@ -420,9 +420,10 @@
 				context.pushProperty( propertyIter.getOriginalProperty() );
 				context.setCurrentGroup( groupClass );
 				if ( context.isValidationRequired( metaConstraint ) ) {
-					metaConstraint.validateConstraint( ( Class<T> ) object.getClass(), context );
+					metaConstraint.validateConstraint( context );
 					failingConstraintViolations.addAll( context.getFailingConstraints() );
 				}
+				context.popProperty();
 			}
 			if ( failingConstraintViolations.size() > numberOfConstraintViolationsBefore ) {
 				break;
@@ -495,11 +496,11 @@
 				);
 				context.pushProperty( propertyIter.getOriginalProperty() );
 				context.setCurrentGroup( groupClass );
-
 				if ( context.isValidationRequired( metaConstraint ) ) {
-					metaConstraint.validateConstraint( beanType, value, context );
+					metaConstraint.validateConstraint( value, context );
 					failingConstraintViolations.addAll( context.getFailingConstraints() );
 				}
+				context.popProperty();
 			}
 			if ( failingConstraintViolations.size() > numberOfConstraintViolations ) {
 				break;




More information about the hibernate-commits mailing list