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.groups;
 
 import java.util.List;
 
Helper class used to order groups and sequences into the right order for validation.

Author(s):
Hardy Ferentschik
Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI
 
 public class ValidationOrderGenerator {
 
 	private static final Log log = LoggerFactory.make();
 
 	private final ConcurrentMap<Class<?>, SequenceresolvedSequences = new ConcurrentHashMap<Class<?>, Sequence>();

Generates a order of groups and sequences for the specified validation groups.

Parameters:
groups The groups specified at the validation call.
Returns:
an instance of ValidationOrder defining the order in which validation has to occur.
 
 		if ( groups == null || groups.size() == 0 ) {
 		}
 
 		for ( Class<?> clazz : groups ) {
 			if ( !clazz.isInterface() ) {
 			}
 		}
 
 		for ( Class<?> clazz : groups ) {
 			if ( isGroupSequenceclazz ) ) {
 				insertSequenceclazzorder );
 			}
 			else {
 				Group group = new Groupclazz );
 				order.insertGroupgroup );
 				insertInheritedGroupsclazzorder );
 			}
 		}
 
 		return order;
 	}
 
 	private boolean isGroupSequence(Class<?> clazz) {
 		return clazz.getAnnotationGroupSequence.class ) != null;
 	}

Recursively add inherited groups into the group chain.

Parameters:
clazz The group interface
chain The group chain we are currently building.
 
 	private void insertInheritedGroups(Class<?> clazzDefaultValidationOrder chain) {
 		for ( Class<?> inheritedGroup : clazz.getInterfaces() ) {
 			Group group = new GroupinheritedGroup );
 			chain.insertGroupgroup );
 			insertInheritedGroupsinheritedGroupchain );
 		}
 	}
 
 	private void insertSequence(Class<?> sequenceClassDefaultValidationOrder validationOrder) {
 		Sequence sequence = .getsequenceClass );
 		if ( sequence == null ) {
 			sequence = resolveSequencesequenceClassnew ArrayList<Class<?>>() );
 			// we expand the inherited groups only after we determined whether the sequence is expandable
 
 			// cache already resolved sequences
			final Sequence cachedResolvedSequence = .putIfAbsentsequenceClasssequence );
			if ( cachedResolvedSequence != null ) {
				sequence = cachedResolvedSequence;
			}
		}
		validationOrder.insertSequencesequence );
	}
	private Sequence resolveSequence(Class<?> sequenceClassList<Class<?>> processedSequences) {
		if ( processedSequences.containssequenceClass ) ) {
		}
		else {
			processedSequences.addsequenceClass );
		}
		List<GroupresolvedSequenceGroups = new ArrayList<Group>();
		GroupSequence sequenceAnnotation = sequenceClass.getAnnotationGroupSequence.class );
		Class<?>[] sequenceArray = sequenceAnnotation.value();
		for ( Class<?> clazz : sequenceArray ) {
			if ( isGroupSequenceclazz ) ) {
				Sequence tmpSequence = resolveSequenceclazzprocessedSequences );
				addGroupsresolvedSequenceGroupstmpSequence.getComposingGroups() );
			}
			else {
				List<Grouplist = new ArrayList<Group>();
				list.addnew Groupclazz ) );
				addGroupsresolvedSequenceGroupslist );
			}
		}
		return new SequencesequenceClassresolvedSequenceGroups );
	}
	private void addGroups(List<GroupresolvedGroupSequenceList<Groupgroups) {
		for ( Group tmpGroup : groups ) {
			if ( resolvedGroupSequence.containstmpGroup ) && resolvedGroupSequence.indexOftmpGroup ) < resolvedGroupSequence
					.size() - 1 ) {
			}
			resolvedGroupSequence.addtmpGroup );
		}
	}
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		sb.append"ValidationOrderGenerator" );
		sb.append"{resolvedSequences=" ).append );
		sb.append'}' );
		return sb.toString();
	}
New to GrepCode? Check out our FAQ X