wms-jax.validation

 = new ArrayList();
    boolean groupSequenceContainsDefault = false;
    for (Class<?> group : groupSequence) {
      if (group.getName().equals(beanClass.getName()))
      {
        defaultGroupSequence.add(Default.class);
        groupSequenceContainsDefault = true;
      }
      else
      {
        if (group.getName().equals(Default.class.getName())) {
          throw new GroupDefinitionException("'Default.class' cannot appear in default group sequence list.");
        }
        defaultGroupSequence.add(group);
      }
    }
    if (!groupSequenceContainsDefault) {
      throw new GroupDefinitionException(beanClass.getName() + " must be part of the redefined default group sequence.");
    }
    if (log.isTraceEnabled()) {
      log.trace("Members of the default group sequence for bean {} are: {}", beanClass.getName(), defaultGroupSequence);
    }
  }
  
  public Set<PropertyDescriptor> getConstrainedProperties()
  {
    return Collections.unmodifiableSet(new HashSet(propertyDescriptors.values()));
  }
  
  private void createMetaData(AnnotationIgnores annotationIgnores, BeanMetaDataCache beanMetaDataCache)
  {
    beanDescriptor = new BeanDescriptorImpl(this);
    initDefaultGroupSequence();
    List<Class<?>> classes = new ArrayList();
    ReflectionHelper.computeClassHierarchy(beanClass, classes);
    for (Class<?> current : classes) {
      initClass(current, annotationIgnores, beanMetaDataCache);
    }
  }
  
  private void initClass(Class<?> clazz, AnnotationIgnores annotationIgnores, BeanMetaDataCache beanMetaDataCache)
  {
    initClassConstraints(clazz, annotationIgnores, beanMetaDataCache);
    initMethodConstraints(clazz, annotationIgnores, beanMetaDataCache);
    initFieldConstraints(clazz, annotationIgnores, beanMetaDataCache);
  }
  
  private void initDefaultGroupSequence()
  {
    List<Class<?>> groupSequence = new ArrayList();
    GroupSequence groupSequenceAnnotation = (GroupSequence)beanClass.getAnnotation(GroupSequence.class);
    if (groupSequenceAnnotation == null) {
      groupSequence.add(beanClass);
    } else {
      groupSequence.addAll(Arrays.asList(groupSequenceAnnotation.value()));
    }
    setDefaultGroupSequence(groupSequence);
  }
  
  private void initFieldConstraints(Class<?> clazz, AnnotationIgnores annotationIgnores, BeanMetaDataCache beanMetaDataCache)
  {
    GetDeclaredFields action = GetDeclaredFields.action(clazz);
    Field[] fields;
    Field[] fields;
    if (System.getSecurityManager() != null) {
      fields = (Field[])AccessController.doPrivileged(action);
    } else {
      fields = action.run();
    }
    for (Field field : fields)
    {
      addToPropertyNameList(field);
      if (!Modifier.isStatic(field.getModifiers())) {
        if (!annotationIgnores.isIgnoreAnnotations(field))
        {
          BeanMetaDataImpl<?> cachedMetaData = beanMetaDataCache.getBeanMetaData(clazz);
          
          boolean cachedFieldIsCascaded = false;
          List<ConstraintDescriptorImpl<?>> fieldMetaData;
          List<ConstraintDescriptorImpl<?>> fieldMetaData;
          if ((cachedMetaData != null) && (cachedMetaData.getMetaConstraintsAsMap().get(clazz) != null))
          {
            fieldMetaData = new ArrayList();
            cachedFieldIsCascaded = cachedMetaData.getCascadedMembers().contains(field);
            for (MetaConstraint<?, ?> metaConstraint : (List)cachedMetaData.getMetaConstraintsAsMap().get(clazz))
            {
              ConstraintDescriptorImpl<?> descriptor = metaConstraint.getDescriptor();
              if ((descriptor.getElementType() == ElementType.FIELD) && (metaConstraint.getPropertyName().equals(ReflectionHelper.getPropertyName(field)))) {
                fieldMetaData.add(descriptor);
              }
            }
          }
          else
          {
            fieldMetaData = findConstraints(field, ElementType.FIELD);
          }
          for (ConstraintDescriptorImpl<?> constraintDescription : fieldMetaData)
          {
            setAccessibility(field);
            MetaConstraint<T, ?> metaConstraint = createMetaConstraint(field, constraintDescription);
            addMetaConstraint(clazz, metaConstraint);
          }
          if ((cachedFieldIsCascaded) || (field.isAnnotationPresent(Valid.class))) {
            addCascadedMember(field);
          }
        }
      }
    }
  }
  
  private void addToPropertyNameList(Member member)
  {
    String name = ReflectionHelper.getPropertyName(member);
    if (name != null) {
      propertyNames.add(name);
    }
  }
  
  private void setAccessibility(Member member)
  {
    SetAccessibility action = SetAccessibility.action(member);
    if (System.getSecurityManager() != null) {
      AccessController.doPrivileged(action);
    } else {
      action.run();
    }
  }
  
  private void initMethodConstraints(Class<?> clazz, AnnotationIgnores annotationIgnores, BeanMetaDataCache beanMetaDataCache)
  {
    GetDeclaredMethods action = GetDeclaredMethods.action(clazz);
    Method[] declaredMethods;
    Method[] declaredMethods;
    if (System.getSecurityManager() != null) {
      declaredMethods = (Method[])AccessController.doPrivileged(action);
    } else {
      declaredMethods = action.run();
    }
    for (Method method : declaredMethods)
    {
      addToPropertyNameList(method);
      if (!Modifier.isStatic(method.getModifiers())) {
        if (!annotationIgnores.isIgnoreAnnotations(method))
        {
          BeanMetaDataImpl<?> cachedMetaData = beanMetaDataCache.getBeanMetaData(clazz);
          
          boolean cachedMethodIsCascaded = false;
          List<ConstraintDescriptorImpl<?>> methodMetaData;
          List<ConstraintDescriptorImpl<?>> methodMetaData;
          if ((cachedMetaData != null) && (cachedMetaData.getMetaConstraintsAsMap().get(clazz) != null))
          {
            cachedMethodIsCascaded = cachedMetaData.getCascadedMembers().contains(method);
            methodMetaData = new ArrayList();
            for (MetaConstraint<?, ?> metaConstraint : (List)cachedMetaData.getMetaConstraintsAsMap().get(clazz))
            {
              ConstraintDescriptorImpl<?> descriptor = metaConstraint.getDescriptor();
              if ((descriptor.getElementType() == ElementType.METHOD) && (metaConstraint.getPropertyName().equals(ReflectionHelper.getPropertyName(method)))) {
                methodMetaData.add(descriptor);
              }
            }
          }
          else
          {
            methodMetaData = findConstraints(method, ElementType.METHOD);
          }
          for (ConstraintDescriptorImpl<?> constraintDescription : methodMetaData)
          {
            setAccessibility(method);
            MetaConstraint<T, ?> metaConstraint = createMetaConstraint(method, constraintDescription);
            addMetaConstraint(clazz, metaConstraint);
          }
          if ((cachedMethodIsCascaded) || (method.isAnnotationPresent(Valid.class))) {
            addCascadedMember(method);
          }
        }
      }
    }
  }
  
  private PropertyDescriptorImpl addPropertyDescriptorForMember(Member member, boolean isCascaded)
  {
    String name = ReflectionHelper.getPropertyName(member);
    PropertyDescriptorImpl propertyDescriptor = (PropertyDescriptorImpl)propertyDescriptors.get(name);
    if (propertyDescriptor == null)
    {
      propertyDescriptor = new PropertyDescriptorImpl(ReflectionHelper.getType(member), isCascaded, name, this);
      
      propertyDescriptors.put(name, propertyDescriptor);
    }
    return propertyDescriptor;
  }
  
  private boolean isValidAnnotationPresent(Member member)
  {
    return ((AnnotatedElement)member).isAnnotationPresent(Valid.class);
  }
  
  private void initClassConstraints(Class<?> clazz, AnnotationIgnores annotationIgnores, BeanMetaDataCache beanMetaDataCache)
  {
    if (annotationIgnores.isIgnoreAnnotations(clazz)) {
      return;
    }
    BeanMetaDataImpl<?> cachedMetaData = beanMetaDataCache.getBeanMetaData(clazz);
    List<ConstraintDescriptorImpl<?>> classMetaData;
    List<ConstraintDescriptorImpl<?>> classMetaData;
    if ((cachedMetaData != null) && (cachedMetaData.getMetaConstraintsAsMap().get(clazz) != null))
    {
      classMetaData = new ArrayList();
      for (MetaConstraint<?, ?> metaConstraint : (List)cachedMetaData.getMetaConstraintsAsMap().get(clazz))
      {
        ConstraintDescriptorImpl<?> descriptor = metaConstraint.getDescriptor();
        if (descriptor.getElementType() == ElementType.TYPE) {
          classMetaData.add(descriptor);
        }
      }
    }
    else
    {
      classMetaData = findClassLevelConstraints(clazz);
    }
    for (ConstraintDescriptorImpl<?> constraintDescription : classMetaData)
    {
      MetaConstraint<T, ?> metaConstraint = createMetaConstraint(null, constraintDescription);
      addMetaConstraint(clazz, metaConstraint);
    }
  }
  
  private <A extends Annotation> MetaConstraint<T, ?> createMetaConstraint(Member m, ConstraintDescriptorImpl<A> descriptor)
  {
    return new MetaConstraint(beanClass, m, descriptor);
  }
  
  private <A extends Annotation> List<ConstraintDescriptorImpl<?>> findConstraintAnnotations(Class<?> clazz, A annotation, ElementType type)
  {
    List<ConstraintDescriptorImpl<?>> constraintDescriptors = new ArrayList();
    
    List<Annotation> constraints = new ArrayList();
    if ((constraintHelper.isConstraintAnnotation(annotation)) || (constraintHelper.isBuiltinConstraint(annotation.annotationType()))) {
      constraints.add(annotation);
    }
    constraints.addAll(constraintHelper.getMultiValueConstraints(annotation));
    for (Annotation constraint : constraints)
    {
      ConstraintDescriptorImpl constraintDescriptor = buildConstraintDescriptor(clazz, constraint, type);
      constraintDescriptors.add(constraintDescriptor);
    }
    return constraintDescriptors;
  }
  
  private <A extends Annotation> ConstraintDescriptorImpl buildConstraintDescriptor(Class<?> clazz, A annotation, ElementType type)
  {
    ConstraintOrigin definedIn = determineOrigin(clazz);
    ConstraintDescriptorImpl constraintDescriptor;
    ConstraintDescriptorImpl constraintDescriptor;
    if ((clazz.isInterface()) && (!clazz.equals(beanClass))) {
      constraintDescriptor = new ConstraintDescriptorImpl(annotation, constraintHelper, clazz, type, definedIn);
    } else {
      constraintDescriptor = new ConstraintDescriptorImpl(annotation, constraintHelper, type, definedIn);
    }
    return constraintDescriptor;
  }
  
  private List<ConstraintDescriptorImpl<?>> findClassLevelConstraints(Class<?> beanClass)
  {
    List<ConstraintDescriptorImpl<?>> metaData = new ArrayList();
    for (Annotation annotation : beanClass.getAnnotations()) {
      metaData.addAll(findConstraintAnnotations(beanClass, annotation, ElementType.TYPE));
    }
    return metaData;
  }
  
  private List<ConstraintDescriptorImpl<?>> findConstraints(Member member, ElementType type)
  {
    assert (((member instanceof Field)) || ((member instanceof Method)));
    
    List<ConstraintDescriptorImpl<?>> metaData = new ArrayList();
    for (Annotation annotation : ((AnnotatedElement)member).getAnnotations()) {
      metaData.addAll(findConstraintAnnotations(member.getDeclaringClass(), annotation, type));
    }
    return metaData;
  }
  
  private ConstraintOrigin determineOrigin(Class<?> clazz)
  {
    if (clazz.equals(beanClass)) {
      return ConstraintOrigin.DEFINED_LOCALLY;
    }
    return ConstraintOrigin.DEFINED_IN_HIERARCHY;
  }
  
  public String toString()
  {
    StringBuilder sb = new StringBuilder();
    sb.append("BeanMetaDataImpl");
    sb.append("{beanClass=").append(beanClass);
    sb.append(", beanDescriptor=").append(beanDescriptor);
    sb.append(", metaConstraints=").append(metaConstraints);
    sb.append(", cascadedMembers=").append(cascadedMembers);
    sb.append(", propertyDescriptors=").append(propertyDescriptors);
    sb.append(", defaultGroupSequence=").append(defaultGroupSequence);
    sb.append(", constraintHelper=").append(constraintHelper);
    sb.append('}');
    return sb.toString();
  }
}

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

