wms-jax.validation

ort javax.validation.ConstraintValidatorFactory;
import javax.validation.ConstraintViolation;
import javax.validation.UnexpectedTypeException;
import javax.validation.ValidationException;
import javax.validation.metadata.ConstraintDescriptor;
import org.hibernate.validator.jtype.TypeUtils;
import org.hibernate.validator.metadata.ConstraintDescriptorImpl;
import org.hibernate.validator.util.LoggerFactory;
import org.hibernate.validator.util.ValidatorTypeHelper;
import org.slf4j.Logger;

public class ConstraintTree<A extends Annotation>
{
  private static final Logger log = ;
  private final ConstraintTree<?> parent;
  private final List<ConstraintTree<?>> children;
  private final ConstraintDescriptorImpl<A> descriptor;
  private final Map<ValidatorCacheKey, ConstraintValidator<A, ?>> constraintValidatorCache;
  
  public ConstraintTree(ConstraintDescriptorImpl<A> descriptor)
  {
    this(descriptor, null);
  }
  
  private ConstraintTree(ConstraintDescriptorImpl<A> descriptor, ConstraintTree<?> parent)
  {
    this.parent = parent;
    this.descriptor = descriptor;
    constraintValidatorCache = new ConcurrentHashMap();
    
    Set<ConstraintDescriptorImpl<?>> composingConstraints = new HashSet();
    for (ConstraintDescriptor<?> composingConstraint : descriptor.getComposingConstraints()) {
      composingConstraints.add((ConstraintDescriptorImpl)composingConstraint);
    }
    children = new ArrayList(composingConstraints.size());
    for (ConstraintDescriptorImpl<?> composingDescriptor : composingConstraints)
    {
      ConstraintTree<?> treeNode = createConstraintTree(composingDescriptor);
      children.add(treeNode);
    }
  }
  
  private <U extends Annotation> ConstraintTree<U> createConstraintTree(ConstraintDescriptorImpl<U> composingDescriptor)
  {
    return new ConstraintTree(composingDescriptor, this);
  }
  
  public List<ConstraintTree<?>> getChildren()
  {
    return children;
  }
  
  public ConstraintDescriptorImpl<A> getDescriptor()
  {
    return descriptor;
  }
  
