[jboss-cvs] JBossAS SVN: r64114 - in projects/microcontainer/trunk/kernel/src/main/org/jboss: beans/metadata/spi and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 18 07:54:34 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-07-18 07:54:34 -0400 (Wed, 18 Jul 2007)
New Revision: 64114

Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAnnotationMetaData.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/AnnotationMetaData.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/metadata/basic/BasicKernelMetaDataRepository.java
Log:
[JBAOP-278] Make AbstractAnnotationMetaData use correct classloader when loading annotation type class

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAnnotationMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAnnotationMetaData.java	2007-07-18 11:39:44 UTC (rev 64113)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAnnotationMetaData.java	2007-07-18 11:54:34 UTC (rev 64114)
@@ -81,6 +81,11 @@
 
    public Annotation getAnnotationInstance()
    {
+      return getAnnotationInstance(null);
+   }   
+   
+   public Annotation getAnnotationInstance(ClassLoader cl)
+   {
       try
       {
          String annString = annotation;
@@ -88,14 +93,17 @@
          {
             annString = StringPropertyReplacer.replaceProperties(annString);
          }
-         //FIXME [JBMICROCONT-99] [JBAOP-278] Use the loader for the bean?
-         ann = (Annotation)AnnotationCreator.createAnnotation(annString, Thread.currentThread().getContextClassLoader());
+         if (cl == null) 
+         {
+            cl = Thread.currentThread().getContextClassLoader();
+         }
+         ann = (Annotation)AnnotationCreator.createAnnotation(annString, cl);
       }
-      catch (Exception e)
+      catch(TokenMgrError e)
       {
          throw new RuntimeException("Error creating annotation for " + annotation, e);
       }
-      catch(TokenMgrError e)
+      catch (Throwable e)
       {
          throw new RuntimeException("Error creating annotation for " + annotation, e);
       }

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/AnnotationMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/AnnotationMetaData.java	2007-07-18 11:39:44 UTC (rev 64113)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/AnnotationMetaData.java	2007-07-18 11:54:34 UTC (rev 64114)
@@ -33,5 +33,16 @@
  */
 public interface AnnotationMetaData extends JBossInterface, MetaDataVisitorNode
 {
+   /**
+    * Get the annotation using passed in classloader
+    * @param classloader The classloader
+    * @return The annotation instance
+    */
+   Annotation getAnnotationInstance(ClassLoader classloader);
+
+   /**
+    * Get the annotation using the thread context classloader
+    * @return The annotation instance
+    */
    Annotation getAnnotationInstance();
 }

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/metadata/basic/BasicKernelMetaDataRepository.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/metadata/basic/BasicKernelMetaDataRepository.java	2007-07-18 11:39:44 UTC (rev 64113)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/metadata/basic/BasicKernelMetaDataRepository.java	2007-07-18 11:54:34 UTC (rev 64114)
@@ -29,6 +29,7 @@
 import org.jboss.beans.metadata.spi.AnnotationMetaData;
 import org.jboss.beans.metadata.spi.BeanMetaData;
 import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.kernel.plugins.config.Configurator;
 import org.jboss.kernel.plugins.metadata.AbstractKernelMetaDataRepository;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.metadata.plugins.context.AbstractMetaDataContext;
@@ -186,7 +187,17 @@
    {
       BeanMetaData beanMetaData = context.getBeanMetaData();
       if (beanMetaData != null)
-         addAnnotations(mutable, beanMetaData.getAnnotations());
+      {
+         try
+         {
+            ClassLoader cl = Configurator.getClassLoader(beanMetaData);
+            addAnnotations(cl, mutable, beanMetaData.getAnnotations());
+         }
+         catch(Throwable t)
+         {
+            throw new RuntimeException("Error getting classloader for metadata");
+         }
+      }
    }
 
    /**
@@ -210,8 +221,16 @@
       if (beanInfo == null)
          return;
       
-      for (PropertyMetaData property : properties)
-         addPropertyAnnotations(mutable, property, beanInfo);
+      try
+      {
+         ClassLoader cl = Configurator.getClassLoader(beanMetaData);
+         for (PropertyMetaData property : properties)
+            addPropertyAnnotations(cl, mutable, property, beanInfo);
+      }
+      catch(Throwable t)
+      {
+         throw new RuntimeException("Error getting classloader for metadata");
+      }
    }
 
    /**
@@ -221,7 +240,7 @@
     * @param propertyMetaData the property
     * @param beanInfo the bean info
     */
-   private void addPropertyAnnotations(MemoryMetaDataLoader mutable, PropertyMetaData propertyMetaData, BeanInfo beanInfo)
+   private void addPropertyAnnotations(ClassLoader classloader, MemoryMetaDataLoader mutable, PropertyMetaData propertyMetaData, BeanInfo beanInfo)
    {
       Set<AnnotationMetaData> propertyAnnotations = propertyMetaData.getAnnotations();
       if (propertyAnnotations == null || propertyAnnotations.size() == 0)
@@ -236,10 +255,10 @@
             {
                MethodInfo methodInfo = propertyInfo.getGetter();
                if (methodInfo != null)
-                  addAnnotations(mutable, methodInfo, propertyAnnotations);
+                  addAnnotations(classloader, mutable, methodInfo, propertyAnnotations);
                methodInfo = propertyInfo.getSetter();
                if (methodInfo != null)
-                  addAnnotations(mutable, methodInfo, propertyAnnotations);
+                  addAnnotations(classloader, mutable, methodInfo, propertyAnnotations);
             }
          }
       }
@@ -252,7 +271,7 @@
     * @param methodInfo the method info
     * @param annotations the annotations
     */
-   private void addAnnotations(MemoryMetaDataLoader mutable, MethodInfo methodInfo, Set<AnnotationMetaData> annotations)
+   private void addAnnotations(ClassLoader classloader, MemoryMetaDataLoader mutable, MethodInfo methodInfo, Set<AnnotationMetaData> annotations)
    {
       TypeInfo[] typeInfos = methodInfo.getParameterTypes();
       String[] paramTypes = new String[typeInfos.length];
@@ -261,7 +280,7 @@
 
       ScopeKey scope = new ScopeKey(CommonLevels.JOINPOINT_OVERRIDE, methodInfo.getName());
       MemoryMetaDataLoader loader = new MemoryMetaDataLoader(scope);
-      addAnnotations(loader, annotations);
+      addAnnotations(classloader, loader, annotations);
       mutable.addComponentMetaDataRetrieval(new MethodSignature(methodInfo.getName(), paramTypes), loader);
    }
    
@@ -271,12 +290,12 @@
     * @param mutable the mutable metadata
     * @param annotations the annotations
     */
-   private void addAnnotations(MemoryMetaDataLoader mutable, Set<AnnotationMetaData> annotations)
+   private void addAnnotations(ClassLoader classloader, MemoryMetaDataLoader mutable, Set<AnnotationMetaData> annotations)
    {
       if (annotations == null || annotations.size() == 0)
          return;
 
       for (AnnotationMetaData annotation : annotations)
-         mutable.addAnnotation(annotation.getAnnotationInstance());
+         mutable.addAnnotation(annotation.getAnnotationInstance(classloader));
    }
 }




More information about the jboss-cvs-commits mailing list