class ConstraintDescriptorImpl$ClassIndexWrapper
{
  final Class<?> clazz;
  final int index;
  
  ConstraintDescriptorImpl$ClassIndexWrapper(Class<?> arg1, int clazz)
  {
    this.clazz = clazz;
    this.index = index;
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if ((o == null) || (getClass() != o.getClass())) {
      return false;
    }
    ConstraintDescriptorImpl<T>.ClassIndexWrapper that = (ClassIndexWrapper)o;
    if (index != index) {
      return false;
    }
    if ((clazz != null) && (!clazz.equals(clazz))) {
      return false;
    }
    if ((clazz == null) && (clazz != null)) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    int result = clazz != null ? clazz.hashCode() : 0;
    result = 31 * result + index;
    return result;
  }
}

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

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.validation.Constraint;
import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintValidator;
import javax.validation.OverridesAttribute;
import javax.validation.OverridesAttribute.List;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import javax.validation.ValidationException;
import javax.validation.groups.Default;
import javax.validation.metadata.ConstraintDescriptor;
import org.hibernate.validator.util.GetAnnotationParameter;
import org.hibernate.validator.util.GetDeclaredMethods;
import org.hibernate.validator.util.GetMethod;
import org.hibernate.validator.util.GetMethods;
import org.hibernate.validator.util.LoggerFactory;
import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
import org.slf4j.Logger;