  public <T, U, V> void validateConstraints(Type type, GlobalExecutionContext<T> executionContext, LocalExecutionContext<U, V> localExecutionContext, List<ConstraintViolation<T>> constraintViolations)
  {
    for (ConstraintTree<?> tree : getChildren())
    {
      List<ConstraintViolation<T>> tmpViolations = new ArrayList();
      tree.validateConstraints(type, executionContext, localExecutionContext, tmpViolations);
      constraintViolations.addAll(tmpViolations);
    }
    ConstraintValidatorContextImpl constraintValidatorContext = new ConstraintValidatorContextImpl(localExecutionContext.getPropertyPath(), descriptor);
    if (!descriptor.getConstraintValidatorClasses().isEmpty())
    {
      if (log.isTraceEnabled()) {
        log.trace("Validating value {} against constraint defined by {}", localExecutionContext.getCurrentValidatedValue(), descriptor);
      }
      ConstraintValidator<A, V> validator = getInitializedValidator(type, executionContext.getConstraintValidatorFactory());
      
      validateSingleConstraint(executionContext, localExecutionContext, constraintViolations, constraintValidatorContext, validator);
    }
    if ((reportAsSingleViolation()) && (constraintViolations.size() > 0))
    {
      constraintViolations.clear();
      String message = (String)getDescriptor().getAttributes().get("message");
      MessageAndPath messageAndPath = new MessageAndPath(message, localExecutionContext.getPropertyPath());
      ConstraintViolation<T> violation = executionContext.createConstraintViolation(localExecutionContext, messageAndPath, descriptor);
      
      constraintViolations.add(violation);
    }
  }
  
  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(localExecutionContext.getCurrentValidatedValue(), constraintValidatorContext);
    }
    catch (RuntimeException e)
    {
      throw new ValidationException("Unexpected exception during isValid call", e);
    }
    if (!isValid) {
      constraintViolations.addAll(executionContext.createConstraintViolations(localExecutionContext, constraintValidatorContext));
    }
  }
  
  private boolean reportAsSingleViolation()
  {
    return getDescriptor().isReportAsSingleViolation();
  }
  
  private <V> ConstraintValidator<A, V> getInitializedValidator(Type type, ConstraintValidatorFactory constraintFactory)
  {
    Class<? extends ConstraintValidator<?, ?>> validatorClass = findMatchingValidatorClass(type);
    if (!(constraintFactory instanceof ConstraintValidatorFactoryImpl)) {
      return createAndInitializeValidator(constraintFactory, validatorClass);
    }
    ValidatorCacheKey key = new ValidatorCacheKey(constraintFactory, validatorClass, null);
    ConstraintValidator<A, V> constraintValidator;
    if (!constraintValidatorCache.containsKey(key))
    {
      ConstraintValidator<A, V> constraintValidator = createAndInitializeValidator(constraintFactory, validatorClass);
      constraintValidatorCache.put(key, constraintValidator);
    }
    else
    {
      if (log.isTraceEnabled()) {
        log.trace("Constraint validator {} found in cache");
      }
      constraintValidator = (ConstraintValidator)constraintValidatorCache.get(key);
    }
    return constraintValidator;
  }
  
  private <V> ConstraintValidator<A, V> createAndInitializeValidator(ConstraintValidatorFactory constraintFactory, Class<? extends ConstraintValidator<?, ?>> validatorClass)
  {
    ConstraintValidator<A, V> constraintValidator = constraintFactory.getInstance(validatorClass);
    if (constraintValidator == null) {
      throw new ValidationException("Constraint factory returned null when trying to create instance of " + validatorClass.getName());
    }
    initializeConstraint(descriptor, constraintValidator);
    return constraintValidator;
  }
  
  private Class<? extends ConstraintValidator<?, ?>> findMatchingValidatorClass(Type type)
  {
    Map<Type, Class<? extends ConstraintValidator<?, ?>>> validatorTypes = ValidatorTypeHelper.getValidatorsTypes(descriptor.getConstraintValidatorClasses());
    
    List<Type> suitableTypes = new ArrayList();
    findSuitableValidatorTypes(type, validatorTypes, suitableTypes);
    
    resolveAssignableTypes(suitableTypes);
    verifyResolveWasUnique(type, suitableTypes);
    
    return (Class)validatorTypes.get(suitableTypes.get(0));
  }
  
  private void verifyResolveWasUnique(Type valueClass, List<Type> assignableClasses)
  {
    if (assignableClasses.size() == 0)
    {
      String className = valueClass.toString();
      if ((valueClass instanceof Class))
      {
        Class<?> clazz = (Class)valueClass;
        if (clazz.isArray()) {
          className = clazz.getComponentType().toString() + "[]";
        } else {
          className = clazz.getName();
        }
      }
      throw new UnexpectedTypeException("No validator could be found for type: " + className);
    }
    if (assignableClasses.size() > 1)
    {
      StringBuilder builder = new StringBuilder();
      builder.append("There are multiple validator classes which could validate the type ");
      builder.append(valueClass);
      builder.append(". The validator classes are: ");
      for (Type clazz : assignableClasses)
      {
        builder.append(clazz);
        builder.append(", ");
      }
      builder.delete(builder.length() - 2, builder.length());
      throw new UnexpectedTypeException(builder.toString());
    }
  }
  
  private void findSuitableValidatorTypes(Type type, Map<Type, Class<? extends ConstraintValidator<?, ?>>> validatorsTypes, List<Type> suitableTypes)
  {
    for (Type validatorType : validatorsTypes.keySet()) {
      if ((TypeUtils.isAssignable(validatorType, type)) && (!suitableTypes.contains(validatorType))) {
        suitableTypes.add(validatorType);
      }
    }
  }
  
  private void resolveAssignableTypes(List<Type> assignableTypes)
  {
    if ((assignableTypes.size() == 0) || (assignableTypes.size() == 1)) {
      return;
    }
    List<Type> typesToRemove = new ArrayList();
    do
    {
      typesToRemove.clear();
      Type type = (Type)assignableTypes.get(0);
      for (int i = 1; i < assignableTypes.size(); i++) {
        if (TypeUtils.isAssignable(type, (Type)assignableTypes.get(i))) {
          typesToRemove.add(type);
        } else if (TypeUtils.isAssignable((Type)assignableTypes.get(i), type)) {
          typesToRemove.add(assignableTypes.get(i));
        }
      }
      assignableTypes.removeAll(typesToRemove);
    } while (typesToRemove.size() > 0);
  }
  
  private <V> void initializeConstraint(ConstraintDescriptor<A> descriptor, ConstraintValidator<A, V> constraintValidator)
  {
    try
    {
      constraintValidator.initialize(descriptor.getAnnotation());
    }
    catch (RuntimeException e)
    {
      throw new ValidationException("Unable to initialize " + constraintValidator.getClass().getName(), e);
    }
  }
  
  public String toString()
  {
    StringBuilder sb = new StringBuilder();
    sb.append("ConstraintTree");
    sb.append("{ descriptor=").append(descriptor);
    sb.append(", isRoot=").append(parent == null);
    sb.append(", constraintValidatorCache=").append(constraintValidatorCache);
    sb.append('}');
    return sb.toString();
  }
  
  private static class ValidatorCacheKey
  {
    private ConstraintValidatorFactory constraintValidatorFactory;
    private Class<? extends ConstraintValidator<?, ?>> validatorType;
    
    private ValidatorCacheKey(ConstraintValidatorFactory constraintValidatorFactory, Class<? extends ConstraintValidator<?, ?>> validatorType)
    {
      this.constraintValidatorFactory = constraintValidatorFactory;
      this.validatorType = validatorType;
    }
    
    public boolean equals(Object o)
    {
      if (this == o) {
        return true;
      }
      if ((o == null) || (getClass() != o.getClass())) {
        return false;
      }
      ValidatorCacheKey that = (ValidatorCacheKey)o;
      if (constraintValidatorFactory != null ? !constraintValidatorFactory.equals(constraintValidatorFactory) : constraintValidatorFactory != null) {
        return false;
      }
      if (validatorType != null ? !validatorType.equals(validatorType) : validatorType != null) {
        return false;
      }
      return true;
    }
    
    public int hashCode()
    {
      int result = constraintValidatorFactory != null ? constraintValidatorFactory.hashCode() : 0;
      result = 31 * result + (validatorType != null ? validatorType.hashCode() : 0);
      return result;
    }
  }
}

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

