Hibernate SVN: r16954 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-26 04:23:23 -0400 (Fri, 26 Jun 2009)
New Revision: 16954
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
Log:
Moved the marking of a processed group into the for loop where it belongs.
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-06-26 08:14:34 UTC (rev 16953)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-26 08:23:23 UTC (rev 16954)
@@ -206,7 +206,7 @@
BeanMetaData<U> beanMetaData = getBeanMetaData( localExecutionContext.getCurrentBeanType() );
if ( beanMetaData.defaultGroupSequenceIsRedefined() ) {
- groupChain.assertDefaulGroupSequenceIsExpandable(beanMetaData.getDefaultGroupSequence());
+ groupChain.assertDefaulGroupSequenceIsExpandable( beanMetaData.getDefaultGroupSequence() );
}
// process first single groups. For these we can skip some object traversal, by first running all validations on the current bean
@@ -291,12 +291,12 @@
boolean tmp = metaConstraint.validateConstraint( globalExecutionContext, localExecutionContext );
validationSuccessful = validationSuccessful && tmp;
}
+ globalExecutionContext.markProcessed(
+ localExecutionContext.getCurrentBean(),
+ localExecutionContext.getCurrentGroup(),
+ localExecutionContext.getPropertyPath()
+ );
}
- globalExecutionContext.markProcessed(
- localExecutionContext.getCurrentBean(),
- localExecutionContext.getCurrentGroup(),
- localExecutionContext.getPropertyPath()
- );
return validationSuccessful;
}
15 years, 6 months
Hibernate SVN: r16953 - core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-26 04:14:34 -0400 (Fri, 26 Jun 2009)
New Revision: 16953
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java
Log:
Made annotations compile again after latest changes to Hibernate Validator
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java 2009-06-25 15:43:42 UTC (rev 16952)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java 2009-06-26 08:14:34 UTC (rev 16953)
@@ -94,7 +94,7 @@
catch ( ClassNotFoundException e ) {
throw new AssertionFailure( "Entity class not found", e);
}
-
+
try {
applyDDL( "", persistentClass, clazz, factory, groups, true );
}
@@ -215,7 +215,7 @@
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDesc) {
if ( Size.class.equals( descriptor.getAnnotation().annotationType() )
- && String.class.equals( propertyDesc.getType() ) ) {
+ && String.class.equals( propertyDesc.getElementClass() ) ) {
@SuppressWarnings( "unchecked" )
ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
int max = sizeConstraint.getAnnotation().max();
15 years, 6 months
Hibernate SVN: r16952 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-25 11:43:42 -0400 (Thu, 25 Jun 2009)
New Revision: 16952
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/SequenceResolutionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/TestEntity.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainTest.java
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/groups/Group.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChain.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChainGenerator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaData.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java
Log:
HV-170 - Refactor the group sequence expansion and take the default sequence expansion of the validated entity into considertation
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/SequenceResolutionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/SequenceResolutionTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/SequenceResolutionTest.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -0,0 +1,44 @@
+// $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.jsr303.tck.tests.constraints.groups.defaultgroupsequence;
+
+import javax.validation.GroupDefinitionException;
+import javax.validation.Validator;
+
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+public class SequenceResolutionTest extends AbstractTest {
+
+ @Test(expectedExceptions = GroupDefinitionException.class)
+ public void testInvalidDefinitionOfDefaultSequenceInEntity() {
+ Validator validator = TestUtil.getDefaultValidator();
+ TestEntity entity = new TestEntity();
+ validator.validate( entity, Complete.class );
+ }
+}
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/TestEntity.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/TestEntity.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/defaultgroupsequence/TestEntity.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -0,0 +1,38 @@
+// $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.jsr303.tck.tests.constraints.groups.defaultgroupsequence;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@GroupSequence({ TimeConsumingChecks.class, TestEntity.class })
+public class TestEntity {
+ @NotNull
+ public String foo;
+}
+
+interface TimeConsumingChecks {
+}
+
+@GroupSequence({ Default.class, TimeConsumingChecks.class })
+interface Complete {
+}
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-06-25 11:12:54 UTC (rev 16951)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -75,13 +75,29 @@
private final transient GroupChainGenerator groupChainGenerator;
private final ConstraintValidatorFactory constraintValidatorFactory;
+
+ /**
+ * {@link MessageInterpolator} as passed to the constructor of this instance.
+ */
private final MessageInterpolator messageInterpolator;
- //never use it directly, always use getCachingTraversableResolver() to retrieved the single threaded caching wrapper.
+
+ /**
+ * {@link TraversableResolver} as passed to the constructor of this instance.
+ * Never use it directly, always use {@link #getCachingTraversableResolver()} to retrieved the single threaded caching wrapper.
+ */
private final TraversableResolver traversableResolver;
+
+ /**
+ * Passed at creation time of this validator instance.
+ */
private final ConstraintHelper constraintHelper;
+
+ /**
+ * Used to get access to the bean meta data. Used to avoid to parsing the constraint configuration for each call
+ * of a given entity.
+ */
private final BeanMetaDataCache beanMetaDataCache;
-
public ValidatorImpl(ConstraintValidatorFactory constraintValidatorFactory, MessageInterpolator messageInterpolator, TraversableResolver traversableResolver, ConstraintHelper constraintHelper, BeanMetaDataCache beanMetaDataCache) {
this.constraintValidatorFactory = constraintValidatorFactory;
this.messageInterpolator = messageInterpolator;
@@ -96,6 +112,7 @@
if ( object == null ) {
throw new IllegalArgumentException( "Validation of a null object" );
}
+
GroupChain groupChain = determineGroupExecutionOrder( groups );
GlobalExecutionContext<T> context = GlobalExecutionContext.getContextForValidate(
@@ -185,9 +202,13 @@
}
path = PathImpl.createShallowCopy( path );
-
LocalExecutionContext<U, V> localExecutionContext = LocalExecutionContext.getLocalExecutionContext( value );
+ BeanMetaData<U> beanMetaData = getBeanMetaData( localExecutionContext.getCurrentBeanType() );
+ if ( beanMetaData.defaultGroupSequenceIsRedefined() ) {
+ groupChain.assertDefaulGroupSequenceIsExpandable(beanMetaData.getDefaultGroupSequence());
+ }
+
// process first single groups. For these we can skip some object traversal, by first running all validations on the current bean
// before traversing the object.
Iterator<Group> groupIterator = groupChain.getGroupIterator();
@@ -231,9 +252,7 @@
* @param <T> The type of the root bean
*/
private <T, U, V> void validateConstraints(GlobalExecutionContext<T> executionContext, LocalExecutionContext<U, V> localExecutionContext, PathImpl path) {
- //casting rely on the fact that root object is at the top of the stack
- @SuppressWarnings("unchecked")
- BeanMetaData<T> beanMetaData = getBeanMetaData( ( Class<T> ) localExecutionContext.getCurrentBeanType() );
+ BeanMetaData<U> beanMetaData = getBeanMetaData( localExecutionContext.getCurrentBeanType() );
if ( localExecutionContext.getCurrentGroup().getName().equals( Default.class.getName() ) ) {
List<Class<?>> defaultGroupSequence = beanMetaData.getDefaultGroupSequence();
if ( log.isTraceEnabled() && defaultGroupSequence.size() > 0 && defaultGroupSequence.get( 0 ) != Default.class ) {
@@ -258,9 +277,9 @@
}
}
- private <T, U, V> boolean validateConstraintsForCurrentGroup(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, BeanMetaData<T> beanMetaData, PathImpl path) {
+ private <T, U, V> boolean validateConstraintsForCurrentGroup(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, BeanMetaData<U> beanMetaData, PathImpl path) {
boolean validationSuccessful = true;
- for ( MetaConstraint<T, ?> metaConstraint : beanMetaData.geMetaConstraintList() ) {
+ for ( MetaConstraint<U, ?> metaConstraint : beanMetaData.geMetaConstraintList() ) {
PathImpl newPath = PathImpl.createShallowCopy( path );
if ( !"".equals( metaConstraint.getPropertyName() ) ) {
newPath.addNode( new NodeImpl( metaConstraint.getPropertyName() ) );
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/Group.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/Group.java 2009-06-25 11:12:54 UTC (rev 16951)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/Group.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -25,7 +25,14 @@
* @author Hardy Ferentschik
*/
public class Group {
+ /**
+ * The actual group.
+ */
private Class<?> group;
+
+ /**
+ * The sequence the group is part of ({@code null}, if this group is not part of a sequence).
+ */
private Class<?> sequence;
public Group(Class<?> group) {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChain.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChain.java 2009-06-25 11:12:54 UTC (rev 16951)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChain.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -18,43 +18,41 @@
package org.hibernate.validation.engine.groups;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import javax.validation.GroupDefinitionException;
+import javax.validation.groups.Default;
/**
- * An instance of <code>GroupExecutionChain</code> defines the order in to validate groups during the validation process.
+ * An instance of {@code GroupChain} defines the group order during one full validation call.
*
* @author Hardy Ferentschik
*/
public class GroupChain {
/**
- * The list of single groups.
+ * The list of single groups to be used this validation.
*/
private List<Group> groupList = new ArrayList<Group>();
/**
- * The list of sequences.
+ * The different sequences for this validation. The map contains the list of groups mapped to their sequence
+ * name.
*/
- private List<List<Group>> sequenceList = new ArrayList<List<Group>>();
+ private Map<Class<?>, List<Group>> sequenceMap = new HashMap<Class<?>, List<Group>>();
public Iterator<Group> getGroupIterator() {
return groupList.iterator();
}
public Iterator<List<Group>> getSequenceIterator() {
- return sequenceList.iterator();
+ return sequenceMap.values().iterator();
}
public boolean containsSequence(Class<?> groupSequence) {
- boolean result = false;
- for ( List<Group> sequence : sequenceList ) {
- if ( sequence.get( 0 ).getSequence().getName().equals( groupSequence.getName() ) ) {
- result = true;
- break;
- }
- }
- return result;
+ return sequenceMap.containsKey( groupSequence );
}
void insertGroup(Group group) {
@@ -68,8 +66,62 @@
return;
}
- if ( !sequenceList.contains( groups ) ) {
- sequenceList.add( groups );
+ if ( !sequenceMap.containsValue( groups ) ) {
+ sequenceMap.put( groups.get( 0 ).getSequence(), groups );
}
}
+
+ @Override
+ public String toString() {
+ return "GroupChain{" +
+ "groupList=" + groupList +
+ ", sequenceMap=" + sequenceMap +
+ '}';
+ }
+
+ public void assertDefaulGroupSequenceIsExpandable(List<Class<?>> defaultGroupSequence) {
+ for ( Map.Entry<Class<?>, List<Group>> entry : sequenceMap.entrySet() ) {
+ Class<?> sequence = entry.getKey();
+ List<Group> groupList = entry.getValue();
+ List<Group> defaultGroupList = buildTempGroupList( defaultGroupSequence, sequence );
+ int defaultGroupIndex = containsDefaultGroupAtIndex( sequence, groupList );
+ if ( defaultGroupIndex != -1 ) {
+ ensureDefaultGroupSequenceIsExpandable( groupList, defaultGroupList, defaultGroupIndex );
+ }
+ }
+ }
+
+ private void ensureDefaultGroupSequenceIsExpandable(List<Group> groupList, List<Group> defaultGroupList, int defaultGroupIndex) {
+ for ( int i = 0; i < defaultGroupList.size(); i++ ) {
+ Group group = defaultGroupList.get( i );
+ if(group.getGroup().equals( Default.class )) {
+ continue; // we don't have to consider the default group since it is the one we want to replace
+ }
+ int index = groupList.indexOf( group ); // check whether the sequence contains group of the default group sequence
+ if ( index == -1 ) {
+ continue; // if the group is not in the sequence we can continue
+ }
+
+ if ( ( i == 0 && index == defaultGroupIndex - 1 ) || ( i == defaultGroupList.size() - 1 && index == defaultGroupIndex + 1 ) ) {
+ // if we are at the beginning or end of he defaultGroupSequence and the matches are either directly before resp after we can continue as well,
+ // since we basically have two groups
+ continue;
+ }
+ throw new GroupDefinitionException( "Unable to expand default group list" + defaultGroupList + " into sequence " + groupList );
+ }
+ }
+
+ private int containsDefaultGroupAtIndex(Class<?> sequence, List<Group> groupList) {
+ Group defaultGroup = new Group( Default.class, sequence );
+ return groupList.indexOf( defaultGroup );
+ }
+
+ private List<Group> buildTempGroupList(List<Class<?>> defaultGroupSequence, Class<?> sequence) {
+ List<Group> groupList = new ArrayList<Group>();
+ for ( Class<?> clazz : defaultGroupSequence ) {
+ Group g = new Group( clazz, sequence );
+ groupList.add( g );
+ }
+ return groupList;
+ }
}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChainGenerator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChainGenerator.java 2009-06-25 11:12:54 UTC (rev 16951)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChainGenerator.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -90,7 +90,7 @@
List<Group> resolvedGroupSequence = new ArrayList<Group>();
GroupSequence sequenceAnnotation = group.getAnnotation( GroupSequence.class );
Class<?>[] sequenceArray = sequenceAnnotation.value();
- for ( Class clazz : sequenceArray ) {
+ for ( Class<?> clazz : sequenceArray ) {
if ( clazz.getAnnotation( GroupSequence.class ) == null ) {
resolvedGroupSequence.add( new Group( clazz, group ) );
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaData.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaData.java 2009-06-25 11:12:54 UTC (rev 16951)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaData.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -24,8 +24,6 @@
import javax.validation.metadata.BeanDescriptor;
import javax.validation.metadata.PropertyDescriptor;
-import org.hibernate.validation.metadata.MetaConstraint;
-
/**
* Interface defining the meta data about the constraints defined in a given bean.
*
@@ -39,7 +37,7 @@
Class<T> getBeanClass();
/**
- * @return an instance of <code>ElementDescriptor</code> describing the bean this meta data applies for.
+ * @return an instance of {@code ElementDescriptor} describing the bean this meta data applies for.
*/
BeanDescriptor getBeanDescriptor();
@@ -54,17 +52,22 @@
List<Class<?>> getDefaultGroupSequence();
/**
- * @return A list of <code>MetaConstraint</code> instances encapsulating the information of all the constraints
+ * @return {@code true} if the entity redefines the default group sequence, {@code false} otherwise.
+ */
+ boolean defaultGroupSequenceIsRedefined();
+
+ /**
+ * @return A list of {@code MetaConstraint} instances encapsulating the information of all the constraints
* defined on the bean.
*/
List<MetaConstraint<T, ? extends Annotation>> geMetaConstraintList();
/**
- * Return <code>PropertyDescriptor</code> for the given property.
+ * Return {@code PropertyDescriptor} for the given property.
*
* @param property the property for which to retrieve the descriptor.
*
- * @return Returns the <code>PropertyDescriptor</code> for the given property or <code>null</code> in case the
+ * @return Returns the {@code PropertyDescriptor} for the given property or {@code null} in case the
* property does not have a descriptor.
*/
PropertyDescriptor getPropertyDescriptor(String property);
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java 2009-06-25 11:12:54 UTC (rev 16951)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -137,6 +137,10 @@
return Collections.unmodifiableList( defaultGroupSequence );
}
+ public boolean defaultGroupSequenceIsRedefined() {
+ return defaultGroupSequence.size() > 1;
+ }
+
public void setDefaultGroupSequence(List<Class<?>> groupSequence) {
defaultGroupSequence = new ArrayList<Class<?>>();
boolean groupSequenceContainsDefault = false;
@@ -331,7 +335,7 @@
@SuppressWarnings("unchecked")
private <A extends Annotation> ConstraintDescriptorImpl buildConstraintDescriptor(Class<?> clazz, A annotation) {
ConstraintDescriptorImpl constraintDescriptor;
- if ( clazz.isInterface() && !clazz.equals( beanClass)) {
+ if ( clazz.isInterface() && !clazz.equals( beanClass ) ) {
constraintDescriptor = new ConstraintDescriptorImpl( annotation, constraintHelper, clazz );
}
else {
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainTest.java 2009-06-25 15:43:42 UTC (rev 16952)
@@ -0,0 +1,162 @@
+// $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.groups;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.GroupDefinitionException;
+import javax.validation.groups.Default;
+
+import static org.testng.FileAssert.fail;
+import org.testng.annotations.Test;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class GroupChainTest {
+ @Test
+ public void testAssertDefaulGroupSequenceIsExpandableWithDefaultAtEndOfSequence() {
+ // create a dummy sequence
+ Group a = new Group( GroupA.class, TestSequence.class );
+ Group b = new Group( GroupB.class, TestSequence.class );
+ Group c = new Group( GroupC.class, TestSequence.class );
+ Group defaultGroup = new Group(
+ Default.class, TestSequence.class
+ );
+ List<Group> sequence = new ArrayList<Group>();
+ sequence.add( a );
+ sequence.add( b );
+ sequence.add( c );
+ sequence.add( defaultGroup );
+
+ GroupChain chain = new GroupChain();
+ chain.insertSequence( sequence );
+
+ // create test default sequence
+ List<Class<?>> defaultSequence = new ArrayList<Class<?>>();
+ defaultSequence.add( Default.class );
+ defaultSequence.add( GroupA.class );
+ try {
+ chain.assertDefaulGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( GroupA.class );
+ defaultSequence.add( Default.class );
+ try {
+ chain.assertDefaulGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( Default.class );
+ defaultSequence.add( GroupC.class );
+ try {
+ chain.assertDefaulGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( GroupC.class );
+ defaultSequence.add( Default.class );
+ chain.assertDefaulGroupSequenceIsExpandable( defaultSequence );
+ }
+
+
+ @Test
+ public void testAssertDefaulGroupSequenceIsExpandableWithDefaultAtBeginningOfSequence() {
+ // create a dummy sequence
+ Group a = new Group( GroupA.class, TestSequence.class );
+ Group b = new Group( GroupB.class, TestSequence.class );
+ Group c = new Group( GroupC.class, TestSequence.class );
+ Group defaultGroup = new Group(
+ Default.class, TestSequence.class
+ );
+ List<Group> sequence = new ArrayList<Group>();
+ sequence.add( defaultGroup );
+ sequence.add( a );
+ sequence.add( b );
+ sequence.add( c );
+
+ GroupChain chain = new GroupChain();
+ chain.insertSequence( sequence );
+
+ // create test default sequence
+ List<Class<?>> defaultSequence = new ArrayList<Class<?>>();
+ defaultSequence.add( Default.class );
+ defaultSequence.add( GroupA.class );
+ chain.assertDefaulGroupSequenceIsExpandable( defaultSequence );
+
+
+ defaultSequence.clear();
+ defaultSequence.add( GroupA.class );
+ defaultSequence.add( Default.class );
+ try {
+ chain.assertDefaulGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( Default.class );
+ defaultSequence.add( GroupC.class );
+ try {
+ chain.assertDefaulGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( GroupC.class );
+ defaultSequence.add( Default.class );
+ try {
+ chain.assertDefaulGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+ }
+}
+
+interface TestSequence {
+}
+
+interface GroupA {
+}
+
+interface GroupB {
+}
+
+interface GroupC {
+}
15 years, 6 months
Hibernate SVN: r16951 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-25 07:12:54 -0400 (Thu, 25 Jun 2009)
New Revision: 16951
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Path.java
Log:
enabledkeyword substitution
Property changes on: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Path.java
___________________________________________________________________
Name: svn:keywords
+ Id
15 years, 6 months
Hibernate SVN: r16950 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validation/util and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-25 06:14:40 -0400 (Thu, 25 Jun 2009)
New Revision: 16950
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
Log:
Made sure that no new path node is added when validating a class level consrtaint.
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-06-25 10:13:28 UTC (rev 16949)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-25 10:14:40 UTC (rev 16950)
@@ -262,7 +262,9 @@
boolean validationSuccessful = true;
for ( MetaConstraint<T, ?> metaConstraint : beanMetaData.geMetaConstraintList() ) {
PathImpl newPath = PathImpl.createShallowCopy( path );
- newPath.addNode( new NodeImpl( metaConstraint.getPropertyName() ) );
+ if ( !"".equals( metaConstraint.getPropertyName() ) ) {
+ newPath.addNode( new NodeImpl( metaConstraint.getPropertyName() ) );
+ }
localExecutionContext.setPropertyPath( newPath );
if ( isValidationRequired( globalExecutionContext, localExecutionContext, metaConstraint ) ) {
Object valueToValidate = metaConstraint.getValue( localExecutionContext.getCurrentBean() );
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-06-25 10:13:28 UTC (rev 16949)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-06-25 10:14:40 UTC (rev 16950)
@@ -32,6 +32,7 @@
import org.hibernate.validation.HibernateValidationProvider;
import org.hibernate.validation.engine.HibernateValidatorConfiguration;
+import org.hibernate.validation.engine.PathImpl;
/**
* Tests for the <code>ReflectionHelper</code>.
@@ -114,8 +115,8 @@
public static void assertConstraintViolation(ConstraintViolation violation, String errorMessage, Class rootBean, Object invalidValue, String propertyPath) {
assertEquals(
- violation.getPropertyPath().toString(),
- propertyPath,
+ violation.getPropertyPath(),
+ PathImpl.createPathFromString( propertyPath ),
"Wrong propertyPath"
);
assertConstraintViolation( violation, errorMessage, rootBean, invalidValue );
15 years, 6 months
Hibernate SVN: r16949 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validation/metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-25 06:13:28 -0400 (Thu, 25 Jun 2009)
New Revision: 16949
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/LocalExecutionContext.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/NodeImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PathImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java
Log:
svn:keyword set to Id
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/LocalExecutionContext.java
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/NodeImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PathImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
15 years, 6 months
Hibernate SVN: r16948 - in beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck: tests/bootstrap/defaultprovider and 17 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-25 06:10:13 -0400 (Thu, 25 Jun 2009)
New Revision: 16948
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/ConstraintInheritanceTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Fubar.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/invalidconstraintdefinitions/InvalidConstraintDefinitionsTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/PlayedWith.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/TraversableResolverTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/validatorcontext/ConstraintValidatorContextTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
Log:
Updated the tests to be independend of a string comparison when comparing path
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -43,7 +43,7 @@
* the Bean Validation API itself!?
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class CustomProviderResolverTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -38,7 +38,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
@Resource( source = "javax.validation.spi.ValidationProvider", destination = "WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider")
@IntegrationTest
public class ExplicitCustomProviderBootstrapTest extends AbstractTest {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -58,7 +58,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class BootstrapTest extends AbstractTest {
private static final String SERVICES_FILE = "META-INF/services/" + ValidationProvider.class.getName();
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -41,7 +41,7 @@
@Artifact(artifactType = ArtifactType.JSR303)
@Resource(source = "empty-constraints.xml",
destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/configuration/empty-constraints.xml")
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class MappingStreamHandlingTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -62,7 +62,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class BuiltinConstraintsTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -43,7 +43,7 @@
@Artifact(artifactType = ArtifactType.JSR303)
@Resource(source = "builtin-constraints-override.xml",
destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml")
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class BuiltinValidatorOverrideTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -54,7 +54,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class ConstraintCompositionTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -39,7 +39,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class ConstraintDefinitionsTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -49,7 +49,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class DefaultGroupRedefinitionTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -39,6 +39,7 @@
import org.hibernate.jsr303.tck.util.TestUtil;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertEqualPaths;
/**
* Tests for the group and group sequence feature.
@@ -46,7 +47,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class GroupTest extends AbstractTest {
@Test
@@ -182,7 +183,7 @@
assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
- assertEquals( constraintViolation.getPropertyPath().toString(), "title", "Wrong propertyName" );
+ assertCorrectPropertyPaths( constraintViolations, "title" );
book.setTitle( "Hibernate Persistence with JPA" );
book.setSubtitle( "Revised Edition of Hibernate in Action" );
@@ -193,7 +194,7 @@
assertEquals( constraintViolation.getMessage(), "size must be between 0 and 30", "Wrong message" );
assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), book.getSubtitle(), "Wrong value" );
- assertCorrectPropertyPaths(constraintViolations, "subtitle");
+ assertCorrectPropertyPaths( constraintViolations, "subtitle" );
book.setSubtitle( "Revised Edition" );
author.setCompany( "JBoss a divison of RedHat" );
@@ -204,7 +205,7 @@
assertEquals( constraintViolation.getMessage(), "size must be between 0 and 20" );
assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), author.getCompany(), "Wrong value" );
- assertCorrectPropertyPaths(constraintViolations, "author.company");
+ assertCorrectPropertyPaths( constraintViolations, "author.company" );
author.setCompany( "JBoss" );
@@ -234,7 +235,7 @@
assertEquals( constraintViolation.getMessage(), "may not be null", "Wrong message" );
assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
- assertCorrectPropertyPaths(constraintViolations, "title");
+ assertCorrectPropertyPaths( constraintViolations, "title" );
book.setTitle( "Hibernate Persistence with JPA" );
book.setSubtitle( "Revised Edition of Hibernate in Action" );
@@ -306,7 +307,9 @@
);
for ( ConstraintViolation<User> constraintViolation : constraintViolations ) {
- if ( constraintViolation.getPropertyPath().toString().equals( "defaultCreditCard" ) ) {
+ if ( assertEqualPaths(
+ constraintViolation.getPropertyPath(), TestUtil.PathImpl.createPathFromString( "defaultCreditCard" )
+ ) ) {
TestUtil.assertConstraintViolation(
constraintViolation,
User.class,
@@ -314,7 +317,9 @@
"defaultCreditCard"
);
}
- else if ( constraintViolation.getPropertyPath().toString().equals( "phoneNumber" ) ) {
+ else if ( assertEqualPaths(
+ constraintViolation.getPropertyPath(), TestUtil.PathImpl.createPathFromString( "phoneNumber" )
+ ) ) {
TestUtil.assertConstraintViolation(
constraintViolation,
User.class,
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/ConstraintInheritanceTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/ConstraintInheritanceTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/ConstraintInheritanceTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -38,7 +38,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class ConstraintInheritanceTest extends AbstractTest {
@Test
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Fubar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/invalidconstraintdefinitions/InvalidConstraintDefinitionsTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/invalidconstraintdefinitions/InvalidConstraintDefinitionsTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/invalidconstraintdefinitions/InvalidConstraintDefinitionsTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -35,7 +35,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class InvalidConstraintDefinitionsTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -43,7 +43,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class ValidatorResolutionTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -42,7 +42,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class BeanDescriptorTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -44,7 +44,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class ConstraintDescriptorTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -37,7 +37,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class PropertyDescriptorTest extends AbstractTest {
@Test
@SpecAssertion(section = "5.4", id = "a")
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -1,4 +1,4 @@
-// $Id: ActorListBased.java 16840 2009-06-19 11:38:29Z hardy.ferentschik $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -1,4 +1,4 @@
-// $Id: ActorListBased.java 16840 2009-06-19 11:38:29Z hardy.ferentschik $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/PlayedWith.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -1,4 +1,4 @@
-// $Id: ValidateTest.java 16824 2009-06-17 20:57:08Z hardy.ferentschik $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -44,7 +44,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class ValidatePropertyTest extends AbstractTest {
//TODO Needs verification
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -49,7 +49,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class ValidateTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -1,4 +1,4 @@
-// $Id: ValidateTest.java 16824 2009-06-17 20:57:08Z hardy.ferentschik $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -38,7 +38,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class ValidateValueTest extends AbstractTest {
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -42,7 +42,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class CustomConstraintValidatorTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -38,7 +38,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class GraphNavigationTest extends AbstractTest {
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/TraversableResolverTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/TraversableResolverTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/TraversableResolverTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -36,7 +36,7 @@
* @author Emmanuel Bernard
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class TraversableResolverTest extends AbstractTest {
@Test
public void testCorrectPathsAreRequested() {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/validatorcontext/ConstraintValidatorContextTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/validatorcontext/ConstraintValidatorContextTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/validatorcontext/ConstraintValidatorContextTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -34,12 +34,13 @@
import org.hibernate.jsr303.tck.util.TestUtil;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertEqualPaths;
/**
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class ConstraintValidatorContextTest extends AbstractTest {
@Test
@@ -107,10 +108,12 @@
boolean validatedNestedBean = false;
for ( ConstraintViolation<DummyBean> violation : constraintViolations ) {
- if ( violation.getPropertyPath().toString().equals( "value" ) ) {
+ if ( assertEqualPaths( violation.getPropertyPath(), TestUtil.PathImpl.createPathFromString( "value" ) ) ) {
assertEquals( "dummy message", violation.getMessage(), "Wrong message" );
}
- else if ( violation.getPropertyPath().toString().equals( "nestedDummy.value" ) ) {
+ else if ( assertEqualPaths(
+ violation.getPropertyPath(), TestUtil.PathImpl.createPathFromString( "nestedDummy.value" )
+ ) ) {
assertEquals( "dummy message", violation.getMessage(), "Wrong message" );
validatedNestedBean = true;
}
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -1,4 +1,4 @@
-// $Id: CustomConstraintValidatorTest.java 16835 2009-06-18 16:29:46Z hardy.ferentschik $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -38,7 +38,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
public class CustomConstraintValidatorTest extends AbstractTest {
@SpecAssertion(section = "2.5", id = "a")
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -1,4 +1,4 @@
-// $Id: MyConstraint.java 16835 2009-06-18 16:29:46Z hardy.ferentschik $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -1,4 +1,4 @@
-// $Id: MyConstraint.java 16835 2009-06-18 16:29:46Z hardy.ferentschik $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -1,4 +1,4 @@
-// $Id: MyConstraintValidator.java 16835 2009-06-18 16:29:46Z hardy.ferentschik $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -35,7 +35,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
@ValidationXml(value = "validation-no-additional-config.xml")
@Resource(source = "order-constraints-no-additional-config.xml",
destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml")
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -34,7 +34,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
@ValidationXml(value = "validation-invalid-xml.xml")
public class InvalidXmlConfigurationTest extends AbstractTest {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -38,7 +38,7 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
+(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
@ValidationXml(value = "validation.xml")
@Resources(
{
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-24 17:39:28 UTC (rev 16947)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-25 10:10:13 UTC (rev 16948)
@@ -20,8 +20,11 @@
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.validation.ConstraintViolation;
import javax.validation.Path;
import javax.validation.Validation;
@@ -32,6 +35,7 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
+import static org.testng.FileAssert.fail;
/**
* @author Hardy Ferentschik
@@ -82,26 +86,32 @@
}
public static <T> void assertCorrectPropertyPaths(Set<ConstraintViolation<T>> violations, String... propertyPaths) {
- List<String> propertyPathsOfViolations = new ArrayList<String>();
+ List<Path> propertyPathsOfViolations = new ArrayList<Path>();
for ( ConstraintViolation<?> violation : violations ) {
- propertyPathsOfViolations.add( violation.getPropertyPath().toString() );
+ propertyPathsOfViolations.add( violation.getPropertyPath() );
}
for ( String propertyPath : propertyPaths ) {
- assertTrue(
- propertyPathsOfViolations.contains( propertyPath ),
- propertyPath + " should be used in at least one constraint violation"
- );
+ Path expectedPath = PathImpl.createPathFromString( propertyPath );
+ boolean containsPath = false;
+ for ( Path actualPath : propertyPathsOfViolations ) {
+ if ( assertEqualPaths( expectedPath, actualPath ) ) {
+ containsPath = true;
+ break;
+ }
+ }
+ if ( !containsPath ) {
+ fail( expectedPath + " is not in the list of path instances contained in the actual constraint violations" );
+ }
}
}
public static <T> void assertConstraintViolation(ConstraintViolation<T> violation, Class<?> rootBean, Object invalidValue, String propertyPath) {
+ if ( !assertEqualPaths( violation.getPropertyPath(), PathImpl.createPathFromString( propertyPath ) ) ) {
+ fail( "Property paths differ." );
+ }
+
assertEquals(
- violation.getPropertyPath().toString(),
- propertyPath,
- "Wrong propertyPath."
- );
- assertEquals(
violation.getRootBean().getClass(),
rootBean,
"Wrong root bean."
@@ -113,6 +123,53 @@
);
}
+ public static boolean assertEqualPaths(Path p1, Path p2) {
+ Iterator<Path.Node> p1Iterator = p1.iterator();
+ Iterator<Path.Node> p2Iterator = p2.iterator();
+ while ( p1Iterator.hasNext() ) {
+ Path.Node p1Node = p1Iterator.next();
+ if ( !p2Iterator.hasNext() ) {
+ return false;
+ }
+ Path.Node p2Node = p2Iterator.next();
+
+ // do the comparison on the node values
+ if ( p2Node.getName() == null ) {
+ if ( p1Node.getName() != null ) {
+ return false;
+ }
+ }
+ else if ( !p2Node.getName().equals( p1Node.getName() ) ) {
+ return false;
+ }
+
+ if ( p2Node.isInIterable() != p1Node.isInIterable() ) {
+ return false;
+ }
+
+
+ if ( p2Node.getIndex() == null ) {
+ if ( p1Node.getIndex() != null ) {
+ return false;
+ }
+ }
+ else if ( !p2Node.getIndex().equals( p1Node.getIndex() ) ) {
+ return false;
+ }
+
+ if ( p2Node.getKey() == null ) {
+ if ( p1Node.getKey() != null ) {
+ return false;
+ }
+ }
+ else if ( !p2Node.getKey().equals( p1Node.getKey() ) ) {
+ return false;
+ }
+ }
+
+ return !p2Iterator.hasNext();
+ }
+
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String property) {
Validator validator = getDefaultValidator();
return validator.getConstraintsForClass( clazz ).getConstraintsForProperty( property );
@@ -133,4 +190,167 @@
}
return inputStream;
}
+
+ public static class PathImpl implements Path {
+
+ /**
+ * Regular expression used to split a string path into its elements.
+ *
+ * @see <a href="http://www.regexplanet.com/simple/index.jsp">Regular expression tester</a>
+ */
+ private static final Pattern pathPattern = Pattern.compile( "(\\w+)(\\[(\\w?)\\])?(\\.(.*))*" );
+
+ private static final String PROPERTY_PATH_SEPERATOR = ".";
+
+ private static final Node ROOT_NODE = new NodeImpl( ( String ) null );
+
+ private final List<Node> nodeList;
+
+ public static PathImpl createPathFromString(String propertyPath) {
+ if ( propertyPath == null ) {
+ throw new IllegalArgumentException( "null is not allowed as property path." );
+ }
+
+ if ( propertyPath.length() == 0 ) {
+ return createNewRootPath();
+ }
+
+ return parseProperty( propertyPath );
+ }
+
+ public static PathImpl createNewRootPath() {
+ return new PathImpl();
+ }
+
+ private PathImpl() {
+ nodeList = new ArrayList<Node>();
+ nodeList.add( ROOT_NODE );
+ }
+
+ public void addNode(Node node) {
+ nodeList.add( node );
+ }
+
+ public Iterator<Path.Node> iterator() {
+ return nodeList.iterator();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ Iterator<Path.Node> iter = iterator();
+ while ( iter.hasNext() ) {
+ Node node = iter.next();
+ if ( ROOT_NODE.equals( node ) ) {
+ continue;
+ }
+ builder.append( node.toString() );
+ if ( iter.hasNext() ) {
+ builder.append( PROPERTY_PATH_SEPERATOR );
+ }
+ }
+ return builder.toString();
+ }
+
+ private static PathImpl parseProperty(String property) {
+ PathImpl path = new PathImpl();
+ String tmp = property;
+ do {
+ Matcher matcher = pathPattern.matcher( tmp );
+ if ( matcher.matches() ) {
+ String value = matcher.group( 1 );
+ String indexed = matcher.group( 2 );
+ String index = matcher.group( 3 );
+ NodeImpl node = new NodeImpl( value );
+ if ( indexed != null ) {
+ node.setInIterable( true );
+ }
+ if ( index != null && index.length() > 0 ) {
+ try {
+ Integer i = Integer.parseInt( index );
+ node.setIndex( i );
+ }
+ catch ( NumberFormatException e ) {
+ node.setKey( index );
+ }
+ }
+ path.addNode( node );
+ tmp = matcher.group( 5 );
+ }
+ else {
+ throw new IllegalArgumentException( "Unable to parse property path " + property );
+ }
+ } while ( tmp != null );
+ return path;
+ }
+ }
+
+ public static class NodeImpl implements Path.Node {
+
+ private static final String INDEX_OPEN = "[";
+ private static final String INDEX_CLOSE = "]";
+
+ private final String name;
+ private boolean isInIterable;
+ private Integer index;
+ private Object key;
+
+
+ public NodeImpl(String name) {
+ this.name = name;
+ }
+
+ NodeImpl(Path.Node node) {
+ this.name = node.getName();
+ this.isInIterable = node.isInIterable();
+ this.index = node.getIndex();
+ this.key = node.getKey();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isInIterable() {
+ return isInIterable;
+ }
+
+ public void setInIterable(boolean inIterable) {
+ isInIterable = inIterable;
+ }
+
+ public Integer getIndex() {
+ return index;
+ }
+
+ public void setIndex(Integer index) {
+ isInIterable = true;
+ this.index = index;
+ }
+
+ public Object getKey() {
+ return key;
+ }
+
+ public void setKey(Object key) {
+ isInIterable = true;
+ this.key = key;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder( name == null ? "" : name );
+ if ( isInIterable ) {
+ builder.append( INDEX_OPEN );
+ if ( getIndex() != null ) {
+ builder.append( getIndex() );
+ }
+ else if ( getKey() != null ) {
+ builder.append( getKey() );
+ }
+ builder.append( INDEX_CLOSE );
+ }
+ return builder.toString();
+ }
+ }
}
15 years, 6 months
Hibernate SVN: r16947 - search/branches.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-06-24 13:39:28 -0400 (Wed, 24 Jun 2009)
New Revision: 16947
Added:
search/branches/v3_1_1_GA_CP/
Log:
JBPAPP-1840 : Create v3_1_1_GA_CP for EAP 5
Copied: search/branches/v3_1_1_GA_CP (from rev 16946, search/tags/v3_1_1_GA)
15 years, 6 months
Hibernate SVN: r16946 - core/branches.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-06-24 13:36:15 -0400 (Wed, 24 Jun 2009)
New Revision: 16946
Added:
core/branches/Branch_3_3_2_GA_CP/
Log:
JBPAPP-1840 : Create Branch_3_3_2_GA_CP for EAP 5
Copied: core/branches/Branch_3_3_2_GA_CP (from rev 16945, core/tags/hibernate-3.3.2.GA)
15 years, 6 months
Hibernate SVN: r16945 - in validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation: metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-24 10:45:17 -0400 (Wed, 24 Jun 2009)
New Revision: 16945
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/GlobalExecutionContext.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/LocalExecutionContext.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.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/PathImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/MetaConstraint.java
Log:
HV-177 While integrating the Path API also refactored the ExecutionContext approach and got rid of the stack type algorithm.
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-06-24 14:43:50 UTC (rev 16944)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-06-24 14:45:17 UTC (rev 16945)
@@ -95,38 +95,37 @@
return descriptor;
}
- /**
- * Validates the specified value.
- *
- * @param value The value to validate
- * @param type The type of the value determined from the type the annotation was placed on.
- * @param executionContext The current execution context.
- * @param constraintViolations List of constraint violation into which to accumulate all constraint violation as we traverse
- * this <code>ConstraintTree </code>.
- * @param <T> Type of the root bean for the current validation.
- * @param <V> Type of the value to be validated.
- */
- public <T, V> void validateConstraints(V value, Type type, ExecutionContext<T> executionContext, List<ConstraintViolation<T>> constraintViolations) {
+ public <T, U, V> void validateConstraints(Type type, GlobalExecutionContext<T> executionContext, LocalExecutionContext<U, V> localExecutionContext, List<ConstraintViolation<T>> constraintViolations) {
// first validate composing constraints
for ( ConstraintTree<?> tree : getChildren() ) {
- tree.validateConstraints( value, type, executionContext, constraintViolations );
+ tree.validateConstraints( type, executionContext, localExecutionContext, constraintViolations );
}
ConstraintValidatorContextImpl constraintValidatorContext = new ConstraintValidatorContextImpl(
- executionContext.peekPropertyPath(), descriptor
+ localExecutionContext.getPropertyPath(), descriptor
);
// we could have a composing constraint which does not need its own validator.
if ( !descriptor.getConstraintValidatorClasses().isEmpty() ) {
if ( log.isTraceEnabled() ) {
- log.trace( "Validating value {} against constraint defined by {}", value, descriptor );
+ log.trace(
+ "Validating value {} against constraint defined by {}",
+ localExecutionContext.getCurrentValidatedValue(),
+ descriptor
+ );
}
ConstraintValidator<A, V> validator = getInitalizedValidator(
- value, type, executionContext.getConstraintValidatorFactory()
+ localExecutionContext.getCurrentValidatedValue(),
+ type,
+ executionContext.getConstraintValidatorFactory()
);
validateSingleConstraint(
- value, executionContext, constraintViolations, constraintValidatorContext, validator
+ executionContext,
+ localExecutionContext,
+ constraintViolations,
+ constraintValidatorContext,
+ validator
);
}
@@ -134,16 +133,20 @@
constraintViolations.clear();
final String message = ( String ) getParent().getDescriptor().getAttributes().get( "message" );
ConstraintValidatorContextImpl.ErrorMessage error = constraintValidatorContext.new ErrorMessage(
- message, executionContext.peekPropertyPath()
+ message, localExecutionContext.getPropertyPath()
);
- constraintViolations.add( executionContext.createConstraintViolation( value, error, descriptor ) );
+ constraintViolations.add(
+ executionContext.createConstraintViolation(
+ localExecutionContext, error, descriptor
+ )
+ );
}
}
- private <T, V> void validateSingleConstraint(V value, ExecutionContext<T> executionContext, List<ConstraintViolation<T>> constraintViolations, ConstraintValidatorContextImpl constraintValidatorContext, ConstraintValidator<A, V> validator) {
+ private <T, U, V> void validateSingleConstraint(GlobalExecutionContext<T> executionContext, LocalExecutionContext<U, V> localExecutionContext, List<ConstraintViolation<T>> constraintViolations, ConstraintValidatorContextImpl constraintValidatorContext, ConstraintValidator<A, V> validator) {
boolean isValid;
try {
- isValid = validator.isValid( value, constraintValidatorContext );
+ isValid = validator.isValid( localExecutionContext.getCurrentValidatedValue(), constraintValidatorContext );
}
catch ( RuntimeException e ) {
throw new ValidationException( "Unexpected exception during isValid call", e );
@@ -151,7 +154,7 @@
if ( !isValid ) {
constraintViolations.addAll(
executionContext.createConstraintViolations(
- value, constraintValidatorContext
+ localExecutionContext, constraintValidatorContext
)
);
}
Deleted: 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-06-24 14:43:50 UTC (rev 16944)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-06-24 14:45:17 UTC (rev 16945)
@@ -1,374 +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.lang.annotation.ElementType;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.ConstraintViolation;
-import javax.validation.MessageInterpolator;
-import javax.validation.TraversableResolver;
-import javax.validation.Path;
-import javax.validation.metadata.ConstraintDescriptor;
-
-import org.hibernate.validation.metadata.MetaConstraint;
-import org.hibernate.validation.util.IdentitySet;
-
-/**
- * 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> {
-
- /**
- * The root bean of the validation.
- */
- private final T rootBean;
-
- /**
- * The root bean class of the validation.
- */
- private Class<T> rootBeanClass;
-
- /**
- * Maps a 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 and property path.
- */
- private final Map<Class<?>, IdentitySet> processedObjects;
-
- /**
- * Maps an object to a list of paths in which it has been invalidated.
- */
- private final Map<Object, Set<PathImpl>> processedPaths;
-
- /**
- * A list of all failing constraints so far.
- */
- private final List<ConstraintViolation<T>> failingConstraintViolations;
-
- /**
- * The current property path we are validating.
- */
- private PathImpl propertyPath;
-
- /**
- * The current group we are validating.
- */
- private Class<?> currentGroup;
-
- /**
- * Stack for keeping track of the currently validated bean.
- */
- private Stack<Object> beanStack = new Stack<Object>();
-
- /**
- * Flag indicating whether an object can only be validated once per group or once per group AND validation path.
- *
- * @todo Make this boolean a configurable item.
- */
- private boolean allowOneValidationPerPath = true;
-
- /**
- * The message resolver which should be used in this context.
- */
- private final MessageInterpolator messageInterpolator;
-
- /**
- * The constraint factory which should be used in this context.
- */
- private final ConstraintValidatorFactory constraintValidatorFactory;
-
- /**
- * Allows a JPA provider to decide whether a property should be validated.
- */
- private final TraversableResolver traversableResolver;
-
- public static <T> ExecutionContext<T> getContextForValidate(T object, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
- @SuppressWarnings("unchecked")
- Class<T> rootBeanClass = ( Class<T> ) object.getClass();
- return new ExecutionContext<T>(
- rootBeanClass, object, object, messageInterpolator, constraintValidatorFactory, traversableResolver
- );
- }
-
- public static <T> ExecutionContext<T> getContextForValidateValue(Class<T> rootBeanClass, Object object, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
- return new ExecutionContext<T>(
- rootBeanClass,
- null,
- object,
- messageInterpolator,
- constraintValidatorFactory,
- traversableResolver
- );
- }
-
- public static <T> ExecutionContext<T> getContextForValidateProperty(T rootBean, Object object, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
- @SuppressWarnings("unchecked")
- Class<T> rootBeanClass = ( Class<T> ) rootBean.getClass();
- return new ExecutionContext<T>(
- rootBeanClass, rootBean, object, messageInterpolator, constraintValidatorFactory, traversableResolver
- );
- }
-
- private ExecutionContext(Class<T> rootBeanClass, T rootBean, Object object, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
- this.rootBean = rootBean;
- this.rootBeanClass = rootBeanClass;
- this.messageInterpolator = messageInterpolator;
- this.constraintValidatorFactory = constraintValidatorFactory;
- this.traversableResolver = traversableResolver;
-
- beanStack.push( object );
- processedObjects = new HashMap<Class<?>, IdentitySet>();
- processedPaths = new IdentityHashMap<Object, Set<PathImpl>>();
- propertyPath = PathImpl.createNewRootPath();
- failingConstraintViolations = new ArrayList<ConstraintViolation<T>>();
- }
-
- public ConstraintValidatorFactory getConstraintValidatorFactory() {
- return constraintValidatorFactory;
- }
-
- public Object peekCurrentBean() {
- return beanStack.peek();
- }
-
- public Class<?> peekCurrentBeanType() {
- return beanStack.peek().getClass();
- }
-
- public void pushCurrentBean(Object validatedBean) {
- beanStack.push( validatedBean );
- }
-
- public void popCurrentBean() {
- beanStack.pop();
- }
-
- public T getRootBean() {
- return rootBean;
- }
-
- public Class<T> getRootBeanClass() {
- return rootBeanClass;
- }
-
- public Class<?> getCurrentGroup() {
- return currentGroup;
- }
-
- public void setCurrentGroup(Class<?> currentGroup) {
- this.currentGroup = currentGroup;
- markProcessed();
- }
-
- /**
- * Returns <code>true</code> if the specified value has already been validated, <code>false</code> otherwise.
- * Each object can only be validated once per group and validation path. The flag {@link #allowOneValidationPerPath}
- * determines whether an object can only be validated once per group or once per group and validation path.�
- *
- * @param value The value to be validated.
- *
- * @return Returns <code>true</code> if the specified value has already been validated, <code>false</code> otherwise.
- */
- public boolean isAlreadyValidated(Object value) {
- boolean alreadyValidated;
- alreadyValidated = isAlreadyValidatedForCurrentGroup( value );
-
- if ( alreadyValidated && allowOneValidationPerPath ) {
- alreadyValidated = isAlreadyValidatedForPath( value );
- }
- return alreadyValidated;
- }
-
- public void addConstraintFailures(List<ConstraintViolation<T>> failingConstraintViolations) {
- for ( ConstraintViolation<T> violation : failingConstraintViolations ) {
- addConstraintFailure( violation );
- }
- }
-
- public List<ConstraintViolation<T>> getFailingConstraints() {
- return failingConstraintViolations;
- }
-
- /**
- * 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) {
- propertyPath.addNode( new NodeImpl( property ) );
- }
-
- public void setProperty(PathImpl path) {
- propertyPath = path;
- }
-
- /**
- * Drops the last level of the current property path of this context.
- */
- public void popProperty() {
- propertyPath.removeLeafNode();
- }
-
- public void markCurrentPropertyAsIterable() {
- ( ( NodeImpl ) propertyPath.getLeafNode() ).setInIterable( true );
- }
-
- public void setPropertyIndex(String index) {
- ( ( NodeImpl ) propertyPath.getLeafNode() ).setIndex( new Integer( index ) );
- }
-
- public PathImpl peekPropertyPath() {
- return new PathImpl( propertyPath );
- }
-
- @SuppressWarnings("SimplifiableIfStatement")
- public boolean isValidationRequired(MetaConstraint metaConstraint) {
- if ( !metaConstraint.getGroupList().contains( currentGroup ) ) {
- return false;
- }
-
- return traversableResolver.isReachable(
- peekCurrentBean(),
- propertyPath.getLeafNode(),
- getRootBeanClass(),
- propertyPath.getPathWithoutLeafNode(),
- metaConstraint.getElementType()
- );
- }
-
- public boolean isCascadeRequired(Member member) {
- final ElementType type = member instanceof Field ? ElementType.FIELD : ElementType.METHOD;
- final Class<T> rootBeanType = getRootBeanClass();
- final Object traversableobject = peekCurrentBean();
- return traversableResolver.isReachable(
- traversableobject,
- propertyPath.getLeafNode(),
- rootBeanType,
- propertyPath.getPathWithoutLeafNode(),
- type
- )
- && traversableResolver.isCascadable(
- traversableobject,
- propertyPath.getLeafNode(),
- rootBeanType,
- propertyPath.getPathWithoutLeafNode(),
- type
- );
- }
-
- public List<ConstraintViolationImpl<T>> createConstraintViolations(Object value, ConstraintValidatorContextImpl constraintValidatorContext) {
- List<ConstraintViolationImpl<T>> constraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
- for ( ConstraintValidatorContextImpl.ErrorMessage error : constraintValidatorContext.getErrorMessages() ) {
- ConstraintViolationImpl<T> violation = createConstraintViolation(
- value, error, constraintValidatorContext.getConstraintDescriptor()
- );
- constraintViolations.add( violation );
- }
- return constraintViolations;
- }
-
- public ConstraintViolationImpl<T> createConstraintViolation(Object value, ConstraintValidatorContextImpl.ErrorMessage error, ConstraintDescriptor<?> descriptor) {
- String messageTemplate = error.getMessage();
- String interpolatedMessage = messageInterpolator.interpolate(
- messageTemplate,
- new MessageInterpolatorContext( descriptor, peekCurrentBean() )
- );
- return new ConstraintViolationImpl<T>(
- messageTemplate,
- interpolatedMessage,
- getRootBeanClass(),
- getRootBean(),
- peekCurrentBean(),
- value,
- error.getPath(),
- descriptor
- );
- }
-
- private boolean isAlreadyValidatedForPath(Object value) {
- Set<PathImpl> pathSet = processedPaths.get( value );
- if ( pathSet == null ) {
- return false;
- }
-
- for ( PathImpl p : pathSet ) {
- if ( p.isSubPathOf( peekPropertyPath() ) || peekPropertyPath().isSubPathOf( p ) ) {
- return true;
- }
- }
-
- return false;
- }
-
- private boolean isAlreadyValidatedForCurrentGroup(Object value) {
- final IdentitySet objectsProcessedInCurrentGroups = processedObjects.get( currentGroup );
- return objectsProcessedInCurrentGroups != null && objectsProcessedInCurrentGroups.contains( value );
- }
-
- private void markProcessed() {
- markProcessForCurrentGroup();
- if ( allowOneValidationPerPath ) {
- markProcessedForCurrentPath();
- }
- }
-
- private void markProcessedForCurrentPath() {
- if ( processedPaths.containsKey( peekCurrentBean() ) ) {
- processedPaths.get( peekCurrentBean() ).add( peekPropertyPath() );
- }
- else {
- Set<PathImpl> set = new HashSet<PathImpl>();
- set.add( peekPropertyPath() );
- processedPaths.put( peekCurrentBean(), set );
- }
- }
-
-
- private void markProcessForCurrentGroup() {
- if ( processedObjects.containsKey( currentGroup ) ) {
- processedObjects.get( currentGroup ).add( peekCurrentBean() );
- }
- else {
- IdentitySet set = new IdentitySet();
- set.add( peekCurrentBean() );
- processedObjects.put( currentGroup, set );
- }
- }
-
- private void addConstraintFailure(ConstraintViolation<T> failingConstraintViolation) {
- int i = failingConstraintViolations.indexOf( failingConstraintViolation );
- if ( i == -1 ) {
- failingConstraintViolations.add( failingConstraintViolation );
- }
- }
-}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/GlobalExecutionContext.java (from rev 16905, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/GlobalExecutionContext.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/GlobalExecutionContext.java 2009-06-24 14:45:17 UTC (rev 16945)
@@ -0,0 +1,257 @@
+// $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.HashSet;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.ConstraintViolation;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.metadata.ConstraintDescriptor;
+
+import org.hibernate.validation.util.IdentitySet;
+
+/**
+ * Context object keeping track of all important data for a top level {@link javax.validation.Validator#validate(Object, Class[])} },
+ * {@link javax.validation.Validator#validateValue(Class, String, Object, Class[])} } or {@link javax.validation.Validator#validateProperty(Object, String, Class[])} call.
+ *
+ * we use this object to collect all failing constraints, but also to cache the caching traversable resolver for a full stack call.
+ *
+ * @author Hardy Ferentschik
+ * @author Emmanuel Bernard
+ */
+public class GlobalExecutionContext<T> {
+
+ /**
+ * The root bean of the validation.
+ */
+ private final T rootBean;
+
+ /**
+ * The root bean class of the validation.
+ */
+ private final Class<T> rootBeanClass;
+
+ /**
+ * Maps a 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 and property path.
+ */
+ private final Map<Class<?>, IdentitySet> processedObjects;
+
+ /**
+ * Maps an object to a list of paths in which it has been invalidated.
+ */
+ private final Map<Object, Set<PathImpl>> processedPaths;
+
+ /**
+ * A list of all failing constraints so far.
+ */
+ private final List<ConstraintViolation<T>> failingConstraintViolations;
+
+ /**
+ * Flag indicating whether an object can only be validated once per group or once per group AND validation path.
+ *
+ * @todo Make this boolean a configurable item.
+ */
+ private boolean allowOneValidationPerPath = true;
+
+ /**
+ * The message resolver which should be used in this context.
+ */
+ private final MessageInterpolator messageInterpolator;
+
+ /**
+ * The constraint factory which should be used in this context.
+ */
+ private final ConstraintValidatorFactory constraintValidatorFactory;
+
+ /**
+ * Allows a JPA provider to decide whether a property should be validated.
+ */
+ private final TraversableResolver traversableResolver;
+
+ public static <T> GlobalExecutionContext<T> getContextForValidate(T object, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
+ @SuppressWarnings("unchecked")
+ Class<T> rootBeanClass = ( Class<T> ) object.getClass();
+ return new GlobalExecutionContext<T>(
+ rootBeanClass, object, messageInterpolator, constraintValidatorFactory, traversableResolver
+ );
+ }
+
+ public static <T> GlobalExecutionContext<T> getContextForValidateProperty(T rootBean, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
+ @SuppressWarnings("unchecked")
+ Class<T> rootBeanClass = ( Class<T> ) rootBean.getClass();
+ return new GlobalExecutionContext<T>(
+ rootBeanClass, rootBean, messageInterpolator, constraintValidatorFactory, traversableResolver
+ );
+ }
+
+ public static <T> GlobalExecutionContext<T> getContextForValidateValue(Class<T> rootBeanClass, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
+ return new GlobalExecutionContext<T>(
+ rootBeanClass,
+ null,
+ messageInterpolator,
+ constraintValidatorFactory,
+ traversableResolver
+ );
+ }
+
+ private GlobalExecutionContext(Class<T> rootBeanClass, T rootBean, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver) {
+ this.rootBean = rootBean;
+ this.rootBeanClass = rootBeanClass;
+ this.messageInterpolator = messageInterpolator;
+ this.constraintValidatorFactory = constraintValidatorFactory;
+ this.traversableResolver = traversableResolver;
+
+ processedObjects = new HashMap<Class<?>, IdentitySet>();
+ processedPaths = new IdentityHashMap<Object, Set<PathImpl>>();
+ failingConstraintViolations = new ArrayList<ConstraintViolation<T>>();
+ }
+
+ public T getRootBean() {
+ return rootBean;
+ }
+
+ public Class<T> getRootBeanClass() {
+ return rootBeanClass;
+ }
+
+ public TraversableResolver getTraversableResolver() {
+ return traversableResolver;
+ }
+
+ public MessageInterpolator getMessageInterpolator() {
+ return messageInterpolator;
+ }
+
+ public <U, V> ConstraintViolationImpl<T> createConstraintViolation(LocalExecutionContext<U, V> localContext, ConstraintValidatorContextImpl.ErrorMessage error, ConstraintDescriptor<?> descriptor) {
+ String messageTemplate = error.getMessage();
+ String interpolatedMessage = messageInterpolator.interpolate(
+ messageTemplate,
+ new MessageInterpolatorContext( descriptor, localContext.getCurrentBean() )
+ );
+ return new ConstraintViolationImpl<T>(
+ messageTemplate,
+ interpolatedMessage,
+ getRootBeanClass(),
+ getRootBean(),
+ localContext.getCurrentBean(),
+ localContext.getCurrentValidatedValue(),
+ error.getPath(),
+ descriptor
+ );
+ }
+
+ public <U, V> List<ConstraintViolationImpl<T>> createConstraintViolations(LocalExecutionContext<U, V> localContext, ConstraintValidatorContextImpl constraintValidatorContext) {
+ List<ConstraintViolationImpl<T>> constraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
+ for ( ConstraintValidatorContextImpl.ErrorMessage error : constraintValidatorContext.getErrorMessages() ) {
+ ConstraintViolationImpl<T> violation = createConstraintViolation(
+ localContext, error, constraintValidatorContext.getConstraintDescriptor()
+ );
+ constraintViolations.add( violation );
+ }
+ return constraintViolations;
+ }
+
+ public ConstraintValidatorFactory getConstraintValidatorFactory() {
+ return constraintValidatorFactory;
+ }
+
+ public boolean isAlreadyValidated(Object value, Class<?> group, PathImpl path) {
+ boolean alreadyValidated;
+ alreadyValidated = isAlreadyValidatedForCurrentGroup( value, group );
+
+ if ( alreadyValidated && allowOneValidationPerPath ) {
+ alreadyValidated = isAlreadyValidatedForPath( value, path );
+ }
+ return alreadyValidated;
+ }
+
+ public void markProcessed(Object value, Class<?> group, PathImpl path) {
+ markProcessForCurrentGroup( value, group );
+ if ( allowOneValidationPerPath ) {
+ markProcessedForCurrentPath( value, path );
+ }
+ }
+
+ private void addConstraintFailure(ConstraintViolation<T> failingConstraintViolation) {
+ int i = failingConstraintViolations.indexOf( failingConstraintViolation );
+ if ( i == -1 ) {
+ failingConstraintViolations.add( failingConstraintViolation );
+ }
+ }
+
+ public void addConstraintFailures(List<ConstraintViolation<T>> failingConstraintViolations) {
+ for ( ConstraintViolation<T> violation : failingConstraintViolations ) {
+ addConstraintFailure( violation );
+ }
+ }
+
+ public List<ConstraintViolation<T>> getFailingConstraints() {
+ return failingConstraintViolations;
+ }
+
+ private boolean isAlreadyValidatedForPath(Object value, PathImpl path) {
+ Set<PathImpl> pathSet = processedPaths.get( value );
+ if ( pathSet == null ) {
+ return false;
+ }
+
+ for ( PathImpl p : pathSet ) {
+ if ( p.isSubPathOf( path ) || path.isSubPathOf( p ) ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private boolean isAlreadyValidatedForCurrentGroup(Object value, Class<?> group) {
+ final IdentitySet objectsProcessedInCurrentGroups = processedObjects.get( group );
+ return objectsProcessedInCurrentGroups != null && objectsProcessedInCurrentGroups.contains( value );
+ }
+
+ private void markProcessedForCurrentPath(Object value, PathImpl path) {
+ if ( processedPaths.containsKey( value ) ) {
+ processedPaths.get( value ).add( path.getPathWithoutLeafNode() );
+ }
+ else {
+ Set<PathImpl> set = new HashSet<PathImpl>();
+ set.add( path.getPathWithoutLeafNode() );
+ processedPaths.put( value, set );
+ }
+ }
+
+
+ private void markProcessForCurrentGroup(Object value, Class<?> group) {
+ if ( processedObjects.containsKey( group ) ) {
+ processedObjects.get( group ).add( value );
+ }
+ else {
+ IdentitySet set = new IdentitySet();
+ set.add( value );
+ processedObjects.put( group, set );
+ }
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/LocalExecutionContext.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/LocalExecutionContext.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/LocalExecutionContext.java 2009-06-24 14:45:17 UTC (rev 16945)
@@ -0,0 +1,113 @@
+// $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;
+
+/**
+ * An instance of this class is used to collect all the relevant information for validating a single entity/bean.
+ *
+ * @author Hardy Ferentschik
+ */
+public class LocalExecutionContext<T,V> {
+
+ /**
+ * The current bean which gets validated. This is the bean hosting the constraints which get validated.
+ */
+ private final T currentBean;
+
+ /**
+ * The class of the current bean.
+ */
+ private final Class<T> currentBeanType;
+
+ /**
+ * The current property path we are validating.
+ */
+ private PathImpl propertyPath;
+
+ /**
+ * The current group we are validating.
+ */
+ private Class<?> currentGroup;
+
+ /**
+ * The value which gets currently evaluated.
+ */
+ private V currentValue;
+
+ public static <T,V> LocalExecutionContext<T,V> getLocalExecutionContext(T value) {
+ @SuppressWarnings("unchecked")
+ Class<T> rootBeanClass = ( Class<T> ) value.getClass();
+ return new LocalExecutionContext<T,V>( value, rootBeanClass );
+ }
+
+ public static <T,V> LocalExecutionContext<T,V> getLocalExecutionContext(Class<T> type) {
+ return new LocalExecutionContext<T,V>( null, type );
+ }
+
+ public LocalExecutionContext(T currentBean, Class<T> currentBeanType) {
+ this.currentBean = currentBean;
+ this.currentBeanType = currentBeanType;
+ }
+
+ public PathImpl getPropertyPath() {
+ return propertyPath;
+ }
+
+ public Class<?> getCurrentGroup() {
+ return currentGroup;
+ }
+
+ public T getCurrentBean() {
+ return currentBean;
+ }
+
+ public Class<T> getCurrentBeanType() {
+ return currentBeanType;
+ }
+
+ public V getCurrentValidatedValue() {
+ return currentValue;
+ }
+
+ public void setPropertyPath(PathImpl propertyPath) {
+ this.propertyPath = propertyPath;
+ }
+
+ public void setCurrentGroup(Class<?> currentGroup) {
+ this.currentGroup = currentGroup;
+ }
+
+ public void setCurrentValidatedValue(V currentValue) {
+ this.currentValue = currentValue;
+ }
+
+ public void markCurrentPropertyAsIterable() {
+ propertyPath.getLeafNode().setInIterable( true );
+ }
+
+ @Override
+ public String toString() {
+ return "LocalExecutionContext{" +
+ "currentBean=" + currentBean +
+ ", currentBeanType=" + currentBeanType +
+ ", propertyPath=" + propertyPath +
+ ", currentGroup=" + currentGroup +
+ ", currentValue=" + currentValue +
+ '}';
+ }
+}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PathImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PathImpl.java 2009-06-24 14:43:50 UTC (rev 16944)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PathImpl.java 2009-06-24 14:45:17 UTC (rev 16945)
@@ -67,7 +67,11 @@
return new PathImpl();
}
- public PathImpl(PathImpl path) {
+ public static PathImpl createShallowCopy(PathImpl path) {
+ return new PathImpl(path);
+ }
+
+ private PathImpl(PathImpl path) {
this.nodeList = new ArrayList<Node>();
Iterator<Node> iter = path.iterator();
while ( iter.hasNext() ) {
@@ -87,7 +91,7 @@
}
}
- public Path getPathWithoutLeafNode() {
+ public PathImpl getPathWithoutLeafNode() {
List<Node> nodes = new ArrayList<Node>( nodeList );
if ( nodes.size() > 1 ) {
nodes.remove( nodes.size() - 1 );
@@ -154,6 +158,7 @@
}
@Override
+ @SuppressWarnings( "SimplifiableIfStatement")
public boolean equals(Object o) {
if ( this == o ) {
return true;
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-06-24 14:43:50 UTC (rev 16944)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-24 14:45:17 UTC (rev 16945)
@@ -18,6 +18,8 @@
package org.hibernate.validation.engine;
import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -58,23 +60,11 @@
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
- * @todo Make all properties transient for serializability.
*/
public class ValidatorImpl implements Validator {
private static final Logger log = LoggerFactory.make();
/**
- * Set of classes which can be used as index in a map.
- */
- private static final Set<Class<?>> VALID_MAP_INDEX_CLASSES = new HashSet<Class<?>>();
-
- static {
- VALID_MAP_INDEX_CLASSES.add( Integer.class );
- VALID_MAP_INDEX_CLASSES.add( Long.class );
- VALID_MAP_INDEX_CLASSES.add( String.class );
- }
-
- /**
* The default group array used in case any of the validate methods is called without a group.
*/
private static final Class<?>[] DEFAULT_GROUP_ARRAY = new Class<?>[] { Default.class };
@@ -82,7 +72,7 @@
/**
* Used to resolve the group execution order for a validate call.
*/
- private GroupChainGenerator groupChainGenerator;
+ private final transient GroupChainGenerator groupChainGenerator;
private final ConstraintValidatorFactory constraintValidatorFactory;
private final MessageInterpolator messageInterpolator;
@@ -102,26 +92,22 @@
groupChainGenerator = new GroupChainGenerator();
}
- /**
- * {@inheritDoc}
- */
public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups) {
if ( object == null ) {
throw new IllegalArgumentException( "Validation of a null object" );
}
GroupChain groupChain = determineGroupExecutionOrder( groups );
- ExecutionContext<T> context = ExecutionContext.getContextForValidate(
+ GlobalExecutionContext<T> context = GlobalExecutionContext.getContextForValidate(
object, messageInterpolator, constraintValidatorFactory, getCachingTraversableResolver()
);
- List<ConstraintViolation<T>> list = validateInContext( context, groupChain );
+ List<ConstraintViolation<T>> list = validateInContext(
+ object, context, groupChain, PathImpl.createNewRootPath()
+ );
return new HashSet<ConstraintViolation<T>>( list );
}
- /**
- * {@inheritDoc}
- */
public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups) {
if ( object == null ) {
throw new IllegalArgumentException( "Validated object cannot be null." );
@@ -136,9 +122,6 @@
return new HashSet<ConstraintViolation<T>>( failingConstraintViolations );
}
- /**
- * {@inheritDoc}
- */
public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups) {
if ( beanType == null ) {
throw new IllegalArgumentException( "The bean type cannot be null." );
@@ -185,43 +168,51 @@
}
/**
- * Validates the object contained in <code>context</code>.
+ * Validates the given object using the available context information.
*
- * @param context A context object containing the object to validate together with other state information needed
- * for validation.
- * @param groupChain A <code>GroupChain</code> instance containing the resolved group sequence to execute
+ * @param value The value to validate.
+ * @param context Global context. Used amongst others to collect all failing constraints.
+ * @param groupChain Contains the information which and in which oder groups have to be executed
+ * @param path The current path of the valiation.
+ * @param <T> The root bean type.
+ * @param <V> The type of the current object on the validation stack.
*
- * @return List of invalid constraints.
+ * @return List of constraint violations or the empty set if there were no violations.
*/
- private <T> List<ConstraintViolation<T>> validateInContext(ExecutionContext<T> context, GroupChain groupChain) {
- if ( context.peekCurrentBean() == null ) {
+ private <T, U, V> List<ConstraintViolation<T>> validateInContext(U value, GlobalExecutionContext<T> context, GroupChain groupChain, PathImpl path) {
+ if ( value == null ) {
return Collections.emptyList();
}
- // process all groups breadth-first
+ path = PathImpl.createShallowCopy( path );
+
+ LocalExecutionContext<U, V> localExecutionContext = LocalExecutionContext.getLocalExecutionContext( value );
+
+ // process first single groups. For these we can skip some object traversal, by first running all validations on the current bean
+ // before traversing the object.
Iterator<Group> groupIterator = groupChain.getGroupIterator();
while ( groupIterator.hasNext() ) {
Group group = groupIterator.next();
- context.setCurrentGroup( group.getGroup() );
- validateConstraints( context );
+ localExecutionContext.setCurrentGroup( group.getGroup() );
+ validateConstraints( context, localExecutionContext, path );
}
groupIterator = groupChain.getGroupIterator();
while ( groupIterator.hasNext() ) {
Group group = groupIterator.next();
- context.setCurrentGroup( group.getGroup() );
- validateCascadedConstraints( context );
+ localExecutionContext.setCurrentGroup( group.getGroup() );
+ validateCascadedConstraints( context, localExecutionContext, path );
}
- // process group sequences depth-first to guarantee that groups following a violation within a group won't get executed.
+ // now we process sequences. For sequences I have to traverse the object graph since I have to stop processing when an error occurs.
Iterator<List<Group>> sequenceIterator = groupChain.getSequenceIterator();
while ( sequenceIterator.hasNext() ) {
List<Group> sequence = sequenceIterator.next();
for ( Group group : sequence ) {
int numberOfViolations = context.getFailingConstraints().size();
- context.setCurrentGroup( group.getGroup() );
+ localExecutionContext.setCurrentGroup( group.getGroup() );
- validateConstraints( context );
- validateCascadedConstraints( context );
+ validateConstraints( context, localExecutionContext, path );
+ validateCascadedConstraints( context, localExecutionContext, path );
if ( context.getFailingConstraints().size() > numberOfViolations ) {
break;
@@ -232,15 +223,18 @@
}
/**
- * Validates the non-cascaded constraints.
+ * Validates non cascaded constraints
*
- * @param executionContext The current validation context.
+ * @param executionContext The global execution context
+ * @param localExecutionContext Collected information for single validation
+ * @param path The current path of the validation
+ * @param <T> The type of the root bean
*/
- private <T> void validateConstraints(ExecutionContext<T> executionContext) {
+ private <T, U, V> void validateConstraints(GlobalExecutionContext<T> executionContext, LocalExecutionContext<U, V> localExecutionContext, PathImpl path) {
//casting rely on the fact that root object is at the top of the stack
@SuppressWarnings("unchecked")
- BeanMetaData<T> beanMetaData = getBeanMetaData( ( Class<T> ) executionContext.peekCurrentBeanType() );
- if ( executionContext.getCurrentGroup().getName().equals( Default.class.getName() ) ) {
+ BeanMetaData<T> beanMetaData = getBeanMetaData( ( Class<T> ) localExecutionContext.getCurrentBeanType() );
+ if ( localExecutionContext.getCurrentGroup().getName().equals( Default.class.getName() ) ) {
List<Class<?>> defaultGroupSequence = beanMetaData.getDefaultGroupSequence();
if ( log.isTraceEnabled() && defaultGroupSequence.size() > 0 && defaultGroupSequence.get( 0 ) != Default.class ) {
log.trace(
@@ -250,56 +244,71 @@
);
}
for ( Class<?> defaultSequenceMember : defaultGroupSequence ) {
- executionContext.setCurrentGroup( defaultSequenceMember );
- boolean validationSuccessful = validateConstraintsForCurrentGroup( executionContext, beanMetaData );
+ localExecutionContext.setCurrentGroup( defaultSequenceMember );
+ boolean validationSuccessful = validateConstraintsForCurrentGroup(
+ executionContext, localExecutionContext, beanMetaData, path
+ );
if ( !validationSuccessful ) {
break;
}
}
}
else {
- validateConstraintsForCurrentGroup( executionContext, beanMetaData );
+ validateConstraintsForCurrentGroup( executionContext, localExecutionContext, beanMetaData, path );
}
}
- /**
- * Validates all constraints for the given bean using the current group set in the execution context.
- *
- * @param executionContext The execution context.
- * @param beanMetaData The bean metadata object for the bean to validate.
- *
- * @return <code>true</code> if the validation was successful (meaning no constraint violations), <code>false</code>
- * otherwise.
- */
- private <T> boolean validateConstraintsForCurrentGroup(ExecutionContext<T> executionContext, BeanMetaData<T> beanMetaData) {
+ private <T, U, V> boolean validateConstraintsForCurrentGroup(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, BeanMetaData<T> beanMetaData, PathImpl path) {
boolean validationSuccessful = true;
for ( MetaConstraint<T, ?> metaConstraint : beanMetaData.geMetaConstraintList() ) {
- executionContext.pushProperty( metaConstraint.getPropertyName() );
- if ( executionContext.isValidationRequired( metaConstraint ) ) {
- boolean tmp = metaConstraint.validateConstraint( executionContext );
+ PathImpl newPath = PathImpl.createShallowCopy( path );
+ newPath.addNode( new NodeImpl( metaConstraint.getPropertyName() ) );
+ localExecutionContext.setPropertyPath( newPath );
+ if ( isValidationRequired( globalExecutionContext, localExecutionContext, metaConstraint ) ) {
+ Object valueToValidate = metaConstraint.getValue( localExecutionContext.getCurrentBean() );
+ localExecutionContext.setCurrentValidatedValue( ( V ) valueToValidate );
+ boolean tmp = metaConstraint.validateConstraint( globalExecutionContext, localExecutionContext );
validationSuccessful = validationSuccessful && tmp;
}
- executionContext.popProperty();
}
+ globalExecutionContext.markProcessed(
+ localExecutionContext.getCurrentBean(),
+ localExecutionContext.getCurrentGroup(),
+ localExecutionContext.getPropertyPath()
+ );
return validationSuccessful;
}
- //this method must always be called after validateConstraints for the same context
- private <T> void validateCascadedConstraints(ExecutionContext<T> context) {
- List<Member> cascadedMembers = getBeanMetaData( context.peekCurrentBeanType() )
+ /**
+ * Validates all cascaded constraints for the given bean using the current group set in the execution context.
+ * This method must always be called after validateConstraints for the same context.
+ *
+ * @param globalExecutionContext The execution context
+ * @param localExecutionContext Collected information for single validation
+ * @param path The current path of the valiation.
+ */
+ private <T, U, V> void validateCascadedConstraints(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, PathImpl path) {
+ List<Member> cascadedMembers = getBeanMetaData( localExecutionContext.getCurrentBeanType() )
.getCascadedMembers();
for ( Member member : cascadedMembers ) {
Type type = ReflectionHelper.typeOf( member );
- context.pushProperty( ReflectionHelper.getPropertyName( member ) );
- if ( context.isCascadeRequired( member ) ) {
- Object value = ReflectionHelper.getValue( member, context.peekCurrentBean() );
+ PathImpl newPath = PathImpl.createShallowCopy( path );
+ newPath.addNode( new NodeImpl( ReflectionHelper.getPropertyName( member ) ) );
+ localExecutionContext.setPropertyPath( newPath );
+ if ( isCascadeRequired( globalExecutionContext, localExecutionContext, member ) ) {
+ Object value = ReflectionHelper.getValue( member, localExecutionContext.getCurrentBean() );
if ( value != null ) {
- Iterator<?> iter = createIteratorForCascadedValue( context, type, value );
+ Iterator<?> iter = createIteratorForCascadedValue( localExecutionContext, type, value );
boolean isIndexable = isIndexable( type );
- validateCascadedConstraint( context, iter, isIndexable );
+ validateCascadedConstraint(
+ globalExecutionContext,
+ iter,
+ isIndexable,
+ localExecutionContext.getCurrentGroup(),
+ localExecutionContext.getPropertyPath()
+ );
}
}
- context.popProperty();
}
}
@@ -313,7 +322,7 @@
*
* @return An iterator over the value of a cascaded property.
*/
- private <T> Iterator<?> createIteratorForCascadedValue(ExecutionContext<T> context, Type type, Object value) {
+ private <U, V> Iterator<?> createIteratorForCascadedValue(LocalExecutionContext<U, V> context, Type type, Object value) {
Iterator<?> iter;
if ( ReflectionHelper.isIterable( type ) ) {
iter = ( ( Iterable<?> ) value ).iterator();
@@ -360,30 +369,36 @@
}
@SuppressWarnings("RedundantArrayCreation")
- private <T> void validateCascadedConstraint(ExecutionContext<T> context, Iterator<?> iter, boolean isIndexable) {
- Object actualValue;
- String propertyIndex;
+ private <T> void validateCascadedConstraint(GlobalExecutionContext<T> context, Iterator<?> iter, boolean isIndexable, Class<?> currentGroup, PathImpl currentPath) {
+ Object value;
+ Integer index;
+ Object mapKey = null;
int i = 0;
while ( iter.hasNext() ) {
- actualValue = iter.next();
- propertyIndex = String.valueOf( i );
- if ( actualValue instanceof Map.Entry ) {
- Object key = ( ( Map.Entry ) actualValue ).getKey();
- if ( VALID_MAP_INDEX_CLASSES.contains( key.getClass() ) ) {
- propertyIndex = key.toString();
- }
- actualValue = ( ( Map.Entry ) actualValue ).getValue();
+ value = iter.next();
+ index = i;
+ if ( value instanceof Map.Entry ) {
+ mapKey = ( ( Map.Entry ) value ).getKey();
+ value = ( ( Map.Entry ) value ).getValue();
}
- if ( !context.isAlreadyValidated( actualValue ) ) {
- if ( isIndexable ) {
- context.setPropertyIndex( propertyIndex );
- }
- context.pushCurrentBean( actualValue );
- GroupChain groupChain = groupChainGenerator.getGroupChainFor( Arrays.asList( new Class<?>[] { context.getCurrentGroup() } ) );
- validateInContext( context, groupChain );
- context.popCurrentBean();
+ if ( isIndexable ) {
+ // only one of the two values index/mapKey will be set. The other will stay null.
+ currentPath.getLeafNode().setIndex( index );
+ currentPath.getLeafNode().setKey( mapKey );
}
+
+ if ( !context.isAlreadyValidated( value, currentGroup, currentPath ) ) {
+
+ GroupChain groupChain = groupChainGenerator.getGroupChainFor(
+ Arrays.asList(
+ new Class<?>[] {
+ currentGroup
+ }
+ )
+ );
+ validateInContext( value, context, groupChain, currentPath );
+ }
i++;
}
}
@@ -445,12 +460,12 @@
}
}
- private <T> void validatePropertyForGroup(
+ private <T, U, V> void validatePropertyForGroup(
T object,
PathImpl path,
List<ConstraintViolation<T>> failingConstraintViolations,
Set<MetaConstraint<T, ?>> metaConstraints,
- Object hostingBeanInstance,
+ U hostingBeanInstance,
Group group,
TraversableResolver cachedTraversableResolver) {
int numberOfConstraintViolationsBefore = failingConstraintViolations.size();
@@ -467,17 +482,21 @@
for ( Class<?> groupClass : groupList ) {
for ( MetaConstraint<T, ?> metaConstraint : metaConstraints ) {
- ExecutionContext<T> context = ExecutionContext.getContextForValidateProperty(
+ GlobalExecutionContext<T> context = GlobalExecutionContext.getContextForValidateProperty(
object,
- hostingBeanInstance,
messageInterpolator,
constraintValidatorFactory,
cachedTraversableResolver
);
- context.setProperty( path );
- context.setCurrentGroup( groupClass );
- if ( context.isValidationRequired( metaConstraint ) ) {
- metaConstraint.validateConstraint( context );
+ LocalExecutionContext<U, V> localContext = LocalExecutionContext.getLocalExecutionContext(
+ hostingBeanInstance
+ );
+ localContext.setPropertyPath( path );
+ localContext.setCurrentGroup( groupClass );
+ if ( isValidationRequired( context, localContext, metaConstraint ) ) {
+ Object valueToValidate = metaConstraint.getValue( localContext.getCurrentBean() );
+ localContext.setCurrentValidatedValue( ( V ) valueToValidate );
+ metaConstraint.validateConstraint( context, localContext );
failingConstraintViolations.addAll( context.getFailingConstraints() );
}
}
@@ -537,16 +556,16 @@
}
}
- private <T> void validateValueForGroup(
- Class<T> beanType,
- Object value,
+ private <U, V> void validateValueForGroup(
+ Class<U> beanType,
+ V value,
PathImpl path,
- List<ConstraintViolation<T>> failingConstraintViolations,
- Set<MetaConstraint<T, ?>> metaConstraints,
+ List<ConstraintViolation<U>> failingConstraintViolations,
+ Set<MetaConstraint<U, ?>> metaConstraints,
Group group,
TraversableResolver cachedTraversableResolver) {
int numberOfConstraintViolations = failingConstraintViolations.size();
- BeanMetaData<T> beanMetaData = getBeanMetaData( metaConstraints.iterator().next().getBeanClass() );
+ BeanMetaData<U> beanMetaData = getBeanMetaData( metaConstraints.iterator().next().getBeanClass() );
List<Class<?>> groupList;
if ( group.isDefaultGroup() ) {
@@ -557,16 +576,17 @@
groupList.add( group.getGroup() );
}
-
for ( Class<?> groupClass : groupList ) {
- for ( MetaConstraint<T, ?> metaConstraint : metaConstraints ) {
- ExecutionContext<T> context = ExecutionContext.getContextForValidateValue(
- beanType, value, messageInterpolator, constraintValidatorFactory, cachedTraversableResolver
+ for ( MetaConstraint<U, ?> metaConstraint : metaConstraints ) {
+ GlobalExecutionContext<U> context = GlobalExecutionContext.getContextForValidateValue(
+ beanType, messageInterpolator, constraintValidatorFactory, cachedTraversableResolver
);
- context.setProperty( path );
- context.setCurrentGroup( groupClass );
- if ( context.isValidationRequired( metaConstraint ) ) {
- metaConstraint.validateConstraint( value, context );
+ LocalExecutionContext<U, V> localContext = LocalExecutionContext.getLocalExecutionContext( beanType );
+ localContext.setPropertyPath( path );
+ localContext.setCurrentGroup( groupClass );
+ localContext.setCurrentValidatedValue( value );
+ if ( isValidationRequired( context, localContext, metaConstraint ) ) {
+ metaConstraint.validateConstraint( context, localContext );
failingConstraintViolations.addAll( context.getFailingConstraints() );
}
}
@@ -589,9 +609,7 @@
*
* @return Returns the bean hosting the constraints which match the specified property path.
*/
- @SuppressWarnings("unchecked")
private <T> Object collectMetaConstraintsForPath(Class<T> clazz, Object value, Iterator<Path.Node> propertyIter, Set<MetaConstraint<T, ?>> metaConstraints) {
-
Path.Node elem = propertyIter.next();
if ( elem.getName() == null ) { // skip root node
elem = propertyIter.next();
@@ -601,11 +619,11 @@
if ( !propertyIter.hasNext() ) {
//use metadata first as ReflectionHelper#containsMember is slow
- //TODO store some metadata here?
- if ( metaData.getPropertyDescriptor( elem.getName() ) == null
- && !ReflectionHelper.containsMember( clazz, elem.getName() ) ) {
- //TODO better error report
- throw new IllegalArgumentException( "Invalid property path." );
+ if ( metaData.getPropertyDescriptor( elem.getName() ) == null ) {
+ throw new IllegalArgumentException(
+ "Invalid property path. There is no property " + elem.getName() + " in entity " + metaData.getBeanClass()
+ .getName()
+ );
}
List<MetaConstraint<T, ? extends Annotation>> metaConstraintList = metaData.geMetaConstraintList();
@@ -630,8 +648,12 @@
}
type = ReflectionHelper.getIndexedType( type );
}
+
+ @SuppressWarnings("unchecked")
+ Class<T> valueClass = ( Class<T> ) ( value == null ? type : value.getClass() );
+
return collectMetaConstraintsForPath(
- ( Class<T> ) ( value == null ? type : value.getClass() ),
+ valueClass,
value,
propertyIter,
metaConstraints
@@ -642,9 +664,6 @@
return value;
}
- /**
- * {@inheritDoc}
- */
private <T> BeanMetaData<T> getBeanMetaData(Class<T> beanClass) {
BeanMetaDataImpl<T> metadata = beanMetaDataCache.getBeanMetaData( beanClass );
if ( metadata == null ) {
@@ -657,8 +676,43 @@
/**
* Must be called and stored for the duration of the stack call
* A new instance is returned each time
+ *
+ * @return The resolver for the duration of a full validation.
*/
private TraversableResolver getCachingTraversableResolver() {
return new SingleThreadCachedTraversableResolver( traversableResolver );
}
+
+ @SuppressWarnings("SimplifiableIfStatement")
+ private boolean isValidationRequired(GlobalExecutionContext globalContext, LocalExecutionContext localContext, MetaConstraint metaConstraint) {
+ if ( !metaConstraint.getGroupList().contains( localContext.getCurrentGroup() ) ) {
+ return false;
+ }
+
+ return globalContext.getTraversableResolver().isReachable(
+ localContext.getCurrentBean(),
+ localContext.getPropertyPath().getLeafNode(),
+ globalContext.getRootBeanClass(),
+ localContext.getPropertyPath().getPathWithoutLeafNode(),
+ metaConstraint.getElementType()
+ );
+ }
+
+ private boolean isCascadeRequired(GlobalExecutionContext globalContext, LocalExecutionContext localContext, Member member) {
+ final ElementType type = member instanceof Field ? ElementType.FIELD : ElementType.METHOD;
+ return globalContext.getTraversableResolver().isReachable(
+ localContext.getCurrentBean(),
+ localContext.getPropertyPath().getLeafNode(),
+ globalContext.getRootBeanClass(),
+ localContext.getPropertyPath().getPathWithoutLeafNode(),
+ type
+ )
+ && globalContext.getTraversableResolver().isCascadable(
+ localContext.getCurrentBean(),
+ localContext.getPropertyPath().getLeafNode(),
+ globalContext.getRootBeanClass(),
+ localContext.getPropertyPath().getPathWithoutLeafNode(),
+ type
+ );
+ }
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/MetaConstraint.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/MetaConstraint.java 2009-06-24 14:43:50 UTC (rev 16944)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/MetaConstraint.java 2009-06-24 14:45:17 UTC (rev 16945)
@@ -26,12 +26,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
+import javax.validation.metadata.ConstraintDescriptor;
-import org.hibernate.validation.util.ReflectionHelper;
import org.hibernate.validation.engine.ConstraintTree;
-import org.hibernate.validation.engine.ExecutionContext;
+import org.hibernate.validation.engine.GlobalExecutionContext;
+import org.hibernate.validation.engine.LocalExecutionContext;
+import org.hibernate.validation.util.ReflectionHelper;
/**
* Instances of this class abstract the constraint type (class, method or field constraint) and gives access to
@@ -120,11 +121,11 @@
return constraintTree;
}
- public <T> boolean validateConstraint(ExecutionContext<T> executionContext) {
- final Object leafBeanInstance = executionContext.peekCurrentBean();
- Object value = getValue( leafBeanInstance );
+ public <T, U, V> boolean validateConstraint(GlobalExecutionContext<T> executionContext, LocalExecutionContext<U, V> localExecutionContext) {
List<ConstraintViolation<T>> constraintViolations = new ArrayList<ConstraintViolation<T>>();
- constraintTree.validateConstraints( value, typeOfAnnoatedElement(), executionContext, constraintViolations );
+ constraintTree.validateConstraints(
+ typeOfAnnoatedElement(), executionContext, localExecutionContext, constraintViolations
+ );
if ( constraintViolations.size() > 0 ) {
executionContext.addConstraintFailures( constraintViolations );
return false;
@@ -132,14 +133,21 @@
return true;
}
- public <T> boolean validateConstraint(Object value, ExecutionContext<T> executionContext) {
- List<ConstraintViolation<T>> constraintViolations = new ArrayList<ConstraintViolation<T>>();
- constraintTree.validateConstraints( value, typeOfAnnoatedElement(), executionContext, constraintViolations );
- if ( constraintViolations.size() > 0 ) {
- executionContext.addConstraintFailures( constraintViolations );
- return false;
+ /**
+ * @param o the object from which to retrieve the value.
+ *
+ * @return Returns the value for this constraint from the specified object. Depending on the type either the value itself
+ * is returned of method or field access is used to access the value.
+ */
+ public Object getValue(Object o) {
+ switch ( elementType ) {
+ case TYPE: {
+ return o;
+ }
+ default: {
+ return ReflectionHelper.getValue( member, o );
+ }
}
- return true;
}
private Type typeOfAnnoatedElement() {
@@ -151,28 +159,11 @@
}
default: {
t = ReflectionHelper.typeOf( member );
- if ( t instanceof Class && ((Class) t).isPrimitive()) {
+ if ( t instanceof Class && ( ( Class ) t ).isPrimitive() ) {
t = ReflectionHelper.boxedTyp( t );
}
}
}
return t;
}
-
- /**
- * @param o the object from which to retrieve the value.
- *
- * @return Returns the value for this constraint from the specified object. Depending on the type either the value itself
- * is returned of method or field access is used to access the value.
- */
- private Object getValue(Object o) {
- switch ( elementType ) {
- case TYPE: {
- return o;
- }
- default: {
- return ReflectionHelper.getValue( member, o );
- }
- }
- }
}
15 years, 6 months