[seam-commits] Seam SVN: r8290 - in tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam: init and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue May 27 13:50:04 EDT 2008


Author: jbalunas at redhat.com
Date: 2008-05-27 13:50:04 -0400 (Tue, 27 May 2008)
New Revision: 8290

Modified:
   tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/Seam.java
   tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/init/DeploymentDescriptor.java
Log:
Port of JBSEAM-2917 to 2.0.2.SP1

Modified: tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/Seam.java
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/Seam.java	2008-05-27 17:11:11 UTC (rev 8289)
+++ tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/Seam.java	2008-05-27 17:50:04 UTC (rev 8290)
@@ -11,7 +11,9 @@
 import static org.jboss.seam.util.EJB.STATELESS;
 import static org.jboss.seam.util.EJB.name;
 
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.persistence.Entity;
@@ -35,30 +37,35 @@
  */
 public class Seam
 {
-    
    private static final Map<Class, String> COMPONENT_NAME_CACHE = new ConcurrentHashMap<Class, String>();
-   private static final Map<String, EjbDescriptor> EJB_DESCRIPTOR_CACHE = new ConcurrentHashMap<String, EjbDescriptor>();
+   private static final Map<Class, EjbDescriptor> EJB_DESCRIPTOR_CACHE = new ConcurrentHashMap<Class, EjbDescriptor>();
+   private static final Set<ClassLoader> CLASSLOADERS_LOADED = new HashSet<ClassLoader>(); 
 
-   public static EjbDescriptor getEjbDescriptor(String className)
+   public static EjbDescriptor getEjbDescriptor(Class clazz)
    {
-      EjbDescriptor info = EJB_DESCRIPTOR_CACHE.get(className);
+      EjbDescriptor info = EJB_DESCRIPTOR_CACHE.get(clazz);
       if (info != null) 
       {
           return info;
       }
-      else
+      else if (!CLASSLOADERS_LOADED.contains(clazz.getClassLoader()))
       {
-         Map<String, EjbDescriptor> ejbDescriptors = new DeploymentDescriptor().getEjbDescriptors();
-         EJB_DESCRIPTOR_CACHE.putAll(ejbDescriptors);
-         return ejbDescriptors.get(className);
+         cacheEjbDescriptors(clazz);
+         return EJB_DESCRIPTOR_CACHE.get(clazz);
       }
+      
+      return null;
    }
    
-   // TODO Better impl
-   static EjbDescriptor getEjbDescriptor(Class clazz)
+   private synchronized static void cacheEjbDescriptors(Class clazz)
    {
-      return getEjbDescriptor(clazz.getName());
-   }
+      if (!CLASSLOADERS_LOADED.contains(clazz.getClassLoader()))
+      {         
+         Map<Class, EjbDescriptor> ejbDescriptors = new DeploymentDescriptor(clazz).getEjbDescriptors();
+         EJB_DESCRIPTOR_CACHE.putAll(ejbDescriptors);
+         CLASSLOADERS_LOADED.add(clazz.getClassLoader());         
+      }
+   } 
   
    /**
     * Get the default scope
@@ -161,7 +168,7 @@
          }
          else
          {
-            EjbDescriptor ejbDescriptor = Seam.getEjbDescriptor(clazz.getName());
+            EjbDescriptor ejbDescriptor = Seam.getEjbDescriptor(clazz);
             if (ejbDescriptor != null)
             {
                return ejbDescriptor.getBeanType() == ComponentType.ENTITY_BEAN ? clazz : null;

Modified: tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/init/DeploymentDescriptor.java
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/init/DeploymentDescriptor.java	2008-05-27 17:11:11 UTC (rev 8289)
+++ tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/init/DeploymentDescriptor.java	2008-05-27 17:50:04 UTC (rev 8290)
@@ -23,10 +23,16 @@
 { 
     private static final LogProvider log = Logging.getLogProvider(Initialization.class);
     
-    private Map<String, EjbDescriptor> ejbDescriptors = new HashMap<String, EjbDescriptor>();
+    private Map<Class, EjbDescriptor> ejbDescriptors = new HashMap<Class, EjbDescriptor>();
+    private Class componentClass;
 
-    public DeploymentDescriptor() 
+    public DeploymentDescriptor(Class clazz) 
     {
+       componentClass = clazz;
+       if (clazz.getClassLoader() == null) {
+           return;
+       }       
+       
         try 
         {
             InputStream ejbJarXml = Resources.getResourceAsStream("META-INF/ejb-jar.xml", null);
@@ -54,7 +60,7 @@
         }
     }
     
-    public Map<String, EjbDescriptor> getEjbDescriptors()
+    public Map<Class, EjbDescriptor> getEjbDescriptors()
     {
        return ejbDescriptors;
     }
@@ -197,6 +203,14 @@
 
     protected void add(EjbDescriptor descriptor) 
     {
-       ejbDescriptors.put(descriptor.getEjbClassName(), descriptor);
+       try
+       {
+          Class ejbClass = componentClass.getClassLoader().loadClass( descriptor.getEjbClassName() );
+          ejbDescriptors.put(ejbClass, descriptor);
+       }
+       catch (ClassNotFoundException cnfe)
+       {
+          log.warn("Could not load EJB class: " + descriptor.getEjbClassName());
+       }
     }
 }




More information about the seam-commits mailing list