import java.util.List;
import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext;

class ConstraintValidatorContextImpl$ErrorBuilderImpl
  implements ConstraintValidatorContext.ConstraintViolationBuilder
{
  String messageTemplate;
  PathImpl propertyPath;
  
  ConstraintValidatorContextImpl$ErrorBuilderImpl(ConstraintValidatorContextImpl paramConstraintValidatorContextImpl, String template, PathImpl path)
  {
    messageTemplate = template;
    propertyPath = path;
  }
  
  public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext addNode(String name)
  {
    PathImpl path;
    PathImpl path;
    if (propertyPath.isRootPath())
    {
      path = PathImpl.createNewPath(name);
    }
    else
    {
      path = PathImpl.createShallowCopy(propertyPath);
      path.addNode(new NodeImpl(name));
    }
    return new ConstraintValidatorContextImpl.NodeBuilderImpl(this$0, messageTemplate, path);
  }
  
  public ConstraintValidatorContext addConstraintViolation()
  {
    ConstraintValidatorContextImpl.access$000(this$0).add(new MessageAndPath(messageTemplate, propertyPath));
    return this$0;
  }
}

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

import java.util.List;
import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder;

class ConstraintValidatorContextImpl$InIterableNodeBuilderImpl
  implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext
{
  String messageTemplate;
  PathImpl propertyPath;
  String deferredNodeName;
  
