コード例 #1
0
 /**
  * Checks whether a given annotation is a multi value constraint and returns the contained
  * constraints if so.
  *
  * @param annotation the annotation to check.
  * @return A list of constraint annotations or the empty list if <code>annotation</code> is not a
  *     multi constraint annotation.
  */
 public <A extends Annotation> List<Annotation> getMultiValueConstraints(A annotation) {
   List<Annotation> annotationList = new ArrayList<Annotation>();
   try {
     final GetMethod getMethod = GetMethod.action(annotation.getClass(), "value");
     final Method method;
     if (System.getSecurityManager() != null) {
       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);
         for (Annotation a : annotations) {
           if (isConstraintAnnotation(a) || isBuiltinConstraint(a.annotationType())) {
             annotationList.add(a);
           }
         }
       }
     }
   } catch (IllegalAccessException iae) {
     // ignore
   } catch (InvocationTargetException ite) {
     // ignore
   }
   return annotationList;
 }
コード例 #2
0
 private void assertGroupsParameterExists(Annotation annotation) {
   try {
     final GetMethod getMethod = GetMethod.action(annotation.annotationType(), "groups");
     final Method method;
     if (System.getSecurityManager() != null) {
       method = AccessController.doPrivileged(getMethod);
     } else {
       method = getMethod.run();
     }
     if (method == null) {
       String msg =
           annotation.annotationType().getName()
               + " contains Constraint annotation, but does "
               + "not contain a groups parameter.";
       throw new ConstraintDefinitionException(msg);
     }
     Class<?>[] defaultGroups = (Class<?>[]) method.getDefaultValue();
     if (defaultGroups.length != 0) {
       String msg =
           annotation.annotationType().getName()
               + " contains Constraint annotation, but the groups "
               + "paramter default value is not the empty array.";
       throw new ConstraintDefinitionException(msg);
     }
   } catch (ClassCastException e) {
     String msg =
         annotation.annotationType().getName()
             + " contains Constraint annotation, but the "
             + "groups parameter is of wrong type.";
     throw new ConstraintDefinitionException(msg);
   }
 }
コード例 #3
0
 /**
  * Checks whether a given annotation is a multi value constraint or not.
  *
  * @param annotation the annotation to check.
  * @return <code>true</code> if the specified annotation is a multi value constraints, <code>false
  *     </code> otherwise.
  */
 public boolean isMultiValueConstraint(Annotation annotation) {
   boolean isMultiValueConstraint = false;
   try {
     final GetMethod getMethod = GetMethod.action(annotation.getClass(), "value");
     final Method method;
     if (System.getSecurityManager() != null) {
       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);
         for (Annotation a : annotations) {
           if (isConstraintAnnotation(a) || isBuiltinConstraint(a.annotationType())) {
             isMultiValueConstraint = true;
           } else {
             isMultiValueConstraint = false;
             break;
           }
         }
       }
     }
   } catch (IllegalAccessException iae) {
     // ignore
   } catch (InvocationTargetException ite) {
     // ignore
   }
   return isMultiValueConstraint;
 }