Title: [2636] branches/v2_1/openejb2/modules/core/src/java/org/openejb: simplify jndi lookup logic slightly
Revision
2636
Author
djencks
Date
2006-05-01 15:10:59 -0400 (Mon, 01 May 2006)

Log Message

simplify jndi lookup logic slightly

Modified Paths


Diff

Modified: branches/v2_1/openejb2/modules/core/src/java/org/openejb/ContainerIndex.java (2635 => 2636)

--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/ContainerIndex.java	2006-05-01 01:03:26 UTC (rev 2635)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/ContainerIndex.java	2006-05-01 19:10:59 UTC (rev 2636)
@@ -45,15 +45,16 @@
 package org.openejb;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
@@ -148,11 +149,12 @@
         jndiNameToIndex.clear();
     }
 
-    public synchronized void addContainer(EJBContainer container) {
+    public synchronized Integer addContainer(EJBContainer container) {
         container = container.getUnmanagedReference();
         Object containerID = container.getContainerID();
-        if (containerIdToIndex.containsKey(containerID)) {
-            return;
+        Integer index;
+        if ((index = (Integer) containerIdToIndex.get(containerID)) != null) {
+            return index;
         }
 
         int i = containers.length;
@@ -162,8 +164,10 @@
         containers = newArray;
 
         containers[i] = container;
-        containerIdToIndex.put(containerID, new Integer(i));
+        index = new Integer(i);
+        containerIdToIndex.put(containerID, index);
         addJNDINames(container, i);
+        return index;
     }
 
     public synchronized void removeContainer(EJBContainer container) {
@@ -200,16 +204,14 @@
 
         // try to fault in the container using the kernel directly
         if ((index == null)) {
-            AbstractName name;
-            try {
-                name = new AbstractName(new URI(containerID));
-            } catch (URISyntaxException e) {
-                log.error("containerId is not a valid URI: " + containerID);
+            URI uri = URI.create(containerID);
+            AbstractNameQuery abstractNameQuery = new AbstractNameQuery(uri);
+            Set results = kernel.listGBeans(abstractNameQuery);
+            if (results.size() != 1) {
+                log.error( "Name query " + abstractNameQuery + " not satisfied in kernel, matches: " + results);
                 return -1;
-            } catch (IllegalArgumentException e) {
-                //not a valid abstract name
-                return -1;
             }
+            AbstractName name = (AbstractName) results.iterator().next();
             EJBContainer ejbContainer;
             try {
                 ejbContainer = (EJBContainer) kernel.getGBean(name);
@@ -218,11 +220,7 @@
                 log.debug("Container not found: " + containerID, e);
                 return -1;
             }
-            addContainer(ejbContainer);
-            index = (Integer) containerIdToIndex.get(containerID);
-            if (index == null) {
-                log.error("added ejb container to index but index value was null: " + containerID);
-            }
+            index = addContainer(ejbContainer);
         }
 
         if (index == null) {

Modified: branches/v2_1/openejb2/modules/core/src/java/org/openejb/server/ejbd/JndiRequestHandler.java (2635 => 2636)

--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/server/ejbd/JndiRequestHandler.java	2006-05-01 01:03:26 UTC (rev 2635)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/server/ejbd/JndiRequestHandler.java	2006-05-01 19:10:59 UTC (rev 2636)
@@ -174,21 +174,9 @@
         } else {
             int index = containerIndex.getContainerIndexByJndiName(name);
             if (index <= 0) {
-                // name not found... check if an abstract name was sent directly
+                // name not found... check if an abstract name or name query was sent directly
                 index = containerIndex.getContainerIndex(req.getRequestString());
             }
-            if (index <=0) {
-                //treat it as an abstractnameQuery and try to resolve it.  Don't remove a leading /
-                URI uri = URI.create(req.getRequestString());
-                AbstractNameQuery abstractNameQuery = new AbstractNameQuery(uri);
-                Kernel kernel = KernelRegistry.getSingleKernel();
-                Set results = kernel.listGBeans(abstractNameQuery);
-                if (results.size() != 1) {
-                    throw new NamingException("Name query " + abstractNameQuery + " not satisfied in kernel, matches: " + results);
-                }
-                AbstractName target = (AbstractName) results.iterator().next();
-                index = containerIndex.getContainerIndex(target.toString());
-            }
             if (index > 0) {
                 EJBContainer deployment = containerIndex.getContainer(index);
                 ProxyInfo info = deployment.getProxyInfo();

Reply via email to