  ConstraintValidatorContextImpl$InIterableNodeBuilderImpl(ConstraintValidatorContextImpl paramConstraintValidatorContextImpl, String template, PathImpl path, String deferredNodeName)
  {
    messageTemplate = template;
    propertyPath = path;
    this.deferredNodeName = deferredNodeName;
  }
  
  public ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder inIterable()
  {
    propertyPath.getLeafNode().setInIterable(true);
    return new ConstraintValidatorContextImpl.InIterablePropertiesBuilderImpl(this$0, messageTemplate, propertyPath, deferredNodeName);
  }
  
  public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name)
  {
    addDeferredNode();
    deferredNodeName = name;
    return this;
  }
  
  public ConstraintValidatorContext addConstraintViolation()
  {
    addDeferredNode();
    ConstraintValidatorContextImpl.access$000(this$0).add(new MessageAndPath(messageTemplate, propertyPath));
    return this$0;
  }
  
  private void addDeferredNode()
  {
    if (deferredNodeName != null)
    {
      NodeImpl node = new NodeImpl(deferredNodeName);
      propertyPath.addNode(node);
    }
  }
}

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

import java.util.List;
import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder;

class ConstraintValidatorContextImpl$InIterablePropertiesBuilderImpl
  implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder
{
  String messageTemplate;
  PathImpl propertyPath;
  String deferredNodeName;
  
  ConstraintValidatorContextImpl$InIterablePropertiesBuilderImpl(ConstraintValidatorContextImpl paramConstraintValidatorContextImpl, String template, PathImpl path, String deferredNodeName)
  {
    messageTemplate = template;
    propertyPath = path;
    this.deferredNodeName = deferredNodeName;
  }
  
  public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext atKey(Object key)
  {
    propertyPath.getLeafNode().setKey(key);
    addDeferredNode();
    return new ConstraintValidatorContextImpl.NodeBuilderImpl(this$0, messageTemplate, propertyPath);
  }
  
  public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext atIndex(Integer index)
  {
    propertyPath.getLeafNode().setIndex(index);
    addDeferredNode();
    return new ConstraintValidatorContextImpl.NodeBuilderImpl(this$0, messageTemplate, propertyPath);
  }
  
  public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name)
  {
    addDeferredNode();
    return new ConstraintValidatorContextImpl.InIterableNodeBuilderImpl(this$0, messageTemplate, propertyPath, name);
  }
  
  public ConstraintValidatorContext addConstraintViolation()
  {
    addDeferredNode();
    ConstraintValidatorContextImpl.access$000(this$0).add(new MessageAndPath(messageTemplate, propertyPath));
    return this$0;
  }
  
  private void addDeferredNode()
  {
    if (deferredNodeName != null)
    {
      NodeImpl node = new NodeImpl(deferredNodeName);
      propertyPath.addNode(node);
    }
  }
}

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

import java.util.List;
import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext;

class ConstraintValidatorContextImpl$NodeBuilderImpl
  implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext
{
  String messageTemplate;
  PathImpl propertyPath;
  
  ConstraintValidatorContextImpl$NodeBuilderImpl(ConstraintValidatorContextImpl paramConstraintValidatorContextImpl, String template, PathImpl path)
  {
    messageTemplate = template;
    propertyPath = path;
  }
  
  public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name)
  {
    return new ConstraintValidatorContextImpl.InIterableNodeBuilderImpl(this$0, messageTemplate, propertyPath, name);
  }
  
  public ConstraintValidatorContext addConstraintViolation()
  {
    ConstraintValidatorContextImpl.access$000(this$0).add(new MessageAndPath(messageTemplate, propertyPath));
    return this$0;
  }
}

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

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder;
import javax.validation.ValidationException;
import javax.validation.metadata.ConstraintDescriptor;

