You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/04/23 07:10:40 UTC

svn commit: r531334 - /incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java

Author: dblevins
Date: Sun Apr 22 22:10:35 2007
New Revision: 531334

URL: http://svn.apache.org/viewvc?view=rev&rev=531334
Log:
new jndi name strategy that uses templates that can be reconfigured

Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java?view=diff&rev=531334&r1=531333&r2=531334
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java Sun Apr 22 22:10:35 2007
@@ -22,14 +22,18 @@
 import javax.jms.MessageListener;
 
 import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.core.CoreDeploymentInfo;
 import org.apache.openejb.core.ivm.naming.BusinessLocalReference;
 import org.apache.openejb.core.ivm.naming.BusinessRemoteReference;
 import org.apache.openejb.core.ivm.naming.ObjectReference;
 import org.apache.openejb.core.ivm.naming.IntraVmJndiReference;
+import org.codehaus.swizzle.stream.StringTemplate;
 
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
 
 
 /**
@@ -42,6 +46,20 @@
 
     public JndiBuilder(Context context) {
         this.context = context;
+
+        String strategyClass = SystemInstance.get().getProperty("openejb.jndiname.strategy.class", LegacyAddedSuffixStrategy.class.getName());
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            strategy = (JndiNameStrategy) classLoader.loadClass(strategyClass).newInstance();
+        } catch (InstantiationException e) {
+            throw new IllegalStateException("Could not instantiate JndiNameStrategy: "+strategyClass, e);
+        } catch (IllegalAccessException e) {
+            throw new IllegalStateException("Could not access JndiNameStrategy: "+strategyClass, e);
+        } catch (ClassNotFoundException e) {
+            throw new IllegalStateException("Could not load JndiNameStrategy: "+strategyClass, e);
+        } catch (Throwable t){
+            throw new IllegalStateException("Could not create JndiNameStrategy: "+strategyClass, t);
+        }
     }
 
     public static interface JndiNameStrategy {
@@ -55,6 +73,30 @@
     }
 
     // TODO: put these into the classpath and get them with xbean-finder
+    public static class TemplatedStrategy implements JndiNameStrategy {
+        private org.codehaus.swizzle.stream.StringTemplate template;
+
+        public TemplatedStrategy() {
+            String format = SystemInstance.get().getProperty("openejb.jndiname.format", "{deploymentId}/{interfaceClass.simpleName}");
+            this.template = new StringTemplate(format);
+        }
+
+
+        public String getName(DeploymentInfo deploymentInfo, Class interfce, Interface type) {
+            Map<String,String> contextData = new HashMap<String,String>();
+            contextData.put("moduleId", deploymentInfo.getModuleID());
+            contextData.put("ejbType", deploymentInfo.getComponentType().name());
+            contextData.put("ejbClass", deploymentInfo.getBeanClass().getName());
+            contextData.put("ejbClass.simpleName", deploymentInfo.getBeanClass().getSimpleName());
+            contextData.put("ejbName", deploymentInfo.getEjbName());
+            contextData.put("deploymentId", deploymentInfo.getDeploymentID().toString());
+            contextData.put("interfaceType", deploymentInfo.getInterfaceType(interfce).name());
+            contextData.put("interfaceClass", interfce.getName());
+            contextData.put("interfaceClass.simpleName", interfce.getSimpleName());
+            return template.apply(contextData);
+        }
+    }
+
     public static class LegacyAddedSuffixStrategy implements JndiNameStrategy {
 
         public String getName(DeploymentInfo deploymentInfo, Class interfce, Interface type) {
@@ -129,7 +171,12 @@
         }
     }
 
+    public JndiNameStrategy getStrategy() {
+        return strategy;
+    }
+
     public void bind(DeploymentInfo deploymentInfo) {
+        JndiNameStrategy strategy = getStrategy();
         CoreDeploymentInfo deployment = (CoreDeploymentInfo) deploymentInfo;
 
         Bindings bindings = new Bindings();
@@ -173,7 +220,13 @@
 
                 for (Class interfce : deployment.getBusinessLocalInterfaces()) {
                     DeploymentInfo.BusinessLocalHome home = deployment.getBusinessLocalHome(asList(interfce));
-                    context.bind("openejb/Deployment/" + deployment.getDeploymentID() + "/" + interfce.getName(), new BusinessLocalReference(home));
+                    BusinessLocalReference ref = new BusinessLocalReference(home);
+                    context.bind("openejb/Deployment/" + deployment.getDeploymentID() + "/" + interfce.getName(), ref);
+                    try {
+                        name = strategy.getName(deployment, interfce, JndiNameStrategy.Interface.BUSINESS_LOCAL);
+                        context.bind("openejb/ejb/" + name, ref);
+                    } catch (NamingException dontCareJustYet) {
+                    }
                 }
             }
         } catch (NamingException e) {
@@ -191,7 +244,14 @@
 
                 for (Class interfce : deployment.getBusinessRemoteInterfaces()) {
                     DeploymentInfo.BusinessRemoteHome home = deployment.getBusinessRemoteHome(asList(interfce));
-                    context.bind("openejb/Deployment/" + deployment.getDeploymentID() + "/" + interfce.getName(), new BusinessRemoteReference(home));
+                    ref = new BusinessRemoteReference(home);
+                    context.bind("openejb/Deployment/" + deployment.getDeploymentID() + "/" + interfce.getName(), ref);
+
+                    try {
+                        name = strategy.getName(deployment, interfce, JndiNameStrategy.Interface.BUSINESS_REMOTE);
+                        context.bind("openejb/ejb/" + name, ref);
+                    } catch (NamingException dontCareJustYet) {
+                    }
                 }
             }
         } catch (NamingException e) {