wms-jax.validation

groups)) {
      sequenceMap.put(((Group)groups.get(0)).getSequence(), groups);
    }
  }
  
  public String toString()
  {
    return "GroupChain{groupList=" + groupList + ", sequenceMap=" + sequenceMap + '}';
  }
  
  public void assertDefaultGroupSequenceIsExpandable(List<Class<?>> defaultGroupSequence)
  {
    for (Map.Entry<Class<?>, List<Group>> entry : sequenceMap.entrySet())
    {
      Class<?> sequence = (Class)entry.getKey();
      List<Group> groupList = (List)entry.getValue();
      List<Group> defaultGroupList = buildTempGroupList(defaultGroupSequence, sequence);
      int defaultGroupIndex = containsDefaultGroupAtIndex(sequence, groupList);
      if (defaultGroupIndex != -1) {
        ensureDefaultGroupSequenceIsExpandable(groupList, defaultGroupList, defaultGroupIndex);
      }
    }
  }
  
  private void ensureDefaultGroupSequenceIsExpandable(List<Group> groupList, List<Group> defaultGroupList, int defaultGroupIndex)
  {
    for (int i = 0; i < defaultGroupList.size(); i++)
    {
      Group group = (Group)defaultGroupList.get(i);
      if (!group.getGroup().equals(Default.class))
      {
        int index = groupList.indexOf(group);
        if (index != -1) {
          if (((i != 0) || (index != defaultGroupIndex - 1)) && ((i != defaultGroupList.size() - 1) || (index != defaultGroupIndex + 1))) {
            throw new GroupDefinitionException("Unable to expand default group list" + defaultGroupList + " into sequence " + groupList);
          }
        }
      }
    }
  }
  
  private int containsDefaultGroupAtIndex(Class<?> sequence, List<Group> groupList)
  {
    Group defaultGroup = new Group(Default.class, sequence);
    return groupList.indexOf(defaultGroup);
  }
  
  private List<Group> buildTempGroupList(List<Class<?>> defaultGroupSequence, Class<?> sequence)
  {
    List<Group> groupList = new ArrayList();
    for (Class<?> clazz : defaultGroupSequence)
    {
      Group g = new Group(clazz, sequence);
      groupList.add(g);
    }
    return groupList;
  }
}