public class ConstraintValidatorContextImpl
  implements ConstraintValidatorContext
{
  private final List<MessageAndPath> messageAndPaths = new ArrayList(3);
  private final PathImpl propertyPath;
  private final ConstraintDescriptor<?> constraintDescriptor;
  private boolean defaultDisabled;
  
  public ConstraintValidatorContextImpl(PathImpl propertyPath, ConstraintDescriptor<?> constraintDescriptor)
  {
    this.propertyPath = propertyPath;
    this.constraintDescriptor = constraintDescriptor;
  }
  
  public void disableDefaultConstraintViolation()
  {
    defaultDisabled = true;
  }
  
  public String getDefaultConstraintMessageTemplate()
  {
    return (String)constraintDescriptor.getAttributes().get("message");
  }
  
  public ConstraintValidatorContext.ConstraintViolationBuilder buildConstraintViolationWithTemplate(String messageTemplate)
  {
    return new ErrorBuilderImpl(messageTemplate, propertyPath);
  }
  
  public ConstraintDescriptor<?> getConstraintDescriptor()
  {
    return constraintDescriptor;
  }
  
  public List<MessageAndPath> getMessageAndPathList()
  {
    if ((defaultDisabled) && (messageAndPaths.size() == 0)) {
      throw new ValidationException("At least one custom message must be created if the default error message gets disabled.");
    }
    List<MessageAndPath> returnedMessageAndPaths = new ArrayList(messageAndPaths);
    if (!defaultDisabled) {
      returnedMessageAndPaths.add(new MessageAndPath(getDefaultConstraintMessageTemplate(), propertyPath));
    }
    return returnedMessageAndPaths;
  }
  
  class ErrorBuilderImpl
    implements ConstraintValidatorContext.ConstraintViolationBuilder
  {
    String messageTemplate;
    PathImpl propertyPath;
    
    ErrorBuilderImpl(String template, PathImpl path)
    {
      messageTemplate = template;
      propertyPath = path;
    }
    
    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext addNode(String name)
    {
      PathImpl path;
      PathImpl path;
      if (propertyPath.isRootPath())
      {
        path = PathImpl.createNewPath(name);
      }
      else
      {
        path = PathImpl.createShallowCopy(propertyPath);
        path.addNode(new NodeImpl(name));
      }
      return new ConstraintValidatorContextImpl.NodeBuilderImpl(ConstraintValidatorContextImpl.this, messageTemplate, path);
    }
    
    public ConstraintValidatorContext addConstraintViolation()
    {
      messageAndPaths.add(new MessageAndPath(messageTemplate, propertyPath));
      return ConstraintValidatorContextImpl.this;
    }
  }
  
  class NodeBuilderImpl
    implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext
  {
    String messageTemplate;
    PathImpl propertyPath;
    
    NodeBuilderImpl(String template, PathImpl path)
    {
      messageTemplate = template;
      propertyPath = path;
    }
    
    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name)
    {
      return new ConstraintValidatorContextImpl.InIterableNodeBuilderImpl(ConstraintValidatorContextImpl.this, messageTemplate, propertyPath, name);
    }
    
    public ConstraintValidatorContext addConstraintViolation()
    {
      messageAndPaths.add(new MessageAndPath(messageTemplate, propertyPath));
      return ConstraintValidatorContextImpl.this;
    }
  }
  
  class InIterableNodeBuilderImpl
    implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext
  {
    String messageTemplate;
    PathImpl propertyPath;
    String deferredNodeName;
    
    InIterableNodeBuilderImpl(String template, PathImpl path, String deferredNodeName)
    {
      messageTemplate = template;
      propertyPath = path;
      this.deferredNodeName = deferredNodeName;
    }
    
    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder inIterable()
    {
      propertyPath.getLeafNode().setInIterable(true);
      return new ConstraintValidatorContextImpl.InIterablePropertiesBuilderImpl(ConstraintValidatorContextImpl.this, messageTemplate, propertyPath, deferredNodeName);
    }
    
    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name)
    {
      addDeferredNode();
      deferredNodeName = name;
      return this;
    }
    
    public ConstraintValidatorContext addConstraintViolation()
    {
      addDeferredNode();
      messageAndPaths.add(new MessageAndPath(messageTemplate, propertyPath));
      return ConstraintValidatorContextImpl.this;
    }
    
    private void addDeferredNode()
    {
      if (deferredNodeName != null)
      {
        NodeImpl node = new NodeImpl(deferredNodeName);
        propertyPath.addNode(node);
      }
    }
  }
  
  class InIterablePropertiesBuilderImpl
    implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder
  {
    String messageTemplate;
    PathImpl propertyPath;
    String deferredNodeName;
    
    InIterablePropertiesBuilderImpl(String template, PathImpl path, String deferredNodeName)
    {
      messageTemplate = template;
      propertyPath = path;
      this.deferredNodeName = deferredNodeName;
    }
    
    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext atKey(Object key)
    {
      propertyPath.getLeafNode().setKey(key);
      addDeferredNode();
      return new ConstraintValidatorContextImpl.NodeBuilderImpl(ConstraintValidatorContextImpl.this, messageTemplate, propertyPath);
    }
    
    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext atIndex(Integer index)
    {
      propertyPath.getLeafNode().setIndex(index);
      addDeferredNode();
      return new ConstraintValidatorContextImpl.NodeBuilderImpl(ConstraintValidatorContextImpl.this, messageTemplate, propertyPath);
    }
    
    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name)
    {
      addDeferredNode();
      return new ConstraintValidatorContextImpl.InIterableNodeBuilderImpl(ConstraintValidatorContextImpl.this, messageTemplate, propertyPath, name);
    }
    
    public ConstraintValidatorContext addConstraintViolation()
    {
      addDeferredNode();
      messageAndPaths.add(new MessageAndPath(messageTemplate, propertyPath));
      return ConstraintValidatorContextImpl.this;
    }
    
    private void addDeferredNode()
    {
      if (deferredNodeName != null)
      {
        NodeImpl node = new NodeImpl(deferredNodeName);
        propertyPath.addNode(node);
      }
    }
  }
}

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

