[jboss-cvs] JBossAS SVN: r94871 - projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 14 11:10:33 EDT 2009


Author: flavia.rainone at jboss.com
Date: 2009-10-14 11:10:32 -0400 (Wed, 14 Oct 2009)
New Revision: 94871

Modified:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
Log:
[JBREFLECT-60] The Class<?> parameter of JavassistTypeInfoFactoryImpl method is now passed along to the JavassistTypeInfo created object.

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2009-10-14 14:45:36 UTC (rev 94870)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2009-10-14 15:10:32 UTC (rev 94871)
@@ -186,7 +186,7 @@
       }
    }
    
-   protected Object instantiate(CtClass ctClass)
+   protected Object instantiate(CtClass ctClass, Class<?> clazz)
    {
       try
       {
@@ -194,12 +194,12 @@
          if (ctClass.isArray())
          {
             TypeInfo componentType = getTypeInfo(ctClass.getComponentType());
-            return new JavassistArrayInfoImpl(this, ctClass, null, componentType);
+            return new JavassistArrayInfoImpl(this, ctClass, clazz, componentType);
          }
 
          if (ctClass.isAnnotation())
          {
-            JavassistAnnotationInfo result = new JavassistAnnotationInfo(this, ctClass, null);
+            JavassistAnnotationInfo result = new JavassistAnnotationInfo(this, ctClass, clazz);
             CtMethod[] methods = ctClass.getDeclaredMethods();
             AnnotationAttributeImpl[] atttributes = new AnnotationAttributeImpl[methods.length];
             for (int i = 0 ; i < methods.length ; i++)
@@ -212,7 +212,7 @@
          }
          else if (ctClass.isEnum())
          {
-            JavassistEnumInfo enumInfo = new JavassistEnumInfo(this, ctClass, null);
+            JavassistEnumInfo enumInfo = new JavassistEnumInfo(this, ctClass, clazz);
             CtField[] fields = ctClass.getFields();
             EnumConstantInfoImpl[] constants = new EnumConstantInfoImpl[fields.length];
             int i = 0;
@@ -226,7 +226,7 @@
          }
 
 
-         return new JavassistTypeInfo(this, ctClass, null);
+         return new JavassistTypeInfo(this, ctClass, clazz);
       }
       catch (NotFoundException e)
       {
@@ -253,7 +253,7 @@
       {
          CtClass clazz = poolFactory.getPoolForLoader(cl).get(name);
 
-         return get(clazz);
+         return get(clazz, null);
       }
       catch(NotFoundException nfe)
       {
@@ -264,7 +264,34 @@
    /**
     * Get the information for a class
     * 
+    * @param name the name
+    * @param cl the classloader
+    * @param clazz
+    * @return the info
+    * @throws ClassNotFoundException when the class cannot be found
+    */
+   public Object get(String name, ClassLoader cl, Class<?> clazz) throws ClassNotFoundException
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+      if (cl == null)
+         throw new IllegalArgumentException("Null classloader");
+      try
+      {
+         CtClass ctClass = poolFactory.getPoolForLoader(cl).get(name);
+
+         return get(ctClass, clazz);
+      }
+      catch(NotFoundException nfe)
+      {
+         throw new ClassNotFoundException(nfe.getMessage());
+      }
+   }
+   
+   /**
+    * Get the information for a class
     * 
+    * 
     * @param clazz the class
     * @return the info
     */
@@ -277,7 +304,7 @@
          ClassLoader cl = clazz.getClassLoader();
          if(cl == null)
             cl = Thread.currentThread().getContextClassLoader();
-         return get(clazz.getName(), cl);
+         return get(clazz.getName(), cl, clazz);
       }
       catch (ClassNotFoundException e)
       {
@@ -289,37 +316,37 @@
    /**
     * Get the information for a class
     * 
-    * @param clazz the class
+    * @param ctClass the class
     * @return the info
     */
-   public Object get(CtClass clazz)
+   public Object get(CtClass ctClass, Class<?> clazz)
    {
-      if (clazz == null)
+      if (ctClass == null)
          throw new IllegalArgumentException("Null class");
-      if(clazz instanceof CtPrimitiveType)
-         return instantiate(clazz);
+      if(ctClass instanceof CtPrimitiveType)
+         return instantiate(ctClass, clazz);
       
-      Map<String, WeakReference<Object>> classLoaderCache = getClassLoaderCache(clazz.getClassPool().getClassLoader());
+      Map<String, WeakReference<Object>> classLoaderCache = getClassLoaderCache(ctClass.getClassPool().getClassLoader());
 
-      WeakReference<Object> weak = (WeakReference<Object>) classLoaderCache.get(clazz.getName());
+      WeakReference<Object> weak = (WeakReference<Object>) classLoaderCache.get(ctClass.getName());
       if (weak != null)
       {
          Object result = weak.get();
          if (result != null)
          {
-            if(compare(clazz, (ClassInfo) result))
+            if(compare(ctClass, (ClassInfo) result))
                return result;
             else
             {
-               classLoaderCache.remove(clazz.getName());
+               classLoaderCache.remove(ctClass.getName());
             }
          }
       }
 
-      Object result = instantiate(clazz);
+      Object result = instantiate(ctClass, clazz);
       
       weak = new WeakReference<Object>(result);
-      classLoaderCache.put(clazz.getName(), weak);
+      classLoaderCache.put(ctClass.getName(), weak);
       
 //      we just ignore generate(..) since it doesnt do anything atm
 //      generate(clazz, result);




More information about the jboss-cvs-commits mailing list