public class ConstraintDescriptorImpl<T extends Annotation>
  implements ConstraintDescriptor<T>, Serializable
{
  private static final long serialVersionUID = -2563102960314069246L;
  private static final Logger log = ;
  private static final int OVERRIDES_PARAMETER_DEFAULT_INDEX = -1;
  private static final String GROUPS = "groups";
  private static final String PAYLOAD = "payload";
  private final T annotation;
  private final List<Class<? extends ConstraintValidator<T, ?>>> constraintValidatorDefinitionClasses;
  private final Set<Class<?>> groups;
  private final Map<String, Object> attributes;
  private final Set<Class<? extends Payload>> payloads;
  private final Set<ConstraintDescriptor<?>> composingConstraints;
  private final boolean isReportAsSingleInvalidConstraint;
  private final ElementType elementType;
  private final ConstraintOrigin definedOn;
  private final transient ConstraintHelper constraintHelper;
  
  public ConstraintDescriptorImpl(T annotation, ConstraintHelper constraintHelper, Class<?> implicitGroup, ElementType type, ConstraintOrigin definedOn)
  {
    this.annotation = annotation;
    this.constraintHelper = constraintHelper;
    elementType = type;
    this.definedOn = definedOn;
    isReportAsSingleInvalidConstraint = annotation.annotationType().isAnnotationPresent(ReportAsSingleViolation.class);
    
    attributes = buildAnnotationParameterMap(annotation);
    groups = buildGroupSet(implicitGroup);
    payloads = buildPayloadSet(annotation);
    constraintValidatorDefinitionClasses = findConstraintValidatorClasses();
    composingConstraints = parseComposingConstraints();
  }
  
  public ConstraintDescriptorImpl(T annotation, ConstraintHelper constraintHelper, ElementType type, ConstraintOrigin definedOn)
  {
    this(annotation, constraintHelper, null, type, definedOn);
  }
  
  private Set<Class<? extends Payload>> buildPayloadSet(T annotation)
  {
    Set<Class<? extends Payload>> payloadSet = new HashSet();
    Class<Payload>[] payloadFromAnnotation;
    try
    {
      GetAnnotationParameter<Class[]> action = GetAnnotationParameter.action(annotation, "payload", Class[].class);
      Class<Payload>[] payloadFromAnnotation;
      if (System.getSecurityManager() != null) {
        payloadFromAnnotation = (Class[])AccessController.doPrivileged(action);
      } else {
        payloadFromAnnotation = (Class[])action.run();
      }
    }
    catch (ValidationException e)
    {
      payloadFromAnnotation = null;
    }
    if (payloadFromAnnotation != null) {
      payloadSet.addAll(Arrays.asList(payloadFromAnnotation));
    }
    return Collections.unmodifiableSet(payloadSet);
  }
  
  private Set<Class<?>> buildGroupSet(Class<?> implicitGroup)
  {
    Set<Class<?>> groupSet = new HashSet();
    
    GetAnnotationParameter<Class[]> action = GetAnnotationParameter.action(annotation, "groups", Class[].class);
    Class<?>[] groupsFromAnnotation;
    Class<?>[] groupsFromAnnotation;
    if (System.getSecurityManager() != null) {
      groupsFromAnnotation = (Class[])AccessController.doPrivileged(action);
    } else {
      groupsFromAnnotation = (Class[])action.run();
    }
    if (groupsFromAnnotation.length == 0) {
      groupSet.add(Default.class);
    } else {
      groupSet.addAll(Arrays.asList(groupsFromAnnotation));
    }
    if ((implicitGroup != null) && (groupSet.contains(Default.class))) {
      groupSet.add(implicitGroup);
    }
    return Collections.unmodifiableSet(groupSet);
  }
  
  private List<Class<? extends ConstraintValidator<T, ?>>> findConstraintValidatorClasses()
  {
    Class<T> annotationType = getAnnotationType();
    List<Class<? extends ConstraintValidator<T, ?>>> constraintValidatorClasses = new ArrayList();
    if (constraintHelper.containsConstraintValidatorDefinition(annotationType))
    {
      for (Class<? extends ConstraintValidator<T, ?>> validator : constraintHelper.getConstraintValidatorDefinition(annotationType)) {
        constraintValidatorClasses.add(validator);
      }
      return Collections.unmodifiableList(constraintValidatorClasses);
    }
    List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> constraintDefinitionClasses = new ArrayList();
    if (constraintHelper.isBuiltinConstraint(annotation.annotationType()))
    {
      constraintDefinitionClasses.addAll(constraintHelper.getBuiltInConstraints(annotationType));
    }
    else
    {
      Class<? extends ConstraintValidator<?, ?>>[] validatedBy = ((Constraint)annotationType.getAnnotation(Constraint.class)).validatedBy();
      
      constraintDefinitionClasses.addAll(Arrays.asList(validatedBy));
    }
    constraintHelper.addConstraintValidatorDefinition(annotation.annotationType(), constraintDefinitionClasses);
    for (Class<? extends ConstraintValidator<? extends Annotation, ?>> validator : constraintDefinitionClasses)
    {
      Class<? extends ConstraintValidator<T, ?>> safeValidator = validator;
      constraintValidatorClasses.add(safeValidator);
    }
    return Collections.unmodifiableList(constraintValidatorClasses);
  }
  
  private Class<T> getAnnotationType()
  {
    return annotation.annotationType();
  }
  
  public T getAnnotation()
  {
    return annotation;
  }
  
  public Set<Class<?>> getGroups()
  {
    return groups;
  }
  
  public Set<Class<? extends Payload>> getPayload()
  {
    return payloads;
  }
  
  public List<Class<? extends ConstraintValidator<T, ?>>> getConstraintValidatorClasses()
  {
    return constraintValidatorDefinitionClasses;
  }
  
  public Map<String, Object> getAttributes()
  {
    return attributes;
  }
  
  public Set<ConstraintDescriptor<?>> getComposingConstraints()
  {
    return composingConstraints;
  }
  
  public boolean isReportAsSingleViolation()
  {
    return isReportAsSingleInvalidConstraint;
  }
  
  public ElementType getElementType()
  {
    return elementType;
  }
  
  public ConstraintOrigin getDefinedOn()
  {
    return definedOn;
  }
  
  public String toString()
  {
    StringBuilder sb = new StringBuilder();
    sb.append("ConstraintDescriptorImpl");
    sb.append("{annotation=").append(annotation.annotationType().getName());
    sb.append(", payloads=").append(payloads);
    sb.append(", hasComposingConstraints=").append(composingConstraints.isEmpty());
    sb.append(", isReportAsSingleInvalidConstraint=").append(isReportAsSingleInvalidConstraint);
    sb.append(", elementType=").append(elementType);
    sb.append(", definedOn=").append(definedOn);
    sb.append(", groups=").append(groups);
    sb.append(", attributes=").append(attributes);
    sb.append('}');
    return sb.toString();
  }
  
  private Map<String, Object> buildAnnotationParameterMap(Annotation annotation)
  {
    GetDeclaredMethods action = GetDeclaredMethods.action(annotation.annotationType());
    Method[] declaredMethods;
    Method[] declaredMethods;
    if (System.getSecurityManager() != null) {
      declaredMethods = (Method[])AccessController.doPrivileged(action);
    } else {
      declaredMethods = action.run();
    }
    Map<String, Object> parameters = new HashMap(declaredMethods.length);
    for (Method m : declaredMethods) {
      try
      {
        parameters.put(m.getName(), m.invoke(annotation, new Object[0]));
      }
      catch (IllegalAccessException e)
      {
        throw new ValidationException("Unable to read annotation attributes: " + annotation.getClass(), e);
      }
      catch (InvocationTargetException e)
      {
        throw new ValidationException("Unable to read annotation attributes: " + annotation.getClass(), e);
      }
    }
    return Collections.unmodifiableMap(parameters);
  }
  
  private Object getMethodValue(Annotation annotation, Method m)
  {
    Object value;
    try
    {
      value = m.invoke(annotation, new Object[0]);
    }
    catch (IllegalAccessException e)
    {
      throw new ValidationException("Unable to retrieve annotation parameter value.");
    }
    catch (InvocationTargetException e)
    {
      throw new ValidationException("Unable to retrieve annotation parameter value.");
    }
    return value;
  }
  
  private Map<ConstraintDescriptorImpl<T>.ClassIndexWrapper, Map<String, Object>> parseOverrideParameters()
  {
    Map<ConstraintDescriptorImpl<T>.ClassIndexWrapper, Map<String, Object>> overrideParameters = new HashMap();
    
    GetMethods getMethods = GetMethods.action(annotation.annotationType());
    Method[] methods;
    Method[] methods;
    if (System.getSecurityManager() != null) {
      methods = (Method[])AccessController.doPrivileged(getMethods);
    } else {
      methods = getMethods.run();
    }
    for (Method m : methods) {
      if (m.getAnnotation(OverridesAttribute.class) != null) {
        addOverrideAttributes(overrideParameters, m, new OverridesAttribute[] { (OverridesAttribute)m.getAnnotation(OverridesAttribute.class) });
      } else if (m.getAnnotation(OverridesAttribute.List.class) != null) {
        addOverrideAttributes(overrideParameters, m, ((OverridesAttribute.List)m.getAnnotation(OverridesAttribute.List.class)).value());
      }
    }
    return overrideParameters;
  }
  
  private void addOverrideAttributes(Map<ConstraintDescriptorImpl<T>.ClassIndexWrapper, Map<String, Object>> overrideParameters, Method m, OverridesAttribute... attributes)
  {
    Object value = getMethodValue(annotation, m);
    for (OverridesAttribute overridesAttribute : attributes)
    {
      ensureAttributeIsOverridable(m, overridesAttribute);
      
      ConstraintDescriptorImpl<T>.ClassIndexWrapper wrapper = new ClassIndexWrapper(overridesAttribute.constraint(), overridesAttribute.constraintIndex());
      
      Map<String, Object> map = (Map)overrideParameters.get(wrapper);
      if (map == null)
      {
        map = new HashMap();
        overrideParameters.put(wrapper, map);
      }
      map.put(overridesAttribute.name(), value);
    }
  }
  
  private void ensureAttributeIsOverridable(Method m, OverridesAttribute overridesAttribute)
  {
    GetMethod getMethod = GetMethod.action(overridesAttribute.constraint(), overridesAttribute.name());
    Method method;
    Method method;
    if (System.getSecurityManager() != null) {
      method = (Method)AccessController.doPrivileged(getMethod);
    } else {
      method = getMethod.run();
    }
    if (method == null) {
      throw new ConstraintDefinitionException("Overridden constraint does not define an attribute with name " + overridesAttribute.name());
    }
    Class<?> returnTypeOfOverriddenConstraint = method.getReturnType();
    if (!returnTypeOfOverriddenConstraint.equals(m.getReturnType()))
    {
      String message = "The overriding type of a composite constraint must be identical to the overridden one. Expected " + returnTypeOfOverriddenConstraint.getName() + " found " + m.getReturnType();
      
      throw new ConstraintDefinitionException(message);
    }
  }
  
  private Set<ConstraintDescriptor<?>> parseComposingConstraints()
  {
    Set<ConstraintDescriptor<?>> composingConstraintsSet = new HashSet();
    Map<ConstraintDescriptorImpl<T>.ClassIndexWrapper, Map<String, Object>> overrideParameters = parseOverrideParameters();
    int index;
    for (Annotation declaredAnnotation : annotation.annotationType().getDeclaredAnnotations()) {
      if ((constraintHelper.isConstraintAnnotation(declaredAnnotation)) || (constraintHelper.isBuiltinConstraint(declaredAnnotation.annotationType())))
      {
        ConstraintDescriptorImpl<?> descriptor = createComposingConstraintDescriptor(declaredAnnotation, overrideParameters, -1);
        
        composingConstraintsSet.add(descriptor);
        log.debug("Adding composing constraint: " + descriptor);
      }
      else if (constraintHelper.isMultiValueConstraint(declaredAnnotation))
      {
        List<Annotation> multiValueConstraints = constraintHelper.getMultiValueConstraints(declaredAnnotation);
        index = 0;
        for (Annotation constraintAnnotation : multiValueConstraints)
        {
          ConstraintDescriptorImpl<?> descriptor = createComposingConstraintDescriptor(constraintAnnotation, overrideParameters, index);
          
          composingConstraintsSet.add(descriptor);
          log.debug("Adding composing constraint: " + descriptor);
          index++;
        }
      }
    }
    return Collections.unmodifiableSet(composingConstraintsSet);
  }
  
  private <U extends Annotation> ConstraintDescriptorImpl<U> createComposingConstraintDescriptor(U declaredAnnotation, Map<ConstraintDescriptorImpl<T>.ClassIndexWrapper, Map<String, Object>> overrideParameters, int index)
  {
    Class<U> annotationType = declaredAnnotation.annotationType();
    return createComposingConstraintDescriptor(overrideParameters, index, declaredAnnotation, annotationType);
  }
  
  private <U extends Annotation> ConstraintDescriptorImpl<U> createComposingConstraintDescriptor(Map<ConstraintDescriptorImpl<T>.ClassIndexWrapper, Map<String, Object>> overrideParameters, int index, U constraintAnnotation, Class<U> annotationType)
  {
    AnnotationDescriptor<U> annotationDescriptor = new AnnotationDescriptor(annotationType, buildAnnotationParameterMap(constraintAnnotation));
    
    Map<String, Object> overrides = (Map)overrideParameters.get(new ClassIndexWrapper(annotationType, index));
    if (overrides != null) {
      for (Map.Entry<String, Object> entry : overrides.entrySet()) {
        annotationDescriptor.setValue((String)entry.getKey(), entry.getValue());
      }
    }
    annotationDescriptor.setValue("groups", groups.toArray(new Class[groups.size()]));
    
    annotationDescriptor.setValue("payload", payloads.toArray(new Class[payloads.size()]));
    
    U annotationProxy = AnnotationFactory.create(annotationDescriptor);
    return new ConstraintDescriptorImpl(annotationProxy, constraintHelper, elementType, definedOn);
  }
  
  private class ClassIndexWrapper
  {
    final Class<?> clazz;
    final int index;
    
    ClassIndexWrapper(int clazz)
    {
      this.clazz = clazz;
      this.index = index;
    }
    
    public boolean equals(Object o)
    {
      if (this == o) {
        return true;
      }
      if ((o == null) || (getClass() != o.getClass())) {
        return false;
      }
      ConstraintDescriptorImpl<T>.ClassIndexWrapper that = (ClassIndexWrapper)o;
      if (index != index) {
        return false;
      }
      if ((clazz != null) && (!clazz.equals(clazz))) {
        return false;
      }
      if ((clazz == null) && (clazz != null)) {
        return false;
      }
      return true;
    }
    
    public int hashCode()
    {
      int result = clazz != null ? clazz.hashCode() : 0;
      result = 31 * result + index;
      return result;
    }
  }
}

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

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import javax.validation.Constraint;
import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintValidator;
import javax.validation.ValidationException;
import javax.validation.constraints.AssertFalse;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Future;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.impl.AssertFalseValidator;
import org.hibernate.validator.constraints.impl.AssertTrueValidator;
import org.hibernate.validator.constraints.impl.DecimalMaxValidatorForNumber;
import org.hibernate.validator.constraints.impl.DecimalMaxValidatorForString;
import org.hibernate.validator.constraints.impl.DecimalMinValidatorForNumber;
import org.hibernate.validator.constraints.impl.DecimalMinValidatorForString;
import org.hibernate.validator.constraints.impl.DigitsValidatorForNumber;
import org.hibernate.validator.constraints.impl.DigitsValidatorForString;
import org.hibernate.validator.constraints.impl.FutureValidatorForCalendar;
import org.hibernate.validator.constraints.impl.FutureValidatorForDate;
import org.hibernate.validator.constraints.impl.MaxValidatorForNumber;
import org.hibernate.validator.constraints.impl.MaxValidatorForString;
import org.hibernate.validator.constraints.impl.MinValidatorForNumber;
import org.hibernate.validator.constraints.impl.MinValidatorForString;
import org.hibernate.validator.constraints.impl.NotNullValidator;
import org.hibernate.validator.constraints.impl.NullValidator;
import org.hibernate.validator.constraints.impl.PastValidatorForCalendar;
import org.hibernate.validator.constraints.impl.PastValidatorForDate;
import org.hibernate.validator.constraints.impl.PatternValidator;
import org.hibernate.validator.constraints.impl.SizeValidatorForArray;
import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfBoolean;
import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfByte;
import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfChar;
import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfDouble;
import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfFloat;
import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfInt;
import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfLong;
import org.hibernate.validator.constraints.impl.SizeValidatorForCollection;
import org.hibernate.validator.constraints.impl.SizeValidatorForMap;
import org.hibernate.validator.constraints.impl.SizeValidatorForString;
import org.hibernate.validator.util.GetAnnotationParameter;
import org.hibernate.validator.util.GetMethod;
import org.hibernate.validator.util.GetMethods;

