Author: shane.bryzak(a)jboss.com
Date: 2008-05-24 06:09:54 -0400 (Sat, 24 May 2008)
New Revision: 8277
Modified:
branches/Seam_2_0/src/main/org/jboss/seam/Seam.java
branches/Seam_2_0/src/main/org/jboss/seam/init/DeploymentDescriptor.java
Log:
backported JBSEAM-2917
Modified: branches/Seam_2_0/src/main/org/jboss/seam/Seam.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/Seam.java 2008-05-23 20:30:05 UTC (rev
8276)
+++ branches/Seam_2_0/src/main/org/jboss/seam/Seam.java 2008-05-24 10:09:54 UTC (rev
8277)
@@ -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,28 @@
*/
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)
+ 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 (clazz.getClassLoader() == null ||
+ (clazz.getClassLoader() != null &&
!CLASSLOADERS_LOADED.contains(clazz.getClassLoader())))
{
- Map<String, EjbDescriptor> ejbDescriptors = new
DeploymentDescriptor().getEjbDescriptors();
+ Map<Class, EjbDescriptor> ejbDescriptors = new
DeploymentDescriptor(clazz).getEjbDescriptors();
EJB_DESCRIPTOR_CACHE.putAll(ejbDescriptors);
- return ejbDescriptors.get(className);
+ CLASSLOADERS_LOADED.add(clazz.getClassLoader());
+ return ejbDescriptors.get(clazz);
}
+
+ return null;
}
-
- // TODO Better impl
- static EjbDescriptor getEjbDescriptor(Class clazz)
- {
- return getEjbDescriptor(clazz.getName());
- }
/**
* Get the default scope
@@ -161,7 +161,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: branches/Seam_2_0/src/main/org/jboss/seam/init/DeploymentDescriptor.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/init/DeploymentDescriptor.java 2008-05-23
20:30:05 UTC (rev 8276)
+++ branches/Seam_2_0/src/main/org/jboss/seam/init/DeploymentDescriptor.java 2008-05-24
10:09:54 UTC (rev 8277)
@@ -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());
+ }
}
}