Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.internal.engine;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
Context object keeping track of all important data for a top level javax.validation.Validator.validate(java.lang.Object,java.lang.Class[]) }, javax.validation.Validator.validateValue(java.lang.Class,java.lang.String,java.lang.Object,java.lang.Class[]) } or javax.validation.Validator.validateProperty(java.lang.Object,java.lang.String,java.lang.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(s):
Hardy Ferentschik
Emmanuel Bernard
Gunnar Morling
 
 public abstract class ValidationContext<T, C extends ConstraintViolation<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<?>, IdentitySetprocessedObjects;

Maps an object to a list of paths in which it has been invalidated.
 
 	private final Map<ObjectSet<PathImpl>> processedPaths;

Contains all failing constraints so far.
 
 	private final Set<C> failingConstraintViolations;

Flag indicating whether an object can only be validated once per group or once per group AND validation path.
 
 	private boolean allowOneValidationPerPath = true;

The message resolver which should be used in this context.
 
The constraint factory which should be used in this context.
 
Allows a JPA provider to decide whether a property should be validated.
 
Whether or not validation should fail on the first constraint violation.
 
	private final boolean failFast;
	public static <T> ValidationContext<T, ConstraintViolation<T>> getContextForValidate(T objectMessageInterpolator messageInterpolatorConstraintValidatorFactory constraintValidatorFactoryTraversableResolver traversableResolverboolean failFast) {
		@SuppressWarnings("unchecked")
		Class<T> rootBeanClass = (Class<T>) object.getClass();
				rootBeanClassobjectmessageInterpolatorconstraintValidatorFactorytraversableResolverfailFast
		);
	}
	public static <T> ValidationContext<T, ConstraintViolation<T>> getContextForValidateProperty(T rootBeanMessageInterpolator messageInterpolatorConstraintValidatorFactory constraintValidatorFactoryTraversableResolver traversableResolverboolean failFast) {
		@SuppressWarnings("unchecked")
		Class<T> rootBeanClass = (Class<T>) rootBean.getClass();
				rootBeanClassrootBeanmessageInterpolatorconstraintValidatorFactorytraversableResolverfailFast
		);
	}
	public static <T> ValidationContext<T, ConstraintViolation<T>> getContextForValidateValue(Class<T> rootBeanClassMessageInterpolator messageInterpolatorConstraintValidatorFactory constraintValidatorFactoryTraversableResolver traversableResolverboolean failFast) {
				rootBeanClass,
				null,
				messageInterpolator,
				constraintValidatorFactory,
				traversableResolver,
				failFast
		);
	}
	public static <T> MethodValidationContext<T> getContextForValidateParameter(Method methodint parameterIndex, T objectMessageInterpolator messageInterpolatorConstraintValidatorFactory constraintValidatorFactoryTraversableResolver traversableResolverboolean failFast) {
		@SuppressWarnings("unchecked")
		Class<T> rootBeanClass = (Class<T>) object.getClass();
		return new MethodValidationContext<T>(
				rootBeanClass,
				object,
				method,
				parameterIndex,
				messageInterpolator,
				constraintValidatorFactory,
				traversableResolver,
				failFast
		);
	}
	public static <T> MethodValidationContext<T> getContextForValidateParameters(Method method, T objectMessageInterpolator messageInterpolatorConstraintValidatorFactory constraintValidatorFactoryTraversableResolver traversableResolverboolean failFast) {
		@SuppressWarnings("unchecked")
		Class<T> rootBeanClass = (Class<T>) object.getClass();
		return new MethodValidationContext<T>(
				rootBeanClass,
				object,
				method,
				messageInterpolator,
				constraintValidatorFactory,
				traversableResolver,
				failFast
		);
	}
	protected ValidationContext(Class<T> rootBeanClass, T rootBeanMessageInterpolator messageInterpolatorConstraintValidatorFactory constraintValidatorFactoryTraversableResolver traversableResolverboolean failFast) {
		this. = rootBean;
		this. = rootBeanClass;
		this. = messageInterpolator;
		this. = constraintValidatorFactory;
		this. = traversableResolver;
		this. = failFast;
	}
	public final T getRootBean() {
		return ;
	}
	public final Class<T> getRootBeanClass() {
	}
	}
	public final boolean isFailFastModeEnabled() {
		return ;
	}
	public abstract <U, V> C createConstraintViolation(ValueContext<U, V> localContextMessageAndPath messageAndPathConstraintDescriptor<?> descriptor);
	public final <U, V> List<C> createConstraintViolations(ValueContext<U, V> localContextConstraintValidatorContextImpl constraintValidatorContext) {
		List<C> constraintViolations = new ArrayList<C>();
		for ( MessageAndPath messageAndPath : constraintValidatorContext.getMessageAndPathList() ) {
violation = createConstraintViolation(
					localContextmessageAndPathconstraintValidatorContext.getConstraintDescriptor()
			);
			constraintViolations.addviolation );
		}
		return constraintViolations;
	}
	}
	public boolean isAlreadyValidated(Object valueClass<?> groupPathImpl path) {
		boolean alreadyValidated;
		alreadyValidated = isAlreadyValidatedForCurrentGroupvaluegroup );
		if ( alreadyValidated &&  ) {
			alreadyValidated = isAlreadyValidatedForPathvaluepath );
		}
		return alreadyValidated;
	}
	public void markProcessed(Object valueClass<?> groupPathImpl path) {
		markProcessForCurrentGroupvaluegroup );
			markProcessedForCurrentPathvaluepath );
		}
	}
	public final void addConstraintFailures(Set<C> failingConstraintViolations) {
		this..addAllfailingConstraintViolations );
	}
	public Set<C> getFailingConstraints() {
	}
	private boolean isAlreadyValidatedForPath(Object valuePathImpl path) {
		Set<PathImplpathSet = .getvalue );
		if ( pathSet == null ) {
			return false;
		}
		for ( PathImpl p : pathSet ) {
			if ( path.isRootPath() || p.isRootPath() || isSubPathOfpathp ) || isSubPathOfppath ) ) {
				return true;
			}
		}
		return false;
	}
	private boolean isSubPathOf(Path p1Path p2) {
		Iterator<Path.Nodep1Iter = p1.iterator();
		Iterator<Path.Nodep2Iter = p2.iterator();
		while ( p1Iter.hasNext() ) {
			Path.Node p1Node = p1Iter.next();
			if ( !p2Iter.hasNext() ) {
				return false;
			}
			Path.Node p2Node = p2Iter.next();
			if ( !p1Node.equalsp2Node ) ) {
				return false;
			}
		}
		return true;
	}
	private boolean isAlreadyValidatedForCurrentGroup(Object valueClass<?> group) {
		final IdentitySet objectsProcessedInCurrentGroups = .getgroup );
		return objectsProcessedInCurrentGroups != null && objectsProcessedInCurrentGroups.containsvalue );
	}
	private void markProcessedForCurrentPath(Object valuePathImpl path) {
		if ( .containsKeyvalue ) ) {
			.getvalue ).addpath );
		}
		else {
			Set<PathImplset = new HashSet<PathImpl>();
			set.addpath );
			.putvalueset );
		}
	}
	private void markProcessForCurrentGroup(Object valueClass<?> group) {
		if ( .containsKeygroup ) ) {
			.getgroup ).addvalue );
		}
		else {
			IdentitySet set = new IdentitySet();
			set.addvalue );
			.putgroupset );
		}
	}
New to GrepCode? Check out our FAQ X