public class ConstraintHelper
{
  private final ConcurrentHashMap<Class<? extends Annotation>, List<Class<? extends ConstraintValidator<?, ?>>>> builtinConstraints = new ConcurrentHashMap();
  private final ConcurrentHashMap<Class<? extends Annotation>, List<Class<? extends ConstraintValidator<? extends Annotation, ?>>>> constraintValidatorDefinitons = new ConcurrentHashMap();
  
  public ConstraintHelper()
  {
    List<Class<? extends ConstraintValidator<?, ?>>> constraintList = new ArrayList();
    
    constraintList.add(AssertFalseValidator.class);
    builtinConstraints.put(AssertFalse.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(AssertTrueValidator.class);
    builtinConstraints.put(AssertTrue.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(DecimalMaxValidatorForNumber.class);
    constraintList.add(DecimalMaxValidatorForString.class);
    builtinConstraints.put(DecimalMax.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(DecimalMinValidatorForNumber.class);
    constraintList.add(DecimalMinValidatorForString.class);
    builtinConstraints.put(DecimalMin.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(DigitsValidatorForString.class);
    constraintList.add(DigitsValidatorForNumber.class);
    builtinConstraints.put(Digits.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(FutureValidatorForCalendar.class);
    constraintList.add(FutureValidatorForDate.class);
    builtinConstraints.put(Future.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(MaxValidatorForNumber.class);
    constraintList.add(MaxValidatorForString.class);
    builtinConstraints.put(Max.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(MinValidatorForNumber.class);
    constraintList.add(MinValidatorForString.class);
    builtinConstraints.put(Min.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(NotNullValidator.class);
    builtinConstraints.put(NotNull.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(NullValidator.class);
    builtinConstraints.put(Null.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(PastValidatorForCalendar.class);
    constraintList.add(PastValidatorForDate.class);
    builtinConstraints.put(Past.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(PatternValidator.class);
    builtinConstraints.put(Pattern.class, constraintList);
    
    constraintList = new ArrayList();
    constraintList.add(SizeValidatorForString.class);
    constraintList.add(SizeValidatorForCollection.class);
    constraintList.add(SizeValidatorForArray.class);
    constraintList.add(SizeValidatorForMap.class);
    constraintList.add(SizeValidatorForArraysOfBoolean.class);
    constraintList.add(SizeValidatorForArraysOfByte.class);
    constraintList.add(SizeValidatorForArraysOfChar.class);
    constraintList.add(SizeValidatorForArraysOfDouble.class);
    constraintList.add(SizeValidatorForArraysOfFloat.class);
    constraintList.add(SizeValidatorForArraysOfInt.class);
    constraintList.add(SizeValidatorForArraysOfLong.class);
    builtinConstraints.put(Size.class, constraintList);
  }
  
  public List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> getBuiltInConstraints(Class<? extends Annotation> annotationClass)
  {
    List<Class<? extends ConstraintValidator<?, ?>>> builtInList = (List)builtinConstraints.get(annotationClass);
    if ((builtInList == null) || (builtInList.size() == 0)) {
      throw new ValidationException("Unable to find constraints for  " + annotationClass);
    }
    List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> constraints = new ArrayList(builtInList.size());
    for (Class<? extends ConstraintValidator<?, ?>> validatorClass : builtInList)
    {
      Class<ConstraintValidator<? extends Annotation, ?>> safeValdiatorClass = validatorClass;
      constraints.add(safeValdiatorClass);
    }
    return constraints;
  }
  
  public boolean isBuiltinConstraint(Class<? extends Annotation> annotationType)
  {
    return builtinConstraints.containsKey(annotationType);
  }
  
  public boolean isMultiValueConstraint(Annotation annotation)
  {
    boolean isMultiValueConstraint = false;
    try
    {
      GetMethod getMethod = GetMethod.action(annotation.getClass(), "value");
      Method method;
      Method method;
      if (System.getSecurityManager() != null) {
        method = (Method)AccessController.doPrivileged(getMethod);
      } else {
        method = getMethod.run();
      }
      if (method != null)
      {
        Class returnType = method.getReturnType();
        if ((returnType.isArray()) && (returnType.getComponentType().isAnnotation()))
        {
          Annotation[] annotations = (Annotation[])method.invoke(annotation, new Object[0]);
          for (Annotation a : annotations) {
            if ((isConstraintAnnotation(a)) || (isBuiltinConstraint(a.annotationType())))
            {
              isMultiValueConstraint = true;
            }
            else
            {
              isMultiValueConstraint = false;
              break;
            }
          }
        }
      }
    }
    catch (IllegalAccessException iae) {}catch (InvocationTargetException ite) {}
    return isMultiValueConstraint;
  }
  
  public <A extends Annotation> List<Annotation> getMultiValueConstraints(A annotation)
  {
    List<Annotation> annotationList = new ArrayList();
    try
    {
      GetMethod getMethod = GetMethod.action(annotation.getClass(), "value");
      Method method;
      Method method;
      if (System.getSecurityManager() != null) {
        method = (Method)AccessController.doPrivileged(getMethod);
      } else {
        method = getMethod.run();
      }
      if (method != null)
      {
        Class returnType = method.getReturnType();
        if ((returnType.isArray()) && (returnType.getComponentType().isAnnotation()))
        {
          Annotation[] annotations = (Annotation[])method.invoke(annotation, new Object[0]);
          for (Annotation a : annotations) {
            if ((isConstraintAnnotation(a)) || (isBuiltinConstraint(a.annotationType()))) {
              annotationList.add(a);
            }
          }
        }
      }
    }
    catch (IllegalAccessException iae) {}catch (InvocationTargetException ite) {}
    return annotationList;
  }
  
  public boolean isConstraintAnnotation(Annotation annotation)
  {
    Constraint constraint = (Constraint)annotation.annotationType().getAnnotation(Constraint.class);
    if (constraint == null) {
      return false;
    }
    assertMessageParameterExists(annotation);
    assertGroupsParameterExists(annotation);
    assertPayloadPar
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