[jboss-cvs] jbossretro/src/main/org/jboss/lang ...

Kabir Khan kkhan at jboss.com
Mon Jul 17 13:48:02 EDT 2006


  User: kkhan   
  Date: 06/07/17 13:48:02

  Modified:    src/main/org/jboss/lang  AnnotationHelper.java
  Log:
  Redirect calls to AccessibleObject.getAnnotations()
  
  Revision  Changes    Path
  1.9       +78 -1     jbossretro/src/main/org/jboss/lang/AnnotationHelper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AnnotationHelper.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossretro/src/main/org/jboss/lang/AnnotationHelper.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- AnnotationHelper.java	17 Jul 2006 16:55:50 -0000	1.8
  +++ AnnotationHelper.java	17 Jul 2006 17:48:02 -0000	1.9
  @@ -21,6 +21,7 @@
   */
   package org.jboss.lang;
   
  +import java.lang.reflect.AccessibleObject;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Field;
   import java.lang.reflect.Method;
  @@ -41,7 +42,7 @@
    * AnnotationHelper.
    * 
    * @author <a href="adrian at jboss.com">Adrian Brock</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   public class AnnotationHelper
   {
  @@ -114,6 +115,82 @@
      /**
       * Whether an annotation is present
       * 
  +    * @param ao the accessible object
  +    * @param annotationClass the annotation class
  +    * @return true when the annotation is present
  +    */
  +   public static boolean isAnnotationPresent(AccessibleObject ao, Class annotationClass)
  +   {
  +      if (ao instanceof Method)
  +      {
  +         return isAnnotationPresent((Method)ao, annotationClass);
  +      }
  +      else if (ao instanceof Constructor)
  +      {
  +         return isAnnotationPresent((Constructor)ao, annotationClass);
  +      }
  +      else if (ao instanceof Field)
  +      {
  +         return isAnnotationPresent((Field)ao, annotationClass);
  +      }
  +      //Should not happen
  +      throw new RuntimeException("Invalid AccessibleObject passed in " + ao);
  +   }
  +
  +   /**
  +    * Get an annotation
  +    * 
  +    * @param ao the accessible object
  +    * @param annotationClass the annotation class
  +    * @return the annotation
  +    */
  +   public static Object getAnnotation(AccessibleObject ao, Class annotationClass)
  +   {
  +      if (ao instanceof Method)
  +      {
  +         return getAnnotation((Method)ao, annotationClass);
  +      }
  +      else if (ao instanceof Constructor)
  +      {
  +         return getAnnotation((Constructor)ao, annotationClass);
  +      }
  +      else if (ao instanceof Field)
  +      {
  +         return getAnnotation((Field)ao, annotationClass);
  +      }
  +      //Should not happen
  +      throw new RuntimeException("Invalid AccessibleObject passed in " + ao);
  +   }
  +
  +   /**
  +    * Get annotations
  +    * 
  +    * @param ao the accessible object
  +    * @return the annotations
  +    */
  +   public static Object[] getAnnotations(AccessibleObject ao)
  +   {
  +      if (ao instanceof Method)
  +      {
  +         return getAnnotations((Method)ao);
  +      }
  +      else if (ao instanceof Constructor)
  +      {
  +         return getAnnotations((Constructor)ao);
  +      }
  +      else if (ao instanceof Field)
  +      {
  +         return getAnnotations((Field)ao);
  +      }
  +      //Should not happen
  +      throw new RuntimeException("Invalid AccessibleObject passed in " + ao);
  +   }
  +
  +   
  +   
  +   /**
  +    * Whether an annotation is present
  +    * 
       * @param method the method
       * @param annotationClass the annotation class
       * @return true when the annotation is present
  
  
  



More information about the jboss-cvs-commits mailing list