/* Location:
 * Qualified Name:     org.hibernate.validator.engine.groups.GroupChain
 * 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.List;
import java.util.Map;
import javax.validation.GroupDefinitionException;
import javax.validation.GroupSequence;
import javax.validation.ValidationException;

public class GroupChainGenerator
{
  private final Map<Class<?>, List<Group>> resolvedSequences = new HashMap();
  
  public GroupChain getGroupChainFor(Collection<Class<?>> groups)
  {
    if ((groups == null) || (groups.size() == 0)) {
      throw new IllegalArgumentException("At least one groups has to be specified.");
    }
    for (Class<?> clazz : groups) {
      if (!clazz.isInterface()) {
        throw new ValidationException("A group has to be an interface. " + clazz.getName() + " is not.");
      }
    }
    GroupChain chain = new GroupChain();
    for (Class<?> clazz : groups) {
      if (clazz.getAnnotation(GroupSequence.class) == null)
      {
        Group group = new Group(clazz);
        chain.insertGroup(group);
        insertInheritedGroups(clazz, chain);
      }
      else
      {
        insertSequence(clazz, chain);
      }
    }
    return chain;
  }
  
  private void insertInheritedGroups(Class<?> clazz, GroupChain chain)
  {
    for (Class<?> extendedInterface : clazz.getInterfaces())
    {
      Group group = new Group(extendedInterface);
      chain.insertGroup(group);
      insertInheritedGroups(extendedInterface, chain);
    }
  }
  
  private void insertSequence(Class<?> clazz, GroupChain chain)
  {
    List<Group> sequence;
    List<Group> sequence;
    if (resolvedSequences.containsKey(clazz)) {
      sequence = (List)resolvedSequences.get(clazz);
    } else {
      sequence = resolveSequence(clazz, new ArrayList());
    }
    chain.insertSequence(sequence);
  }
  
  private List<Group> resolveSequence(Class<?> group, List<Class<?>> processedSequences)
  {
    if (processedSequences.contains(group)) {
      throw new GroupDefinitionException("Cyclic dependency in groups definition");
    }
    processedSequences.add(group);
    
    List<Group> resolvedGroupSequence = new ArrayList();
    GroupSequence sequenceAnnotation = (GroupSequence)group.getAnnotation(GroupSequence.class);
    Class<?>[] sequenceArray = sequenceAnnotation.value();
    for (Class<?> clazz : sequenceArray) {
      if (clazz.getAnnotation(GroupSequence.class) == null)
      {
        resolvedGroupSequence.add(new Group(clazz, group));
      }
      else
      {
        List<Group> tmpSequence = resolveSequence(clazz, processedSequences);
        addTmpSequence(resolvedGroupSequence, tmpSequence);
      }
    }
    resolvedSequences.put(group, resolvedGroupSequence);
    return resolvedGroupSequence;
  }
  
  private void addTmpSequence(List<Group> resolvedGroupSequence, List<Group> tmpSequence)
  {
    for (Group tmpGroup : tmpSequence)
    {
      if ((resolvedGroupSequence.contains(tmpGroup)) && (resolvedGroupSequence.indexOf(tmpGroup) < resolvedGroupSequence.size() - 1)) {
        throw new GroupDefinitionException("Unable to expand group sequence.");
      }
      resolvedGroupSequence.add(tmpGroup);
    }
  }
}

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

import java.lang.annotation.ElementType;
import javax.validation.groups.Default;

public class LocalExecutionContext<T, V>
{
  private final T currentBean;
  private final Class<T> currentBeanType;
  private PathImpl propertyPath;
  private Class<?> currentGroup;
  private V currentValue;
  private ElementType elementType;
  
  public static <T, V> LocalExecutionContext<T, V> getLocalExecutionContext(T value)
  {
    Class<T> rootBeanClass = value.getClass();
    return new LocalExecutionContext(value, rootBeanClass);
  }
  
  public static <T, V> LocalExecutionContext<T, V> getLocalExecutionContext(Class<T> type)
  {
    return new LocalExecutionContext(null, type);
  }
  
  public LocalExecutionContext(T currentBean, Class<T> currentBeanType)
  {
    this.currentBean = currentBean;
    this.currentBeanType = currentBeanType;
  }
  
  public PathImpl getPropertyPath()
  {
    return propertyPath;
  }
  
  public Class<?> getCurrentGroup()
  {
    return currentGroup;
  }
  
  public T getCurrentBean()
  {
    return (T)currentBean;
  }
  
  public Class<T> getCurrentBeanType()
  {
    return currentBeanType;
  }
  
  public V getCurrentValidatedValue()
  {
    return (V)currentValue;
  }
  
  public void setPropertyPath(PathImpl propertyPath)
  {
    this.propertyPath = propertyPath;
  }
  
  public void setCurrentGroup(Class<?> currentGroup)
  {
    this.currentGroup = currentGroup;
  }
  
  public void setCurrentValidatedValue(V currentValue)
  {
    this.currentValue = currentValue;
  }
  
  public void markCurrentPropertyAsIterable()
  {
    propertyPath.getLeafNode().setInIterable(true);
  }
  
  public boolean validatingDefault()
  {
    return (getCurrentGroup() != null) && (getCurrentGroup().getName().equals(Default.class.getName()));
  }
  
  public ElementType getElementType()
  {
    return elementType;
  }
  
  public void setElementType(ElementType elementType)
  {
    this.elementType = elementType;
  }
  
  public String toString()
  {
    StringBuilder sb = new StringBuilder();
    sb.append("LocalExecutionContext");
    sb.append("{currentBean=").append(currentBean);
    sb.append(", currentBeanType=").append(currentBeanType);
    sb.append(", propertyPath=").append(propertyPath);
    sb.append(", currentGroup=").append(currentGroup);
    sb.append(", currentValue=").append(currentValue);
    sb.append(", elementType=").append(elementType);
    sb.append('}');
    return sb.toString();
  }
}

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

import javax.validation.Path;

public class MessageAndPath
{
  private final String message;
  private final Path propertyPath;
  
  public MessageAndPath(String message, Path property)
  {
    this.message = message;
    propertyPath = property;
  }
  
  public String getMessage()
  {
    return message;
  }
  
  public Path getPath()
  {
    return propertyPath;
  }
}

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

import javax.validation.MessageInterpolator.Context;
import javax.validation.metadata.ConstraintDescriptor;

public class MessageInterpolatorContext
  implements MessageInterpolator.Context
{
  private final ConstraintDescriptor<?> constraintDescriptor;
  private final Object validatedValue;
  
  public MessageInterpolatorContext(ConstraintDescriptor<?> constraintDescriptor, Object validatedValue)
  {
    this.constraintDescriptor = constraintDescriptor;
    this.validatedValue = validatedValue;
  }
  
  public ConstraintDescriptor<?> getConstraintDescriptor()
  {
    return constraintDescriptor;
  }
  
  public Object getValidatedValue()
  {
    return validatedValue;
  }
}

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

import java.io.Serializable;
import javax.validation.Path.Node;

public class NodeImpl
  implements Path.Node, Serializable
{
  private static final long serialVersionUID = 2075466571633860499L;
  private static final String INDEX_OPEN = "[";
  private static final String INDEX_CLOSE = "]";
  private final String name;
  private boolean isInIterable;
  private Integer index;
  private Object key;
  
  public NodeImpl(String name)
  {
    this.name = name;
  }
  
  NodeImpl(Path.Node node)
  {
    name = node.getName();
    isInIterable = node.isInIterable();
    index = node.getIndex();
    key = node.getKey();
  }
  
  public String getName()
  {
    return name;
  }
  
  public boolean isInIterable()
  {
    return isInIterable;
  }
  
  public void setInIterable(boolean inIterable)
  {
    isInIterable = inIterable;
  }
  
  public Integer getIndex()
  {
    return index;
  }
  
  public void setIndex(Integer index)
  {
    isInIterable = true;
    this.index = index;
  }
  
  public Object getKey()
  {
    return key;
  }
  
  public void setKey(Object key)
  {
    isInIterable = true;
    this.key = key;
  }
  
  public String toString()
  {
    StringBuilder builder = new StringBuilder(name == null ? "" : name);
    if (isInIterable)
    {
      builder.append("[");
      if (getIndex() != null) {
        builder.append(getIndex());
      } else if (getKey() != null) {
        builder.append(getKey());
      }
      builder.append("]");
    }
    return builder.toString();
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if ((o == null) || (getClass() != o.getClass())) {
      return false;
    }
    NodeImpl node = (NodeImpl)o;
    if (isInIterable != isInIterable) {
      return false;
    }
    if (index != null ? !index.equals(index) : index != null) {
      return false;
    }
    if (key != null ? !key.equals(key) : key != null) {
      return false;
    }
    if (name != null ? !name.equals(name) : name != null) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    int result = name != null ? name.hashCode() : 0;
    result = 31 * result + (isInIterable ? 1 : 0);
    result = 31 * result + (index != null ? index.hashCode() : 0);
    result = 31 * result + (key != null ? key.hashCode() : 0);
    return result;
  }
}

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

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.validation.Path;
import javax.validation.Path.Node;

public class PathImpl
  implements Path, Serializable
{
  private static final long serialVersionUID = 7564511574909882392L;
  private static final Pattern pathPattern = Pattern.compile("(\\w+)(\\[(\\w*)\\])?(\\.(.*))*");
  private static final String PROPERTY_PATH_SEPERATOR = ".";
  private final List<Path.Node> nodeList;
  
  public static PathImpl createPathFromString(String propertyPath)
  {
    if (propertyPath == null) {
      throw new IllegalArgumentException("null is not allowed as property path.");
    }
    if (propertyPath.length() == 0) {
      return createNewPath(null);
    }
    return parseProperty(propertyPath);
  }
  
  public static PathImpl createNewPath(String name)
  {
    PathImpl path = new PathImpl();
    NodeImpl node = new NodeImpl(name);
    path.addNode(node);
    return path;
  }
  
  public static PathImpl createShallowCopy(Path path)
  {
    return path == null ? null : new PathImpl(path);
  }
  
  private PathImpl(Path path)
  {
    nodeList = new ArrayList();
    for (Object aPath : path) {
      nodeList.add(new NodeImpl((Path.Node)aPath));
    }
  }
  
  private PathImpl()
  {
    nodeList = new ArrayList();
  }
  
  private PathImpl(List<Path.Node> nodeList)
  {
    this.nodeList = new ArrayList();
    for (Path.Node node : nodeList) {
      this.nodeList.add(new NodeImpl(node));
    }
  }
  
  public boolean isRootPath()
  {
    return (nodeList.size() == 1) && (((Path.Node)nodeList.get(0)).getName() == null);
  }
  
  public PathImpl getPathWithoutLeafNode()
  {
    List<Path.Node> nodes = new ArrayList(nodeList);
    PathImpl path = null;
    if (nodes.size() > 1)
    {
      nodes.remove(nodes.size() - 1);
      path = new PathImpl(nodes);
    }
    return path;
  }
  
  public void addNode(Path.Node node)
  {
    nodeList.add(node);
  }
  
  public Path.Node removeLeafNode()
  {
    if (nodeList.size() == 0) {
      throw new IllegalStateException("No nodes in path!");
    }
    if (nodeList.size() == 1) {
      throw new IllegalStateException("Root node cannot be removed!");
    }
    return (Path.Node)nodeList.remove(nodeList.size() - 1);
  }
  
  public NodeImpl getLeafNode()
  {
    if (nodeList.size() == 0) {
      throw new IllegalStateException("No nodes in path!");
    }
    return (NodeImpl)nodeList.get(nodeList.size() - 1);
  }
  
  public Iterator<Path.Node> iterator()
  {
    return nodeList.iterator();
  }
  
  public boolean isSubPathOf(Path path)
  {
    Iterator<Path.Node> pathIter = path.iterator();
    Iterator<Path.Node> thisIter = iterator();
    while (pathIter.hasNext())
    {
      Path.Node pathNode = (Path.Node)pathIter.next();
      if (!thisIter.hasNext()) {
        return false;
      }
      Path.Node thisNode = (Path.Node)thisIter.next();
      if (!thisNode.equals(pathNode)) {
        return false;
      }
    }
    return true;
  }
  
  public String toString()
  {
    StringBuilder builder = new StringBuilder();
    Iterator<Path.Node> iter = iterator();
    while (iter.hasNext())
    {
      Path.Node node = (Path.Node)iter.next();
      builder.append(node.toString());
      if (iter.hasNext()) {
        builder.append(".");
      }
    }
    return builder.toString();
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if ((o == null) || (getClass() != o.getClass())) {
      return false;
    }
    PathImpl path = (PathImpl)o;
    if ((nodeList != null) && (!nodeList.equals(nodeList))) {
      return false;
    }
    if ((nodeList == null) && (nodeList != null)) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    return nodeList != null ? nodeList.hashCode() : 0;
  }
  
  private static PathImpl parseProperty(String property)
  {
    PathImpl path = new PathImpl();
    String tmp = property;
    do
    {
      Matcher matcher = pathPattern.matcher(tmp);
      if (matcher.matches())
      {
        String value = matcher.group(1);
        String indexed = matcher.group(2);
        String index = matcher.group(3);
        NodeImpl node = new NodeImpl(value);
        if (indexed != null) {
          node.setInIterable(true);
        }
        if ((index != null) && (index.length() > 0)) {
          try
          {
            Integer i = Integer.valueOf(Integer.parseInt(index));
            node.setIndex(i);
          }
          catch (NumberFormatException e)
          {
            node.setKey(index);
          }
        }
        path.addNode(node);
        tmp = matcher.group(5);
      }
      else
      {
        throw new IllegalArgumentException("Unable to parse property path " + property);
      }
    } while (tmp != null);
    return path;
  }
}

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

import java.lang.annotation.ElementType;
import java.security.AccessController;
import javax.validation.Path;
import javax.validation.Path.Node;
import javax.validation.TraversableResolver;
import javax.validation.ValidationException;
import org.hibernate.validator.util.LoadClass;
import org.hibernate.validator.util.LoggerFactory;
import org.hibernate.validator.util.NewInstance;
import org.slf4j.Logger;

public class DefaultTraversableResolver
  implements TraversableResolver
{
  private static final Logger log = ;
  private static final String PERSISTENCE_UTIL_CLASS_NAME = "javax.persistence.PersistenceUtil";
  private static final String JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME = "org.hibernate.validator.engine.resolver.JPATraversableResolver";
  private TraversableResolver jpaTraversableResolver;
  
  public DefaultTraversableResolver()
  {
    detectJPA();
  }
  
  private void detectJPA()
  {
    try
    {
      loadClass("javax.persistence.PersistenceUtil", getClass());
      log.debug("Found {} on classpath.", "javax.persistence.PersistenceUtil");
    }
    catch (ValidationException e)
    {
      log.debug("Cannot find {} on classpath. All properties will per default be traversable.", "javax.persistence.PersistenceUtil");
      
      return;
    }
    try
    {
      Class<? extends TraversableResolver> jpaAwareResolverClass = loadClass("org.hibernate.validator.engine.resolver.JPATraversableResolver", getClass());
      
      NewInstance<? extends TraversableResolver> newInstance = NewInstance.action(jpaAwareResolverClass, "");
      if (System.getSecurityManager() != null) {
        jpaTraversableResolver = ((TraversableResolver)AccessController.doPrivileged(newInstance));
      } else {
        jpaTraversableResolver = ((TraversableResolver)newInstance.run());
      }
      log.info("Instantiated an instance of {}.", "org.hibernate.validator.engine.resolver.JPATraversableResolver");
    }
    catch (ValidationException e)
    {
      log.info("Unable to load or instanciate JPA aware resolver {}. All properties will per default be traversable.", "org.hibernate.validator.engine.resolver.JPATraversableResolver");
    }
  }
  
  private Class<?> loadClass(String className, Class<?> caller)
  {
    LoadClass action = LoadClass.action(className, caller);
    if (System.getSecurityManager() != null) {
      return (Class)AccessController.doPrivileged(action);
    }
    return action.run();
  }
  
  public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType)
  {
    return (jpaTraversableResolver == null) || (jpaTraversableResolver.isReachable(traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType));
  }
  
  public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType)
  {
    return (jpaTraversableResolver == null) || (jpaTraversableResolver.isCascadable(traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType));
  }
}

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

import java.lang.annotation.ElementType;
import javax.persistence.Persistence;
import javax.persistence.PersistenceUtil;
import javax.validation.Path;
import javax.validation.Path.Node;
import javax.validation.TraversableResolver;

public class JPATraversableResolver
  implements TraversableResolver
{
  public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType)
  {
    return (traversableObject == null) || (Persistence.getPersistenceUtil().isLoaded(traversableObject, traversableProperty.getName()));
  }
  
  public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType)
  {
    return true;
  }
}

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

class SingleThreadCachedTraversableResolver$1 {}

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

import java.lang.annotation.ElementType;
import javax.validation.Path;
import javax.validation.Path.Node;

class SingleThreadCachedTraversableResolver$TraversableHolder
{
  private final Object traversableObject;
  private final Path.Node traversableProperty;
  private final Class<?> rootBeanType;
  private final Path pathToTraversableObject;
  private final ElementType elementType;
  private final int hashCode;
  private Boolean isReachable;
  private Boolean isCascadable;
  
  private SingleThreadCachedTraversableResolver$TraversableHolder(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType)
  {
    this.traversableObject = traversableObject;
    this.traversableProperty = traversableProperty;
    this.rootBeanType = rootBeanType;
    this.pathToTraversableObject = pathToTraversableObject;
    this.elementType = elementType;
    hashCode = buildHashCode();
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if ((o == null) || (getClass() != o.getClass())) {
      return false;
    }
    TraversableHolder that = (TraversableHolder)o;
    if (elementType != elementType) {
      return false;
    }
    if (!pathToTraversableObject.equals(pathToTraversableObject)) {
      return false;
    }
    if (!rootBeanType.equals(rootBeanType)) {
      return false;
    }
    if (traversableObject != null ? !traversableObject.equals(traversableObject) : traversableObject != null) {
      return false;
    }
    if (!traversableProperty.equals(traversableProperty)) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    return hashCode;
  }
  
  public int buildHashCode()
  {
    int result = traversableObject != null ? traversableObject.hashCode() : 0;
    result = 31 * result + traversableProperty.hashCode();
    result = 31 * result + rootBeanType.hashCode();
    result = 31 * result + pathToTraversableObject.hashCode();
    result = 31 * result + elementType.hashCode();
    return result;
  }
}

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

import java.lang.annotation.ElementType;
import java.util.HashMap;
import java.util.Map;
import javax.validation.Path;
import javax.validation.Path.Node;
import javax.validation.TraversableResolver;

public class SingleThreadCachedTraversableResolver
  implements TraversableResolver
{
  private TraversableResolver delegate;
  private Map<TraversableHolder, TraversableHolder> traversables = new HashMap();
  
  public SingleThreadCachedTraversableResolver(TraversableResolver delegate)
  {
    this.delegate = delegate;
  }
  
  public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType)
  {
    TraversableHolder currentLH = new TraversableHolder(traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType, null);
    
    TraversableHolder cachedLH = (TraversableHolder)traversables.get(currentLH);
    if (cachedLH == null)
    {
      isReachable = Boolean.valueOf(delegate.isReachable(traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType));
      
      traversables.put(currentLH, currentLH);
      cachedLH = currentLH;
    }
    else if (isReachable == null)
    {
      isReachable = Boolean.valueOf(delegate.isReachable(traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType));
    }
    return isReachable.booleanValue();
  }
  
  public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType)
  {
    TraversableHolder currentLH = new TraversableHolder(traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType, null);
    
    TraversableHolder cachedLH = (TraversableHolder)traversables.get(currentLH);
    if (cachedLH == null)
    {
      isCascadable = Boolean.valueOf(delegate.isCascadable(traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType));
      
      traversables.put(currentLH, currentLH);
      cachedLH = currentLH;
    }
    else if (isCascadable == null)
    {
      isCascadable = Boolean.valueOf(delegate.isCascadable(traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType));
    }
    return isCascadable.booleanValue();
  }
  
  private static class TraversableHolder
  {
    private final Object traversableObject;
    private final Path.Node traversableProperty;
    private final Class<?> rootBeanType;
    private final Path pathToTraversableObject;
    private final ElementType elementType;
    private final int hashCode;
    private Boolean isReachable;
    private Boolean isCascadable;
    
    private TraversableHolder(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType)
    {
      this.traversableObject = traversableObject;
      this.traversableProperty = traversableProperty;
      this.rootBeanType = rootBeanType;
      this.pathToTraversableObject = pathToTraversableObject;
      this.elementType = elementType;
      hashCode = buildHashCode();
    }
    
    public boolean equals(Object o)
    {
      if (this == o) {
        return true;
      }
      if ((o == null) || (getClass() != o.getClass())) {
        return false;
      }
      TraversableHolder that = (TraversableHolder)o;
      if (elementType != elementType) {
        return false;
      }
      if (!pathToTraversableObject.equals(pathToTraversableObject)) {
        return false;
      }
      if (!rootBeanType.equals(rootBeanType)) {
        return false;
      }
      if (traversableObject != null ? !traversableObject.equals(traversableObject) : traversableObject != null) {
        return false;
      }
      if (!traversableProperty.equals(traversableProperty)) {
        return false;
      }
      return true;
    }
    
    public int hashCode()
    {
      return hashCode;
    }
    
    public int buildHashCode()
    {
      int result = traversableObject != null ? traversableObject.hashCode() : 0;
      result = 31 * result + traversableProperty.hashCode();
      result = 31 * result + rootBeanType.hashCode();
      result = 31 * result + pathToTraversableObject.hashCode();
      result = 31 * result + elementType.hashCode();
      return result;
    }
  }
}

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

import java.util.Locale;

class ResourceBundleMessageInterpolator$LocalisedMessage
{
  private final String message;
  private final Locale locale;
  
  ResourceBundleMessageInterpolator$LocalisedMessage(String message, Locale locale)
  {
    this.message = message;
    this.locale = locale;
  }
  
  public String getMessage()
  {
    return message;
  }
  
  public Locale getLocale()
  {
    return locale;
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if ((o == null) || (getClass() != o.getClass())) {
      return false;
    }
    LocalisedMessage that = (LocalisedMessage)o;
    if (locale != null ? !locale.equals(locale) : locale != null) {
      return false;
    }
    if (message != null ? !message.equals(message) : message != null) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    int result = message != null ? message.hashCode() : 0;
    result = 31 * result + (locale != null ? locale.hashCode() : 0);
    return result;
  }
}

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

import java.security.AccessController;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.validation.MessageInterpolator;
import javax.validation.MessageInterpolator.Context;
import javax.validation.metadata.ConstraintDescriptor;
import org.hibernate.validator.util.GetClassLoader;
import org.hibernate.validator.util.LoggerFactory;
import org.slf4j.Logger;

public class ResourceBundleMessageInterpolator
  implements MessageInterpolator
{
  private static final String DEFAULT_VALIDATION_MESSAGES = "org.hibernate.validator.ValidationMessages";
  private static final String USER_VALIDATION_MESSAGES = "ValidationMessages";
  private static final Logger log = ;
  private static final Pattern messageParameterPattern = Pattern.compile("(\\{[^\\}]+?\\})");
  private final Locale defaultLocale;
  private final Map<Locale, ResourceBundle> userBundlesMap = new ConcurrentHashMap();
  private final Map<Locale, ResourceBundle> defaultBundlesMap = new ConcurrentHashMap();
  private final Map<LocalisedMessage, String> resolvedMessages = new WeakHashMap();
  
  public ResourceBundleMessageInterpolator()
  {
    this(null);
  }
  
  public ResourceBundleMessageInterpolator(ResourceBundle resourceBundle)
  {
    defaultLocale = Locale.getDefault();
    if (resourceBundle == null)
    {
      ResourceBundle bundle = getFileBasedResourceBundle(defaultLocale);
      if (bundle != null) {
        userBundlesMap.put(defaultLocale, bundle);
      }
    }
    else
    {
      userBundlesMap.put(defaultLocale, resourceBundle);
    }
    defaultBundlesMap.put(defaultLocale, ResourceBundle.getBundle("org.hibernate.validator.ValidationMessages", defaultLocale));
  }
  
  public String interpolate(String message, MessageInterpolator.Context context)
  {
    return interpolateMessage(message, context.getConstraintDescriptor().getAttributes(), defaultLocale);
  }
  
  public String interpolate(String message, MessageInterpolator.Context context, Locale locale)
  {
    return interpolateMessage(message, context.getConstraintDescriptor().getAttributes(), locale);
  }
  
  private String interpolateMessage(String message, Map<String, Object> annotationParameters, Locale locale)
  {
    LocalisedMessage localisedMessage = new LocalisedMessage(message, locale);
    String resolvedMessage = (String)resolvedMessages.get(localisedMessage);
    if (resolvedMessage == null)
    {
      ResourceBundle userResourceBundle = findUserResourceBundle(locale);
      ResourceBundle defaultResourceBundle = findDefaultResourceBundle(locale);
      
      resolvedMessage = message;
      boolean evaluatedDefaultBundleOnce = false;
      for (;;)
      {
        String userBundleResolvedMessage = replaceVariables(resolvedMessage, userResourceBundle, locale, true);
        if ((evaluatedDefaultBundleOnce) && (!hasReplacementTakenPlace(userBundleResolvedMessage, resolvedMessage))) {
          break;
        }
        resolvedMessage = replaceVariables(userBundleResolvedMessage, defaultResourceBundle, locale, false);
        evaluatedDefaultBundleOnce = true;
        resolvedMessages.put(localisedMessage, resolvedMessage);
      }
    }
    resolvedMessage = replaceAnnotationAttributes(resolvedMessage, annotationParameters);
    
    resolvedMessage = resolvedMessage.replace("\\{", "{");
    resolvedMessage = resolvedMessage.replace("\\}", "}");
    resolvedMessage = resolvedMessage.replace("\\\\", "\\");
    return resolvedMessage;
  }
  
  private boolean hasReplacementTakenPlace(String origMessage, String newMessage)
  {
    return !origMessage.equals(newMessage);
  }
  
  private ResourceBundle getFileBasedResourceBundle(Locale locale)
  {
    ResourceBundle rb = null;
    boolean isSecured = System.getSecurityManager() != null;
    GetClassLoader action = GetClassLoader.fromContext();
    ClassLoader classLoader = isSecured ? (ClassLoader)AccessController.doPrivileged(action) : action.run();
    if (classLoader != null) {
      rb = loadBundle(classLoader, locale, "ValidationMessages not found by thread local classloader");
    }
    if (rb == null)
    {
      action = GetClassLoader.fromClass(ResourceBundleMessageInterpolator.class);
      classLoader = isSecured ? (ClassLoader)AccessController.doPrivileged(action) : action.run();
      rb = loadBundle(classLoader, locale, "ValidationMessages not found by validator classloader");
    }
    if (log.isDebugEnabled()) {
      if (rb != null) {
        log.debug("ValidationMessages found");
      } else {
        log.debug("ValidationMessages not found. Delegating to org.hibernate.validator.ValidationMessages");
      }
    }
    return rb;
  }
  
  private ResourceBundle loadBundle(ClassLoader classLoader, Locale locale, String message)
  {
    ResourceBundle rb = null;
    try
    {
      rb = ResourceBundle.getBundle("ValidationMessages", locale, classLoader);
    }
    catch (MissingResourceException e)
    {
      log.trace(message);
    }
    return rb;
  }
  
  private String replaceVariables(String message, ResourceBundle bundle, Locale locale, boolean recurse)
  {
    Matcher matcher = messageParameterPattern.matcher(message);
    StringBuffer sb = new StringBuffer();
    while (matcher.find())
    {
      String parameter = matcher.group(1);
      String resolvedParameterValue = resolveParameter(parameter, bundle, locale, recurse);
      
      matcher.appendReplacement(sb, escapeMetaCharacters(resolvedParameterValue));
    }
    matcher.appendTail(sb);
    return sb.toString();
  }
  
  private String replaceAnnotationAttributes(String message, Map<String, Object> annotationParameters)
  {
    Matcher matcher = messageParameterPattern.matcher(message);
    StringBuffer sb = new StringBuffer();
    while (matcher.find())
    {
      String parameter = matcher.group(1);
      Object variable = annotationParameters.get(removeCurlyBrace(parameter));
      String resolvedParameterValue;
      String resolvedParameterValue;
      if (variable != null) {
        resolvedParameterValue = escapeMetaCharacters(variable.toString());
      } else {
        resolvedParameterValue = parameter;
      }
      matcher.appendReplacement(sb, resolvedParameterValue);
    }
    matcher.appendTail(sb);
    return sb.toString();
  }
  
  private String resolveParameter(String parameterName, ResourceBundle bundle, Locale locale, boolean recurse)
  {
    String parameterValue;
    try
    {
      if (bundle != null)
      {
        String parameterValue = bundle.getString(removeCurlyBrace(parameterName));
        if (recurse) {
          parameterValue = replaceVariables(parameterValue, bundle, locale, recurse);
        }
      }
      else
      {
        parameterValue = parameterName;
      }
    }
    catch (MissingResourceException e)
    {
      parameterValue = parameterName;
    }
    return parameterValue;
  }
  
  private String removeCurlyBrace(String parameter)
  {
    return parameter.substring(1, parameter.length() - 1);
  }
  
  private ResourceBundle findDefaultResourceBundle(Locale locale)
  {
    if (defaultBundlesMap.containsKey(locale)) {
      return (ResourceBundle)defaultBundlesMap.get(locale);
    }
    ResourceBundle bundle = ResourceBundle.getBundle("org.hibernate.validator.ValidationMessages", locale);
    defaultBundlesMap.put(locale, bundle);
    return bundle;
  }
  
  private ResourceBundle findUserResourceBundle(Locale locale)
  {
    if (userBundlesMap.containsKey(locale)) {
      return (ResourceBundle)userBundlesMap.get(locale);
    }
    ResourceBundle bundle = getFileBasedResourceBundle(locale);
    if (bundle != null) {
      userBundlesMap.put(locale, bundle);
    }
    return bundle;
  }
  
  private String escapeMetaCharacters(String s)
  {
    String escapedString = s.replace("\\", "\\\\");
    escapedString = escapedString.replace("$", "\\$");
    return escapedString;
  }
  
  private static class LocalisedMessage
  {
    private final String message;
    private final Locale locale;
    
    LocalisedMessage(String message, Locale locale)
    {
      this.message = message;
      this.locale = locale;
    }
    
    public String getMessage()
    {
      return message;
    }
    
    public Locale getLocale()
    {
      return locale;
    }
    
    public boolean equals(Object o)
    {
      if (this == o) {
        return true;
      }
      if ((o == null) || (getClass() != o.getClass())) {
        return false;
      }
      LocalisedMessage that = (LocalisedMessage)o;
      if (locale != null ? !locale.equals(locale) : locale != null) {
        return false;
      }
      if (message != null ? !message.equals(message) : message != null) {
        return false;
      }
      return true;
    }
    
    public int hashCode()
    {
      int result = message != null ? message.hashCode() : 0;
      result = 31 * result + (locale != null ? locale.hashCode() : 0);
      return result;
    }
  }
}

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

import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import org.hibernate.validator.metadata.BeanMetaDataCache;
import org.hibernate.validator.metadata.ConstraintHelper;

public class ValidatorContextImpl
  implements ValidatorContext
{
  private MessageInterpolator messageInterpolator;
  private TraversableResolver tr
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