import java.security.AccessController;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
import org.hibernate.validator.util.NewInstance;

public class ConstraintValidatorFactoryImpl
  implements ConstraintValidatorFactory
{
  public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key)
  {
    NewInstance<T> newInstance = NewInstance.action(key, "");
    if (System.getSecurityManager() != null) {
      return (ConstraintValidator)AccessController.doPrivileged(newInstance);
    }
    return (ConstraintValidator)newInstance.run();
  }
}

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

import java.io.Serializable;
import java.lang.annotation.ElementType;
import javax.validation.ConstraintViolation;
import javax.validation.Path;
import javax.validation.metadata.ConstraintDescriptor;

public class ConstraintViolationImpl<T>
  implements ConstraintViolation<T>, Serializable
{
  private final String interpolatedMessage;
  private final T rootBean;
  private final Object value;
  private final Path propertyPath;
  private final Object leafBeanInstance;
  private final ConstraintDescriptor constraintDescriptor;
  private final String messageTemplate;
  private final Class<T> rootBeanClass;
  private final ElementType elementType;
  
  public ConstraintViolationImpl(String messageTemplate, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor constraintDescriptor, ElementType elementType)
  {
    this.messageTemplate = messageTemplate;
    this.interpolatedMessage = interpolatedMessage;
    this.rootBean = rootBean;
    this.value = value;
    this.propertyPath = propertyPath;
    this.leafBeanInstance = leafBeanInstance;
    this.constraintDescriptor = constraintDescriptor;
    this.rootBeanClass = rootBeanClass;
    this.elementType = elementType;
  }
  
  public String getMessage()
  {
    return interpolatedMessage;
  }
  
  public String getMessageTemplate()
  {
    return messageTemplate;
  }
  
  public T getRootBean()
  {
    return (T)rootBean;
  }
  
  public Class<T> getRootBeanClass()
  {
    return rootBeanClass;
  }
  
  public Object getLeafBean()
  {
    return leafBeanInstance;
  }
  
  public Object getInvalidValue()
  {
    return value;
  }
  
  public Path getPropertyPath()
  {
    return propertyPath;
  }
  
  public ConstraintDescriptor getConstraintDescriptor()
  {
    return constraintDescriptor;
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if (!(o instanceof ConstraintViolationImpl)) {
      return false;
    }
    ConstraintViolationImpl that = (ConstraintViolationImpl)o;
    if (interpolatedMessage != null ? !interpolatedMessage.equals(interpolatedMessage) : interpolatedMessage != null) {
      return false;
    }
    if (propertyPath != null ? !propertyPath.equals(propertyPath) : propertyPath != null) {
      return false;
    }
    if (rootBean != null ? !rootBean.equals(rootBean) : rootBean != null) {
      return false;
    }
    if (leafBeanInstance != null ? !leafBeanInstance.equals(leafBeanInstance) : leafBeanInstance != null) {
      return false;
    }
    if (elementType != null ? !elementType.equals(elementType) : elementType != null) {
      return false;
    }
    if (value != null ? !value.equals(value) : value != null) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    int result = interpolatedMessage != null ? interpolatedMessage.hashCode() : 0;
    result = 31 * result + (propertyPath != null ? propertyPath.hashCode() : 0);
    result = 31 * result + (rootBean != null ? rootBean.hashCode() : 0);
    result = 31 * result + (leafBeanInstance != null ? leafBeanInstance.hashCode() : 0);
    result = 31 * result + (value != null ? value.hashCode() : 0);
    result = 31 * result + (elementType != null ? elementType.hashCode() : 0);
    return result;
  }
  
  public String toString()
  {
    StringBuilder sb = new StringBuilder();
    sb.append("ConstraintViolationImpl");
    sb.append("{interpolatedMessage='").append(interpolatedMessage).append('\'');
    sb.append(", propertyPath=").append(propertyPath);
    sb.append(", rootBeanClass=").append(rootBeanClass);
    sb.append(", messageTemplate='").append(messageTemplate).append('\'');
    sb.append('}');
    return sb.toString();
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.engine.ConstraintViolationImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hibernate.validator.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.validator.util.IdentitySet;

public class GlobalExecutionContext<T>
{
  private final T rootBean;
  private final Class<T> rootBeanClass;
  private final Map<Class<?>, IdentitySet> processedObjects;
  private final Map<Object, Set<PathImpl>> processedPaths;
  private final List<ConstraintViolation<T>> failingConstraintViolations;
  private boolean allowOneValidationPerPath = true;
  private final MessageInterpolator messageInterpolator;
  private final ConstraintValidatorFactory constraintValidatorFactory;
  private final TraversableResolver traversableResolver;
  
  public static <T> GlobalExecutionContext<T> getContextForValidate(T object, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver)
  {
    Class<T> rootBeanClass = object.getClass();
    return new GlobalExecutionContext(rootBeanClass, object, messageInterpolator, constraintValidatorFactory, traversableResolver);
  }
  
  public static <T> GlobalExecutionContext<T> getContextForValidateProperty(T rootBean, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver)
  {
    Class<T> rootBeanClass = rootBean.getClass();
    return new GlobalExecutionContext(rootBeanClass, rootBean, messageInterpolator, constraintValidatorFactory, traversableResolver);
  }
  
  public static <T> GlobalExecutionContext<T> getContextForValidateValue(Class<T> rootBeanClass, MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, TraversableResolver traversableResolver)
  {
    return new GlobalExecutionContext(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();
    processedPaths = new IdentityHashMap();
    failingConstraintViolations = new ArrayList();
  }
  
  public T getRootBean()
  {
    return (T)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, MessageAndPath messageAndPath, ConstraintDescriptor<?> descriptor)
  {
    String messageTemplate = messageAndPath.getMessage();
    String interpolatedMessage = messageInterpolator.interpolate(messageTemplate, new MessageInterpolatorContext(descriptor, localContext.getCurrentBean()));
    
    return new ConstraintViolationImpl(messageTemplate, interpolatedMessage, getRootBeanClass(), getRootBean(), localContext.getCurrentBean(), localContext.getCurrentValidatedValue(), messageAndPath.getPath(), descriptor, localContext.getElementType());
  }
  
  public <U, V> List<ConstraintViolationImpl<T>> createConstraintViolations(LocalExecutionContext<U, V> localContext, ConstraintValidatorContextImpl constraintValidatorContext)
  {
    List<ConstraintViolationImpl<T>> constraintViolations = new ArrayList();
    for (MessageAndPath messageAndPath : constraintValidatorContext.getMessageAndPathList())
    {
      ConstraintViolationImpl<T> violation = createConstraintViolation(localContext, messageAndPath, constraintValidatorContext.getConstraintDescriptor());
      
      constraintViolations.add(violation);
    }
    return constraintViolations;
  }
  
  public ConstraintValidatorFactory getConstraintValidatorFactory()
  {
    return constraintValidatorFactory;
  }
  
  public boolean isAlreadyValidated(Object value, Class<?> group, PathImpl path)
  {
    boolean 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 = (Set)processedPaths.get(value);
    if (pathSet == null) {
      return false;
    }
    for (PathImpl p : pathSet) {
      if ((p.isRootPath()) || (path.isRootPath()) || (p.isSubPathOf(path)) || (path.isSubPathOf(p))) {
        return true;
      }
    }
    return false;
  }
  
  private boolean isAlreadyValidatedForCurrentGroup(Object value, Class<?> group)
  {
    IdentitySet objectsProcessedInCurrentGroups = (IdentitySet)processedObjects.get(group);
    return (objectsProcessedInCurrentGroups != null) && (objectsProcessedInCurrentGroups.contains(value));
  }
  
  private void markProcessedForCurrentPath(Object value, PathImpl path)
  {
    PathImpl parentPath = path.getPathWithoutLeafNode();
    if (parentPath == null) {
      parentPath = PathImpl.createNewPath(null);
    }
    if (processedPaths.containsKey(value))
    {
      ((Set)processedPaths.get(value)).add(parentPath);
    }
    else
    {
      Set<PathImpl> set = new HashSet();
      set.add(parentPath);
      processedPaths.put(value, set);
    }
  }
  
  private void markProcessForCurrentGroup(Object value, Class<?> group)
  {
    if (processedObjects.containsKey(group))
    {
      ((IdentitySet)processedObjects.get(group)).add(value);
    }
    else
    {
      IdentitySet set = new IdentitySet();
      set.add(value);
      processedObjects.put(group, set);
    }
  }
}

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

import javax.validation.groups.Default;

public class Group
{
  private Class<?> group;
  private Class<?> sequence;
  
  public Group(Class<?> group)
  {
    this(group, null);
  }
  
  public Group(Class<?> group, Class<?> sequence)
  {
    this.group = group;
    this.sequence = sequence;
  }
  
  public Class<?> getGroup()
  {
    return group;
  }
  
  public Class<?> getSequence()
  {
    return sequence;
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if ((o == null) || (getClass() != o.getClass())) {
      return false;
    }
    Group group1 = (Group)o;
    if (group != null ? !group.equals(group) : group != null) {
      return false;
    }
    return true;
  }
  
  public boolean isDefaultGroup()
  {
    return getGroup().getName().equals(Default.class.getName());
  }
  
  public int hashCode()
  {
    return group != null ? group.hashCode() : 0;
  }
  
  public String toString()
  {
    return "Group{groups=" + group + ", sequence=" + sequence + '}';
  }
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.validation.GroupDefinitionException;
import javax.validation.groups.Default;

public class GroupChain
{
  private List<Group> groupList = new ArrayList();
  private Map<Class<?>, List<Group>> sequenceMap = new HashMap();
  
  public Iterator<Group> getGroupIterator()
  {
    return groupList.iterator();
  }
  
  public Iterator<List<Group>> getSequenceIterator()
  {
    return sequenceMap.values().iterator();
  }
  
  void insertGroup(Group group)
  {
    if (!groupList.contains(group)) {
      groupList.add(group);
    }
  }
  
  void insertSequence(List<Group> groups)
  {
    if ((groups == null) || (groups.size() == 0)) {
      return;
    }
    if (!sequenceMap.containsValue(
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