wms-jax.validation

aversableResolver;
  private ConstraintValidatorFactory constraintValidatorFactory;
  private final MessageInterpolator factoryMessageInterpolator;
  private final TraversableResolver factoryTraversableResolver;
  private final ConstraintValidatorFactory factoryConstraintValidatorFactory;
  private final ConstraintHelper constraintHelper;
  private final BeanMetaDataCache beanMetaDataCache;
  
  public ValidatorContextImpl(ConstraintValidatorFactory constraintValidatorFactory, MessageInterpolator factoryMessageInterpolator, TraversableResolver factoryTraversableResolver, ConstraintHelper constraintHelper, BeanMetaDataCache beanMetaDataCache)
  {
    factoryConstraintValidatorFactory = constraintValidatorFactory;
    this.factoryMessageInterpolator = factoryMessageInterpolator;
    this.factoryTraversableResolver = factoryTraversableResolver;
    this.constraintHelper = constraintHelper;
    this.beanMetaDataCache = beanMetaDataCache;
    messageInterpolator(factoryMessageInterpolator);
    traversableResolver(factoryTraversableResolver);
    constraintValidatorFactory(factoryConstraintValidatorFactory);
  }
  
  public ValidatorContext messageInterpolator(MessageInterpolator messageInterpolator)
  {
    if (messageInterpolator == null) {
      this.messageInterpolator = factoryMessageInterpolator;
    } else {
      this.messageInterpolator = messageInterpolator;
    }
    return this;
  }
  
  public ValidatorContext traversableResolver(TraversableResolver traversableResolver)
  {
    if (traversableResolver == null) {
      this.traversableResolver = factoryTraversableResolver;
    } else {
      this.traversableResolver = traversableResolver;
    }
    return this;
  }
  
  public ValidatorContext constraintValidatorFactory(ConstraintValidatorFactory factory)
  {
    if (constraintValidatorFactory == null) {
      constraintValidatorFactory = factoryConstraintValidatorFactory;
    } else {
      constraintValidatorFactory = factory;
    }
    return this;
  }
  
  public Validator getValidator()
  {
    return new ValidatorImpl(constraintValidatorFactory, messageInterpolator, traversableResolver, constraintHelper, beanMetaDataCache);
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.engine.ValidatorContextImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.engine;

import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
import javax.validation.spi.ConfigurationState;
import org.hibernate.validator.metadata.AnnotationIgnores;
import org.hibernate.validator.metadata.BeanMetaDataCache;
import org.hibernate.validator.metadata.BeanMetaDataImpl;
import org.hibernate.validator.metadata.ConstraintDescriptorImpl;
import org.hibernate.validator.metadata.ConstraintHelper;
import org.hibernate.validator.metadata.ConstraintOrigin;
import org.hibernate.validator.metadata.MetaConstraint;
import org.hibernate.validator.util.ReflectionHelper;
import org.hibernate.validator.xml.XmlMappingParser;

public class ValidatorFactoryImpl
  implements ValidatorFactory
{
  private final MessageInterpolator messageInterpolator;
  private final TraversableResolver traversableResolver;
  private final ConstraintValidatorFactory constraintValidatorFactory;
  private final ConstraintHelper constraintHelper;
  private final BeanMetaDataCache beanMetaDataCache;
  
  public ValidatorFactoryImpl(ConfigurationState configurationState)
  {
    messageInterpolator = configurationState.getMessageInterpolator();
    constraintValidatorFactory = configurationState.getConstraintValidatorFactory();
    traversableResolver = configurationState.getTraversableResolver();
    constraintHelper = new ConstraintHelper();
    beanMetaDataCache = new BeanMetaDataCache();
    
    initBeanMetaData(configurationState.getMappingStreams());
  }
  
  public Validator getValidator()
  {
    return usingContext().getValidator();
  }
  
  public MessageInterpolator getMessageInterpolator()
  {
    return messageInterpolator;
  }
  
  public TraversableResolver getTraversableResolver()
  {
    return traversableResolver;
  }
  
  public ConstraintValidatorFactory getConstraintValidatorFactory()
  {
    return constraintValidatorFactory;
  }
  
  public <T> T unwrap(Class<T> type)
  {
    throw new ValidationException("Type " + type + " not supported");
  }
  
  public ValidatorContext usingContext()
  {
    return new ValidatorContextImpl(constraintValidatorFactory, messageInterpolator, traversableResolver, constraintHelper, beanMetaDataCache);
  }
  
  private <T> void initBeanMetaData(Set<InputStream> mappingStreams)
  {
    XmlMappingParser mappingParser = new XmlMappingParser(constraintHelper);
    mappingParser.parse(mappingStreams);
    
    Set<Class<?>> processedClasses = mappingParser.getProcessedClasses();
    AnnotationIgnores annotationIgnores = mappingParser.getAnnotationIgnores();
    for (Class<?> clazz : processedClasses)
    {
      Class<T> beanClass = clazz;
      BeanMetaDataImpl<T> metaData = new BeanMetaDataImpl(beanClass, constraintHelper, annotationIgnores, beanMetaDataCache);
      
      List<Class<?>> classes = new ArrayList();
      ReflectionHelper.computeClassHierarchy(beanClass, classes);
      for (Class<?> classInHierarchy : classes) {
        if (processedClasses.contains(classInHierarchy)) {
          addXmlConfiguredConstraintToMetaData(mappingParser, beanClass, classInHierarchy, metaData);
        }
      }
      if (!mappingParser.getDefaultSequenceForClass(beanClass).isEmpty()) {
        metaData.setDefaultGroupSequence(mappingParser.getDefaultSequenceForClass(beanClass));
      }
      beanMetaDataCache.addBeanMetaData(beanClass, metaData);
    }
  }
  
  private <T, A extends Annotation> void addXmlConfiguredConstraintToMetaData(XmlMappingParser mappingParser, Class<T> rootClass, Class<?> hierarchyClass, BeanMetaDataImpl<T> metaData)
  {
    for (MetaConstraint<?, ? extends Annotation> constraint : mappingParser.getConstraintsForClass(hierarchyClass))
    {
      ConstraintOrigin definedIn = definedIn(rootClass, hierarchyClass);
      ConstraintDescriptorImpl<A> descriptor = new ConstraintDescriptorImpl(constraint.getDescriptor().getAnnotation(), constraintHelper, constraint.getElementType(), definedIn);
      
      MetaConstraint<T, A> newMetaConstraint = new MetaConstraint(rootClass, constraint.getMember(), descriptor);
      
      metaData.addMetaConstraint(hierarchyClass, newMetaConstraint);
    }
    for (Member m : mappingParser.getCascadedMembersForClass(hierarchyClass)) {
      metaData.addCascadedMember(m);
    }
  }
  
  private ConstraintOrigin definedIn(Class<?> rootClass, Class<?> hierarchyClass)
  {
    if (hierarchyClass.equals(rootClass)) {
      return ConstraintOrigin.DEFINED_LOCALLY;
    }
    return ConstraintOrigin.DEFINED_IN_HIERARCHY;
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.engine.ValidatorFactoryImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.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;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.ConstraintViolation;
import javax.validation.MessageInterpolator;
import javax.validation.Path;
import javax.validation.Path.Node;
import javax.validation.TraversableResolver;
import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.groups.Default;
import javax.validation.metadata.BeanDescriptor;
import org.hibernate.validator.engine.groups.Group;
import org.hibernate.validator.engine.groups.GroupChain;
import org.hibernate.validator.engine.groups.GroupChainGenerator;
import org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver;
import org.hibernate.validator.jtype.TypeUtils;
import org.hibernate.validator.metadata.BeanMetaData;
import org.hibernate.validator.metadata.BeanMetaDataCache;
import org.hibernate.validator.metadata.BeanMetaDataImpl;
import org.hibernate.validator.metadata.ConstraintHelper;
import org.hibernate.validator.metadata.MetaConstraint;
import org.hibernate.validator.util.ReflectionHelper;

public class ValidatorImpl
  implements Validator
{
  private static final Class<?>[] DEFAULT_GROUP_ARRAY = { Default.class };
  private final transient GroupChainGenerator groupChainGenerator;
  private final ConstraintValidatorFactory constraintValidatorFactory;
  private final MessageInterpolator messageInterpolator;
  private final TraversableResolver traversableResolver;
  private final ConstraintHelper constraintHelper;
  private final BeanMetaDataCache beanMetaDataCache;
  
  public ValidatorImpl(ConstraintValidatorFactory constraintValidatorFactory, MessageInterpolator messageInterpolator, TraversableResolver traversableResolver, ConstraintHelper constraintHelper, BeanMetaDataCache beanMetaDataCache)
  {
    this.constraintValidatorFactory = constraintValidatorFactory;
    this.messageInterpolator = messageInterpolator;
    this.traversableResolver = traversableResolver;
    this.constraintHelper = constraintHelper;
    this.beanMetaDataCache = beanMetaDataCache;
    
    groupChainGenerator = new GroupChainGenerator();
  }
  
  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);
    
    GlobalExecutionContext<T> context = GlobalExecutionContext.getContextForValidate(object, messageInterpolator, constraintValidatorFactory, getCachingTraversableResolver());
    
    List<ConstraintViolation<T>> list = validateInContext(object, context, groupChain, null);
    return new HashSet(list);
  }
  
  public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups)
  {
    if (object == null) {
      throw new IllegalArgumentException("Validated object cannot be null.");
    }
    sanityCheckPropertyPath(propertyName);
    GroupChain groupChain = determineGroupExecutionOrder(groups);
    
    List<ConstraintViolation<T>> failingConstraintViolations = new ArrayList();
    validateProperty(object, PathImpl.createPathFromString(propertyName), failingConstraintViolations, groupChain);
    
    return new HashSet(failingConstraintViolations);
  }
  
  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.");
    }
    sanityCheckPropertyPath(propertyName);
    GroupChain groupChain = determineGroupExecutionOrder(groups);
    
    List<ConstraintViolation<T>> failingConstraintViolations = new ArrayList();
    validateValue(beanType, value, PathImpl.createPathFromString(propertyName), failingConstraintViolations, groupChain);
    
    return new HashSet(failingConstraintViolations);
  }
  
  public BeanDescriptor getConstraintsForClass(Class<?> clazz)
  {
    return getBeanMetaData(clazz).getBeanDescriptor();
  }
  
  public <T> T unwrap(Class<T> type)
  {
    throw new ValidationException("Type " + type + " not supported");
  }
  
  private void sanityCheckPropertyPath(String propertyName)
  {
    if ((propertyName == null) || (propertyName.length() == 0)) {
      throw new IllegalArgumentException("Invalid property path.");
    }
  }
  
  private GroupChain determineGroupExecutionOrder(Class<?>[] groups)
  {
    if (groups == null) {
      throw new IllegalArgumentException("null passed as group name");
    }
    if (groups.length == 0) {
      groups = DEFAULT_GROUP_ARRAY;
    }
    return groupChainGenerator.getGroupChainFor(Arrays.asList(groups));
  }
  
  private <T, U, V> List<ConstraintViolation<T>> validateInContext(U value, GlobalExecutionContext<T> context, GroupChain groupChain, PathImpl path)
  {
    if (value == null) {
      return Collections.emptyList();
    }
    path = PathImpl.createShallowCopy(path);
    LocalExecutionContext<U, V> localExecutionContext = LocalExecutionContext.getLocalExecutionContext(value);
    
    BeanMetaData<U> beanMetaData = getBeanMetaData(localExecutionContext.getCurrentBeanType());
    if (beanMetaData.defaultGroupSequenceIsRedefined()) {
      groupChain.assertDefaultGroupSequenceIsExpandable(beanMetaData.getDefaultGroupSequence());
    }
    Iterator<Group> groupIterator = groupChain.getGroupIterator();
    while (groupIterator.hasNext())
    {
      Group group = (Group)groupIterator.next();
      localExecutionContext.setCurrentGroup(group.getGroup());
      validateConstraintsForCurrentGroup(context, localExecutionContext, path);
    }
    groupIterator = groupChain.getGroupIterator();
    while (groupIterator.hasNext())
    {
      Group group = (Group)groupIterator.next();
      localExecutionContext.setCurrentGroup(group.getGroup());
      validateCascadedConstraints(context, localExecutionContext, path);
    }
    Iterator<List<Group>> sequenceIterator = groupChain.getSequenceIterator();
    while (sequenceIterator.hasNext())
    {
      List<Group> sequence = (List)sequenceIterator.next();
      for (Group group : sequence)
      {
        int numberOfViolations = context.getFailingConstraints().size();
        localExecutionContext.setCurrentGroup(group.getGroup());
        
        validateConstraintsForCurrentGroup(context, localExecutionContext, path);
        validateCascadedConstraints(context, localExecutionContext, path);
        if (context.getFailingConstraints().size() > numberOfViolations) {
          break;
        }
      }
    }
    return context.getFailingConstraints();
  }
  
  private <T, U, V> void validateConstraintsForCurrentGroup(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, PathImpl path)
  {
    BeanMetaData<U> beanMetaData = getBeanMetaData(localExecutionContext.getCurrentBeanType());
    boolean validatingDefault = localExecutionContext.validatingDefault();
    boolean validatedBeanRedefinesDefault = beanMetaData.defaultGroupSequenceIsRedefined();
    if (!validatingDefault)
    {
      validateConstraintsForNonDefaultGroup(globalExecutionContext, localExecutionContext, path);
      return;
    }
    if (validatedBeanRedefinesDefault) {
      validateConstraintsForRedefinedDefaultGroupOnMainEntity(globalExecutionContext, localExecutionContext, path, beanMetaData);
    } else {
      validateConstraintsForRedefinedDefaultGroup(globalExecutionContext, localExecutionContext, path, beanMetaData);
    }
  }
  
  private <T, U, V> void validateConstraintsForRedefinedDefaultGroup(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, PathImpl path, BeanMetaData<U> beanMetaData)
  {
    for (Map.Entry<Class<?>, List<MetaConstraint<U, ? extends Annotation>>> entry : beanMetaData.getMetaConstraintsAsMap().entrySet())
    {
      Class<?> hostingBeanClass = (Class)entry.getKey();
      constraints = (List)entry.getValue();
      
      List<Class<?>> defaultGroupSequence = getBeanMetaData(hostingBeanClass).getDefaultGroupSequence();
      for (Class<?> defaultSequenceMember : defaultGroupSequence)
      {
        localExecutionContext.setCurrentGroup(defaultSequenceMember);
        boolean validationSuccessful = true;
        for (MetaConstraint<U, ? extends Annotation> metaConstraint : constraints)
        {
          boolean tmp = validateConstraint(globalExecutionContext, localExecutionContext, metaConstraint, path);
          
          validationSuccessful = (validationSuccessful) && (tmp);
        }
        if (!validationSuccessful) {
          break;
        }
      }
    }
    List<MetaConstraint<U, ? extends Annotation>> constraints;
  }
  
  private <T, U, V> void validateConstraintsForRedefinedDefaultGroupOnMainEntity(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, PathImpl path, BeanMetaData<U> beanMetaData)
  {
    List<Class<?>> defaultGroupSequence = beanMetaData.getDefaultGroupSequence();
    for (Class<?> defaultSequenceMember : defaultGroupSequence)
    {
      localExecutionContext.setCurrentGroup(defaultSequenceMember);
      boolean validationSuccessful = true;
      for (MetaConstraint<U, ? extends Annotation> metaConstraint : beanMetaData.getMetaConstraintsAsList())
      {
        boolean tmp = validateConstraint(globalExecutionContext, localExecutionContext, metaConstraint, path);
        
        validationSuccessful = (validationSuccessful) && (tmp);
      }
      if (!validationSuccessful) {
        break;
      }
    }
  }
  
  private <T, U, V> void validateConstraintsForNonDefaultGroup(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, PathImpl path)
  {
    BeanMetaData<U> beanMetaData = getBeanMetaData(localExecutionContext.getCurrentBeanType());
    for (MetaConstraint<U, ? extends Annotation> metaConstraint : beanMetaData.getMetaConstraintsAsList()) {
      validateConstraint(globalExecutionContext, localExecutionContext, metaConstraint, path);
    }
  }
  
  private <T, U, V> boolean validateConstraint(GlobalExecutionContext<T> globalExecutionContext, LocalExecutionContext<U, V> localExecutionContext, MetaConstraint<U, ?> metaConstraint, PathImpl path)
  {
    boolean validationSuccessful = true;
    PathImpl newPath;
    PathImpl newPath;
    if (path == null)
    {
      newPath = PathImpl.createNewPath(metaConstraint.getPropertyName());
    }
    else
    {
      newPath = PathImpl.createShallowCopy(path);
      if (metaConstraint.getElementType() != ElementType.TYPE) {
        newPath.addNode(new NodeImpl(metaConstraint.getPropertyName()));
      }
    }
    localExecutionContext.setPropertyPath(newPath);
    if (isValidationRequired(globalExecutionContext, localExecutionContext, metaConstraint))
    {
      Object valueToValidate = metaConstraint.getValue(localExecutionContext.getCurrentBean());
      localExecutionContext.setCurrentValidatedValue(valueToValidate);
      validationSuccessful = metaConstraint.validateConstraint(globalExecutionContext, localExecutionContext);
    }
    globalExecutionContext.markProcessed(localExecutionContext.getCurrentBean(), localExecutionContext.getCurrentGroup(), localExecutionContext.getPropertyPath());
    
    return validationSuccessful;
  }
  
  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);
      PathImpl newPath;
      PathImpl newPath;
      if (path == null)
      {
        newPath = PathImpl.createNewPath(ReflectionHelper.getPropertyName(member));
      }
      else
      {
        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(localExecutionContext, type, value);
          boolean isIndexable = isIndexable(type);
          validateCascadedConstraint(globalExecutionContext, iter, isIndexable, localExecutionContext.getCurrentGroup(), localExecutionContext.getPropertyPath());
        }
      }
    }
  }
  
  private <U, V> Iterator<?> createIteratorForCascadedValue(LocalExecutionContext<U, V> context, Type type, Object value)
  {
    Iterator<?> iter;
    if (ReflectionHelper.isIterable(type))
    {
      Iterator<?> iter = ((Iterable)value).iterator();
      context.markCurrentPropertyAsIterable();
    }
    else if (ReflectionHelper.isMap(type))
    {
      Map<?, ?> map = (Map)value;
      Iterator<?> iter = map.entrySet().iterator();
      context.markCurrentPropertyAsIterable();
    }
    else if (TypeUtils.isArray(type))
    {
      List<?> arrayList = Arrays.asList((Object[])value);
      Iterator<?> iter = arrayList.iterator();
      context.markCurrentPropertyAsIterable();
    }
    else
    {
      List<Object> list = new ArrayList();
      list.add(value);
      iter = list.iterator();
    }
    return iter;
  }
  
  private boolean isIndexable(Type type)
  {
    boolean isIndexable = false;
    if (ReflectionHelper.isList(type)) {
      isIndexable = true;
    } else if (ReflectionHelper.isMap(type)) {
      isIndexable = true;
    } else if (TypeUtils.isArray(type)) {
      isIndexable = true;
    }
    return isIndexable;
  }
  
  private <T> void validateCascadedConstraint(GlobalExecutionContext<T> context, Iterator<?> iter, boolean isIndexable, Class<?> currentGroup, PathImpl currentPath)
  {
    int i = 0;
    while (iter.hasNext())
    {
      Object value = iter.next();
      Integer index = Integer.valueOf(i);
      if ((value instanceof Map.Entry))
      {
        Object mapKey = ((Map.Entry)value).getKey();
        value = ((Map.Entry)value).getValue();
        currentPath.getLeafNode().setKey(mapKey);
      }
      else if (isIndexable)
      {
        currentPath.getLeafNode().setIndex(index);
      }
      if (!context.isAlreadyValidated(value, currentGroup, currentPath))
      {
        GroupChain groupChain = groupChainGenerator.getGroupChainFor(Arrays.asList(new Class[] { currentGroup }));
        
        validateInContext(value, context, groupChain, currentPath);
      }
      i++;
    }
  }
  
  private <T> void validateProperty(T object, PathImpl propertyPath, List<ConstraintViolation<T>> failingConstraintViolations, GroupChain groupChain)
  {
    Class<T> beanType = object.getClass();
    
    Set<MetaConstraint<T, ?>> metaConstraints = new HashSet();
    Object hostingBeanInstance = collectMetaConstraintsForPath(beanType, object, propertyPath.iterator(), metaConstraints);
    if (hostingBeanInstance == null) {
      throw new IllegalArgumentException("Invalid property path.");
    }
    if (metaConstraints.size() == 0) {
      return;
    }
    TraversableResolver cachedResolver = getCachingTraversableResolver();
    
    Iterator<Group> groupIterator = groupChain.getGroupIterator();
    while (groupIterator.hasNext())
    {
      Group group = (Group)groupIterator.next();
      validatePropertyForGroup(object, propertyPath, failingConstraintViolations, metaConstraints, hostingBeanInstance, group, cachedResolver);
    }
    Iterator<List<Group>> sequenceIterator = groupChain.getSequenceIterator();
    int numberOfConstraintViolationsBefore;
    while (sequenceIterator.hasNext())
    {
      List<Group> sequence = (List)sequenceIterator.next();
      numberOfConstraintViolationsBefore = failingConstraintViolations.size();
      for (Group group : sequence)
      {
        validatePropertyForGroup(object, propertyPath, failingConstraintViolations, metaConstraints, hostingBeanInstance, group, cachedResolver);
        if (failingConstraintViolations.size() > numberOfConstraintViolationsBefore) {
          break;
        }
      }
    }
  }
  
  private <T, U, V> void validatePropertyForGroup(T object, PathImpl path, List<ConstraintViolation<T>> failingConstraintViolations, Set<MetaConstraint<T, ?>> metaConstraints, U hostingBeanInstance, Group group, TraversableResolver cachedTraversableResolver)
  {
    int numberOfConstraintViolationsBefore = failingConstraintViolations.size();
    BeanMetaData<T> beanMetaData = getBeanMetaData(((MetaConstraint)metaConstraints.iterator().next()).getBeanClass());
    List<Class<?>> groupList;
    List<Class<?>> groupList;
    if (group.isDefaultGroup())
    {
      groupList = beanMetaData.getDefaultGroupSequence();
    }
    else
    {
      groupList = new ArrayList();
      groupList.add(group.getGroup());
    }
    for (Class<?> groupClass : groupList)
    {
      for (MetaConstraint<T, ?> metaConstraint : metaConstraints)
      {
        GlobalExecutionContext<T> context = GlobalExecutionContext.getContextForValidateProperty(object, messageInterpolator, constraintValidatorFactory, cachedTraversableResolver);
        
        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(valueToValidate);
          metaConstraint.validateConstraint(context, localContext);
          failingConstraintViolations.addAll(context.getFailingConstraints());
        }
      }
      if (failingConstraintViolations.size() > numberOfConstraintViolationsBefore) {
        break;
      }
    }
  }
  
  private <T> void validateValue(Class<T> beanType, Object value, PathImpl propertyPath, List<ConstraintViolation<T>> failingConstraintViolations, GroupChain groupChain)
  {
    Set<MetaConstraint<T, ?>> metaConstraints = new HashSet();
    collectMetaConstraintsForPath(beanType, null, propertyPath.iterator(), metaConstraints);
    if (metaConstraints.size() == 0) {
      return;
    }
    TraversableResolver cachedTraversableResolver = getCachingTraversableResolver();
    
    Iterator<Group> groupIterator = groupChain.getGroupIterator();
    while (groupIterator.hasNext())
    {
      Group group = (Group)groupIterator.next();
      validateValueForGroup(beanType, value, propertyPath, failingConstraintViolations, metaConstraints, group, cachedTraversableResolver);
    }
    Iterator<List<Group>> sequenceIterator = groupChain.getSequenceIterator();
    int numberOfConstraintViolations;
    while (sequenceIterator.hasNext())
    {
      List<Group> sequence = (List)sequenceIterator.next();
      numberOfConstraintViolations = failingConstraintViolations.size();
      for (Group group : sequence)
      {
        validateValueForGroup(beanType, value, propertyPath, failingConstraintViolations, metaConstraints, group, cachedTraversableResolver);
        if (failingConstraintViolations.size() > numberOfConstraintViolations) {
          break;
        }
      }
    }
  }
  
  private <U, V> void validateValueForGroup(Class<U> beanType, V value, PathImpl path, List<ConstraintViolation<U>> failingConstraintViolations, Set<MetaConstraint<U, ?>> metaConstraints, Group group, TraversableResolver cachedTraversableResolver)
  {
    int numberOfConstraintViolations = failingConstraintViolations.size();
    BeanMetaData<U> beanMetaData = getBeanMetaData(((MetaConstraint)metaConstraints.iterator().next()).getBeanClass());
    List<Class<?>> groupList;
    List<Class<?>> groupList;
    if (group.isDefaultGroup())
    {
      groupList = beanMetaData.getDefaultGroupSequence();
    }
    else
    {
      groupList = new ArrayList();
      groupList.add(group.getGroup());
    }
    for (Class<?> groupClass : groupList)
    {
      for (MetaConstraint<U, ?> metaConstraint : metaConstraints)
      {
        GlobalExecutionContext<U> context = GlobalExecutionContext.getContextForValidateValue(beanType, messageInterpolator, constraintValidatorFactory, cachedTraversableResolver);
        
        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());
        }
      }
      if (failingConstraintViolations.size() > numberOfConstraintViolations) {
        break;
      }
    }
  }
  
  private <T> Object collectMetaConstraintsForPath(Class<T> clazz, Object value, Iterator<Path.Node> propertyIter, Set<MetaConstraint<T, ?>> metaConstraints)
  {
    Path.Node elem = (Path.Node)propertyIter.next();
    
    BeanMetaData<T> metaData = getBeanMetaData(clazz);
    if (!metaData.isPropertyPresent(elem.getName())) {
      throw new IllegalArgumentException("Invalid property path. There is no property " + elem.getName() + " in entity " + metaData.getBeanClass().getName());
    }
    if (!propertyIter.hasNext())
    {
      List<MetaConstraint<T, ? extends Annotation>> metaConstraintList = metaData.getMetaConstraintsAsList();
      for (MetaConstraint<T, ?> metaConstraint : metaConstraintList) {
        if ((elem.getName() != null) && (elem.getName().equals(metaConstraint.getPropertyName()))) {
          metaConstraints.add(metaConstraint);
        }
      }
    }
    else
    {
      List<Member> cascadedMembers = metaData.getCascadedMembers();
      for (Member m : cascadedMembers) {
        if (ReflectionHelper.getPropertyName(m).equals(elem.getName()))
        {
          Type type = ReflectionHelper.typeOf(m);
          value = value == null ? null : ReflectionHelper.getValue(m, value);
          if (elem.isInIterable())
          {
            if ((value != null) && (elem.getIndex() != null)) {
              value = ReflectionHelper.getIndexedValue(value, elem.getIndex());
            } else if ((value != null) && (elem.getKey() != null)) {
              value = ReflectionHelper.getMappedValue(value, elem.getKey());
            } else if (value != null) {
              throw new IllegalArgumentException("Property path must provide index or map key");
            }
            type = ReflectionHelper.getIndexedType(type);
          }
          Class<T> valueClass = (Class)(value == null ? type : value.getClass());
          
          return collectMetaConstraintsForPath(valueClass, value, propertyIter, metaConstraints);
        }
      }
    }
    return value;
  }
  
  private <U> BeanMetaData<U> getBeanMetaData(Class<U> beanClass)
  {
    BeanMetaDataImpl<U> beanMetaData = beanMetaDataCache.getBeanMetaData(beanClass);
    if (beanMetaData == null)
    {
      beanMetaData = new BeanMetaDataImpl(beanClass, constraintHelper, beanMetaDataCache);
      beanMetaDataCache.addBeanMetaData(beanClass, beanMetaData);
    }
    return beanMetaData;
  }
  
  private TraversableResolver getCachingTraversableResolver()
  {
    return new SingleThreadCachedTraversableResolver(traversableResolver);
  }
  
  private boolean isValidationRequired(GlobalExecutionContext globalContext, LocalExecutionContext localContext, MetaConstraint metaConstraint)
  {
    if (!metaConstraint.getGroupList().contains(localContext.getCurrentGroup())) {
      return false;
    }
    Path pathToObject = localContext.getPropertyPath().getPathWithoutLeafNode();
    if (pathToObject == null) {
      pathToObject = PathImpl.createNewPath(null);
    }
    boolean isReachable;
    try
    {
      isReachable = globalContext.getTraversableResolver().isReachable(localContext.getCurrentBean(), localContext.getPropertyPath().getLeafNode(), globalContext.getRootBeanClass(), pathToObject, metaConstraint.getElementType());
    }
    catch (RuntimeException e)
    {
      throw new ValidationException("Call to TraversableResolver.isReachable() threw an exception", e);
    }
    return isReachable;
  }
  
  private boolean isCascadeRequired(GlobalExecutionContext globalContext, LocalExecutionContext localContext, Member member)
  {
    ElementType type = (member instanceof Field) ? ElementType.FIELD : ElementType.METHOD;
    
    Path pathToObject = localContext.getPropertyPath().getPathWithoutLeafNode();
    if (pathToObject == null) {
      pathToObject = PathImpl.createNewPath(null);
    }
    boolean isReachable;
    try
    {
      isReachable = globalContext.getTraversableResolver().isReachable(localContext.getCurrentBean(), localContext.getPropertyPath().getLeafNode(), globalContext.getRootBeanClass(), pathToObject, type);
    }
    catch (RuntimeException e)
    {
      throw new ValidationException("Call to TraversableResolver.isReachable() threw an exception", e);
    }
    boolean isCascadable;
    try
    {
      isCascadable = globalContext.getTraversableResolver().isCascadable(localContext.getCurrentBean(), localContext.getPropertyPath().getLeafNode(), globalContext.getRootBeanClass(), pathToObject, type);
    }
    catch (RuntimeException e)
    {
      throw new ValidationException("Call to TraversableResolver.isCascadable() threw an exception", e);
    }
    return (isReachable) && (isCascadable);
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.engine.ValidatorImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator;

import javax.validation.Configuration;
import javax.validation.ValidatorFactory;
import javax.validation.spi.BootstrapState;
import javax.validation.spi.ConfigurationState;
import javax.validation.spi.ValidationProvider;
import org.hibernate.validator.engine.ConfigurationImpl;
import org.hibernate.validator.engine.ValidatorFactoryImpl;

public class HibernateValidator
  implements ValidationProvider<HibernateValidatorConfiguration>
{
  public HibernateValidatorConfiguration createSpecializedConfiguration(BootstrapState state)
  {
    return (HibernateValidatorConfiguration)HibernateValidatorConfiguration.class.cast(new ConfigurationImpl(this));
  }
  
  public Configuration<?> createGenericConfiguration(BootstrapState state)
  {
    return new ConfigurationImpl(state);
  }
  
  public ValidatorFactory buildValidatorFactory(ConfigurationState configurationState)
  {
    return new ValidatorFactoryImpl(configurationState);
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.HibernateValidator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator;

import javax.validation.Configuration;

public abstract interface HibernateValidatorConfiguration
  extends Configuration<HibernateValidatorConfiguration>
{}

/* Location:
 * Qualified Name:     org.hibernate.validator.HibernateValidatorConfiguration
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.jtype;

public abstract interface ClassSerializer
{
  public abstract String toString(Class<?> paramClass);
}

/* Location:
 * Qualified Name:     org.hibernate.validator.jtype.ClassSerializer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.jtype;

class ClassSerializers$1
  implements ClassSerializer
{
  public String toString(Class<?> klass)
  {
    return klass.getName();
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.jtype.ClassSerializers.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.jtype;

class ClassSerializers$2
  implements ClassSerializer
{
  public String toString(Class<?> klass)
  {
    return ClassUtils.getUnqualifiedClassName(klass);
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.jtype.ClassSerializers.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.jtype;

public final class ClassSerializers
{
  public static final ClassSerializer QUALIFIED = new ClassSerializer()
  {
    public String toString(Class<?> klass)
    {
      return klass.getName();
    }
  };
  public static final ClassSerializer UNQUALIFIED = new ClassSerializer()
  {
    public String toString(Class<?> klass)
    {
      return ClassUtils.getUnqualifiedClassName(klass);
    }
  };
  
  private ClassSerializers()
  {
    throw new AssertionError();
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.jtype.ClassSerializers
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.jtype;

import java.lang.reflect.Array;

final class ClassUtils
{
  private ClassUtils()
  {
    throw new AssertionError();
  }
  
  public static String getUnqualifiedClassName(Class<?> klass)
  {
    return getUnqualifiedClassName(klass.getName());
  }
  
  public static String getUnqualifiedClassName(String className)
  {
    int dot = className.lastIndexOf('.');
    
    return dot == -1 ? className : className.substring(dot + 1);
  }
  
  public static Class<?> getArrayType(Class<?> componentType)
  {
    return Array.newInstance(componentType, 0).getClass();
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.jtype.ClassUtils
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.jtype;

import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Type;

class DefaultGenericArrayType
  implements GenericArrayType
{
  private final Type componentType;
  
  public DefaultGenericArrayType(Type componentType)
  {
    this.componentType = ((Type)Utils.checkNotNull(componentType, "componentType"));
  }
  
  public Type getGenericComponentType()
  {
    return componentType;
  }
  
  public int hashCode()
  {
    return componentType.hashCode();
  }
  
  public boolean equals(Object object)
  {
    if (!(object instanceof GenericArrayType)) {
      return false;
    }
    GenericArrayType type = (GenericArrayType)object;
    
    return componentType.equals(type.getGenericComponentType());
  }
  
  public String toString()
  {
    return toString(this);
  }
  
  public static String toString(GenericArrayType type)
  {
    return toString(type, ClassSerializers.QUALIFIED);
  }
  
  public static String toString(GenericArrayType type, ClassSerializer serializer)
  {
    return TypeUtils.toString(type.getGenericComponentType(), serializer) + "[]";
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.jtype.DefaultGenericArrayType
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.jtype;

import java.lang.reflect.MalformedParameterizedTypeException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;

class DefaultParameterizedType
  implements ParameterizedType
{
  private final Type ownerType;
  private final Type rawType;
  private final Type[] actualTypeArguments;
  
  public DefaultParameterizedType(Type ownerType, Class<?> rawType, Type[] actualTypeArguments)
  {
    this.rawType = ((Type)Utils.checkNotNull(rawType, "rawType"));
    if (actualTypeArguments == null) {
      actualTypeArguments = new Type[0];
    }
    TypeVariable<?>[] typeParameters = rawType.getTypeParameters();
    if (typeParameters.length != actualTypeArguments.length) {
      throw new MalformedParameterizedTypeException();
    }
    if (ownerType == null) {
      ownerType = rawType.getDeclaringClass();
    }
    this.ownerType = ownerType;
    this.actualTypeArguments = ((T
1 2 3 4 5 6 7 8 9 10 11

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd