[jboss-cvs] container/src/main/org/jboss/annotation/factory ...

Kabir Khan kkhan at jboss.com
Wed Jul 19 11:52:47 EDT 2006


  User: kkhan   
  Date: 06/07/19 11:52:47

  Modified:    src/main/org/jboss/annotation/factory 
                        AnnotationCreator.java
  Log:
  Make it possible to pass in a null class to annotation creator and a classloader to use to load the annotation class
  
  Revision  Changes    Path
  1.3       +42 -20    container/src/main/org/jboss/annotation/factory/AnnotationCreator.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AnnotationCreator.java
  ===================================================================
  RCS file: /cvsroot/jboss/container/src/main/org/jboss/annotation/factory/AnnotationCreator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- AnnotationCreator.java	18 Jul 2006 13:27:44 -0000	1.2
  +++ AnnotationCreator.java	19 Jul 2006 15:52:47 -0000	1.3
  @@ -51,7 +51,7 @@
    *
    * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
    * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class AnnotationCreator implements AnnotationParserVisitor
   {
  @@ -311,9 +311,37 @@
         throw new RuntimeException("unable to determine member type for annotation: " + annotation.getName() + "." + member);
      }
      
  -   public static Object createAnnotation(ASTAnnotation node, Class annotation) throws Exception
  +   private static ASTAnnotation getRootExpr(final String annotationExpr) throws Exception
  +   {
  +      try
  +      {
  +         ASTAnnotation node = (ASTAnnotation)AccessController.doPrivileged(new PrivilegedExceptionAction() {
  +           public Object run() throws Exception{
  +              AnnotationParser parser = new AnnotationParser(new StringReader(annotationExpr));
  +              org.jboss.annotation.factory.ast.ASTStart start = parser.Start();
  +              ASTAnnotation node = (ASTAnnotation) start.jjtGetChild(0);
  +              
  +              return node;
  +           }
  +         });
  +         
  +         return node;
  +      }
  +      catch (PrivilegedActionException e)
  +      {
  +         throw new RuntimeException(e.getException());
  +      }
  +   }
  +   
  +   
  +   public static Object createAnnotation(ASTAnnotation node, Class annotation, ClassLoader cl) throws Exception
      {
         HashMap map = new HashMap();
  +      if (annotation == null)
  +      {
  +         ClassLoader loader = (cl != null) ? cl : Thread.currentThread().getContextClassLoader();
  +         annotation = loader.loadClass(node.getIdentifier());
  +      }
         
         if (node.jjtGetNumChildren() > 0)
         {
  @@ -343,26 +371,20 @@
         return AnnotationProxy.createProxy(map, annotation);
      }
   
  -   public static Object createAnnotation(final String annotationExpr, final Class annotation) throws Exception
  -   {
  -      try
  +   public static Object createAnnotation(ASTAnnotation node, Class annotation) throws Exception
         {
  -         Object proxy = AccessController.doPrivileged(new PrivilegedExceptionAction() {
  -           public Object run() throws Exception{
  -              AnnotationParser parser = new AnnotationParser(new StringReader(annotationExpr));
  -              org.jboss.annotation.factory.ast.ASTStart start = parser.Start();
  -              ASTAnnotation node = (ASTAnnotation) start.jjtGetChild(0);
  -              
  -              return createAnnotation(node, annotation);
  +      return createAnnotation(node, annotation, null);
              }
  -         });
            
  -         return proxy;
  -      }
  -      catch (PrivilegedActionException e)
  +   public static Object createAnnotation(final String annotationExpr, final Class annotation) throws Exception
         {
  -         throw new RuntimeException(e.getException());
  +      return createAnnotation(getRootExpr(annotationExpr), annotation, null);
         }
  +
  +   public static Object createAnnotation(String annotationExpr, ClassLoader cl) throws Exception
  +   {
  +      return createAnnotation(getRootExpr(annotationExpr), null, cl);
      }
   
  +   
   }
  
  
  



More information about the jboss-cvs-commits mailing list