geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: rev 47628 - in geronimo/trunk/modules: j2ee/src/java/org/apache/geronimo/j2ee/deployment j2ee/src/test/org/apache/geronimo/j2ee/deployment naming/src/java/org/apache/geronimo/naming/deployment
Date Fri, 01 Oct 2004 05:13:02 GMT
Author: dain
Date: Thu Sep 30 22:13:01 2004
New Revision: 47628

Added:
   geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefInfo.java
   geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/UnresolvedEJBRefException.java
Modified:
   geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefContext.java
   geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
Log:
http://issues.apache.org/jira/browse/GERONIMO-340
Add support for ejb-ref resolution by matching on the ejb interfaces


Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefContext.java
==============================================================================
--- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefContext.java
(original)
+++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefContext.java
Thu Sep 30 22:13:01 2004
@@ -32,12 +32,14 @@
     private final EJBReferenceBuilder ejbReferenceBuilder;
     private final Map ejbRemoteIndex;
     private final Map ejbLocalIndex;
+    private final Map ejbInterfaceIndex;
 
     public EJBRefContext(EJBReferenceBuilder ejbReferenceBuilder) {
         assert ejbReferenceBuilder != null: "ejbReferenceBuilder is null";
 
         ejbRemoteIndex = new HashMap();
         ejbLocalIndex = new HashMap();
+        ejbInterfaceIndex = new HashMap();
         this.ejbReferenceBuilder = ejbReferenceBuilder;
     }
 
@@ -48,6 +50,7 @@
         this.ejbReferenceBuilder = ejbReferenceBuilder;
         this.ejbRemoteIndex = ejbRefContext.ejbRemoteIndex;
         this.ejbLocalIndex = ejbRefContext.ejbLocalIndex;
+        this.ejbInterfaceIndex = ejbRefContext.ejbInterfaceIndex;
     }
 
     public EJBReferenceBuilder getEjbReferenceBuilder() {
@@ -62,28 +65,46 @@
         return ejbLocalIndex;
     }
 
-    public void addEJBRemoteId(URI modulePath, String name, String containerId) throws DeploymentException
{
+    public void addEJBRemoteId(URI modulePath, String name, String containerId, boolean isSession,
String home, String remote) throws DeploymentException {
         Map references = (Map) ejbRemoteIndex.get(name);
         if (references == null || references.isEmpty()) {
             references = new HashMap();
             ejbRemoteIndex.put(name, references);
         }
-        addEJBId(modulePath, name, containerId, references);
+
+        EJBRefInfo ejbRefInfo = new EJBRefInfo(false, isSession, home, remote);
+        Map interfacesReferences = (Map) ejbInterfaceIndex.get(ejbRefInfo);
+        if (interfacesReferences == null || interfacesReferences.isEmpty()) {
+            interfacesReferences = new HashMap();
+            ejbInterfaceIndex.put(ejbRefInfo, interfacesReferences);
+        }
+
+        addEJBId(modulePath, name, containerId, references, interfacesReferences);
     }
 
-    public void addEJBLocalId(URI modulePath, String name, String containerId) throws DeploymentException
{
+    public void addEJBLocalId(URI modulePath, String name, String containerId, boolean isSession,
String localHome, String local) throws DeploymentException {
         Map references = (Map) ejbLocalIndex.get(name);
         if (references == null || references.isEmpty()) {
             references = new HashMap();
             ejbLocalIndex.put(name, references);
         }
-        addEJBId(modulePath, name, containerId, references);
+
+        EJBRefInfo ejbRefInfo = new EJBRefInfo(true, isSession, localHome, local);
+        Map interfacesReferences = (Map) ejbInterfaceIndex.get(ejbRefInfo);
+        if (interfacesReferences == null || interfacesReferences.isEmpty()) {
+            interfacesReferences = new HashMap();
+            ejbInterfaceIndex.put(ejbRefInfo, interfacesReferences);
+        }
+
+        addEJBId(modulePath, name, containerId, references, interfacesReferences);
     }
 
-    private void addEJBId(URI modulePath, String name, String containerId, Map references)
throws DeploymentException {
+    private void addEJBId(URI modulePath, String name, String containerId, Map references,
Map interfacesReferences) throws DeploymentException {
         try {
             URI ejbURI = new URI(null, null, modulePath.getPath(), name);
             references.put(ejbURI, containerId);
+            URI moduelURI = new URI(null, null, modulePath.getPath(), null);
+            interfacesReferences.put(moduelURI, containerId);
         } catch (URISyntaxException e) {
             throw new DeploymentException(e);
         }
@@ -152,4 +173,40 @@
         // there is more then one ejb with the specifiec name
         throw new AmbiguousEJBRefException(ejbLink);
     }
+
+    public Reference getImplicitEJBRemoteRef(URI module, String refName, boolean isSession,
String home, String remote) throws DeploymentException {
+        EJBRefInfo ejbRefInfo = new EJBRefInfo(false, isSession, home, remote);
+        String containerId = getImplicitContainerId(module, refName, ejbRefInfo);
+        return getEJBRemoteRef(containerId, isSession, home, remote);
+    }
+
+    public Reference getImplicitEJBLocalRef(URI module, String refName, boolean isSession,
String localHome, String local) throws DeploymentException {
+        EJBRefInfo ejbRefInfo = new EJBRefInfo(true, isSession, localHome, local);
+        String containerId = getImplicitContainerId(module, refName, ejbRefInfo);
+        return getEJBLocalRef(containerId, isSession, localHome, local);
+    }
+
+    private String getImplicitContainerId(URI module, String refName, EJBRefInfo ejbRefInfo)
throws DeploymentException {
+        Map references = (Map) ejbInterfaceIndex.get(ejbRefInfo);
+
+        // if we didn't find any ejbs that implement that interface... give up
+        if (references == null || references.isEmpty()) {
+            throw new UnresolvedEJBRefException(refName, ejbRefInfo, false);
+        }
+
+        // if there is only one matching ejb, use it
+        if (references.size() == 1) {
+            return (String) references.values().iterator().next();
+        }
+
+        // We got more then one matching ejb.  Try to find an ejb in the current module
+        String ejbRef = (String) references.get(module);
+        if (ejbRef != null) {
+            return ejbRef;
+        }
+
+        // there is more then one ejb that implements that interface... give up
+        throw new UnresolvedEJBRefException(refName, ejbRefInfo, true);
+    }
+
 }

Added: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefInfo.java
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefInfo.java
Thu Sep 30 22:13:01 2004
@@ -0,0 +1,74 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.j2ee.deployment;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public final class EJBRefInfo {
+    private final boolean isLocal;
+    private final boolean isSession;
+    private final String homeIntf;
+    private final String beanIntf;
+
+    public EJBRefInfo(boolean local, boolean session, String homeIntf, String beanIntf) {
+        assert homeIntf != null: "homeIntf is null";
+        assert beanIntf != null: "beanIntf is null";
+        isLocal = local;
+        isSession = session;
+        this.homeIntf = homeIntf;
+        this.beanIntf = beanIntf;
+    }
+
+    public boolean isLocal() {
+        return isLocal;
+    }
+
+    public boolean isSession() {
+        return isSession;
+    }
+
+    public String getHomeIntf() {
+        return homeIntf;
+    }
+
+    public String getBeanIntf() {
+        return beanIntf;
+    }
+
+    public boolean equals(Object object) {
+        if (!(object instanceof EJBRefInfo)) {
+            return false;
+        }
+
+        // match isSession
+        EJBRefInfo ejbRefInfo = (EJBRefInfo) object;
+        return ejbRefInfo.isLocal == isLocal &&
+                ejbRefInfo.isSession == isSession &&
+                ejbRefInfo.homeIntf.equals(homeIntf) &&
+                ejbRefInfo.beanIntf.equals(beanIntf);
+    }
+
+    public int hashCode() {
+        int result = 17;
+        result = 37 * result + (isLocal ? 1 : 0);
+        result = 37 * result + (isSession ? 1 : 0);
+        result = 37 * result + homeIntf.hashCode();
+        result = 37 * result + beanIntf.hashCode();
+        return result;
+    }
+}

Added: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/UnresolvedEJBRefException.java
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/UnresolvedEJBRefException.java
Thu Sep 30 22:13:01 2004
@@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.j2ee.deployment;
+
+import org.apache.geronimo.deployment.DeploymentException;
+
+/**
+ * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
+ */
+public class UnresolvedEJBRefException extends DeploymentException {
+    private final String refName;
+    private final EJBRefInfo ejbRefInfo;
+
+    public UnresolvedEJBRefException(String refName, EJBRefInfo ejbRefInfo, boolean foundMultiple)
{
+        super(createMessage(refName, ejbRefInfo, foundMultiple));
+        this.refName = refName;
+        this.ejbRefInfo = ejbRefInfo;
+    }
+
+    public String getRefName() {
+        return refName;
+    }
+
+    public EJBRefInfo getEjbRefInfo() {
+        return ejbRefInfo;
+    }
+
+    private static String createMessage(String refName, EJBRefInfo ejbRefInfo, boolean foundMultiple)
{
+        StringBuffer msg = new StringBuffer();
+        if (foundMultiple) {
+            msg.append("Two or more EJBs were found");
+        } else {
+            msg.append("Could not find an EJB");
+        }
+        msg.append(" for reference ").append(refName).append(" to a ");
+        msg.append((ejbRefInfo.isLocal() ? "local " : "remote "));
+        msg.append((ejbRefInfo.isSession() ? "session " : "entity "));
+
+        msg.append(" bean that has the home interface ").append(ejbRefInfo.getHomeIntf());
+        msg.append(" and the ").append(ejbRefInfo.isLocal() ? "local" : "remote");
+        msg.append(" interface ").append(ejbRefInfo.getBeanIntf());
+
+        return msg.toString();
+    }
+}

Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java
==============================================================================
--- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java
(original)
+++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java
Thu Sep 30 22:13:01 2004
@@ -124,6 +124,34 @@
         }
     }
 
+    public void testBasicImplicitRefs() throws Exception {
+        assertReferenceEqual(language_lisp, ejbRefContext.getImplicitEJBRemoteRef(coffee,
"blah", true, "LispHome", "LispRemote"));
+        assertReferenceEqual(language_lisp_local, ejbRefContext.getImplicitEJBLocalRef(coffee,
"blah", true, "LispLocalHome", "LispLocal"));
+    }
+
+    public void testInModuleImplicitRefs() throws Exception {
+        assertReferenceEqual(coffee_java_local, ejbRefContext.getImplicitEJBLocalRef(coffee,
"blah", true, "LocalHome", "Local"));
+        assertReferenceEqual(car_enzo_local, ejbRefContext.getImplicitEJBLocalRef(car, "blah",
true, "LocalHome", "Local"));
+    }
+
+    public void testAmbiguousModuleImplicitRefs() throws Exception {
+        try {
+            ejbRefContext.getImplicitEJBLocalRef(language, "blah", true, "LocalHome", "Local");
+            fail("should have thrown an UnresolvedEJBRefException");
+        } catch (UnresolvedEJBRefException e) {
+            // good
+        }
+    }
+
+    public void testNoMatchImplicitRefs() throws Exception {
+        try {
+            ejbRefContext.getImplicitEJBLocalRef(language, "blah", true, "foo", "bar");
+            fail("should have thrown an UnresolvedEJBRefException");
+        } catch (UnresolvedEJBRefException e) {
+            // good
+        }
+    }
+
     protected void setUp() throws Exception {
         carFile = File.createTempFile("EARTest", ".car");
         ejbRefContext = new EJBRefContext(new EJBReferenceBuilder() {
@@ -136,20 +164,20 @@
             }
         });
 
-        ejbRefContext.addEJBRemoteId(coffee, "peaberry", coffee_peaberry);
-        ejbRefContext.addEJBLocalId(coffee, "peaberry", coffee_peaberry_local);
-        ejbRefContext.addEJBRemoteId(coffee, "java", coffee_java);
-        ejbRefContext.addEJBLocalId(coffee, "java", coffee_java_local);
-
-        ejbRefContext.addEJBRemoteId(language, "lisp", language_lisp);
-        ejbRefContext.addEJBLocalId(language, "lisp", language_lisp_local);
-        ejbRefContext.addEJBRemoteId(language, "java", language_java);
-        ejbRefContext.addEJBLocalId(language, "java", language_java_local);
-
-        ejbRefContext.addEJBRemoteId(car, "gt", car_gt);
-        ejbRefContext.addEJBLocalId(car, "gt", car_gt_local);
-        ejbRefContext.addEJBRemoteId(car, "enzo", car_enzo);
-        ejbRefContext.addEJBLocalId(car, "enzo", car_enzo_local);
+        ejbRefContext.addEJBRemoteId(coffee, "peaberry", coffee_peaberry, true, "CoffeeHome",
"CoffeeRemote");
+        ejbRefContext.addEJBLocalId(coffee, "peaberry", coffee_peaberry_local, true, "CoffeeLocalHome",
"CoffeeLocal");
+        ejbRefContext.addEJBRemoteId(coffee, "java", coffee_java, true, "CoffeeHome", "CoffeeRemote");
+        ejbRefContext.addEJBLocalId(coffee, "java", coffee_java_local, true, "LocalHome",
"Local");
+
+        ejbRefContext.addEJBRemoteId(language, "lisp", language_lisp, true, "LispHome", "LispRemote");
+        ejbRefContext.addEJBLocalId(language, "lisp", language_lisp_local, true, "LispLocalHome",
"LispLocal");
+        ejbRefContext.addEJBRemoteId(language, "java", language_java, true, "JavaHome", "JavaRemote");
+        ejbRefContext.addEJBLocalId(language, "java", language_java_local, true, "JavaLocalHome",
"JavaLocal");
+
+        ejbRefContext.addEJBRemoteId(car, "gt", car_gt, true, "GTHome", "GTRemote");
+        ejbRefContext.addEJBLocalId(car, "gt", car_gt_local, true, "GTLocalHome", "GTLocalRemote");
+        ejbRefContext.addEJBRemoteId(car, "enzo", car_enzo, true, "EnzoHome", "EnzoRemote");
+        ejbRefContext.addEJBLocalId(car, "enzo", car_enzo_local, true, "LocalHome", "Local");
     }
 
     protected void tearDown() throws Exception {

Modified: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
==============================================================================
--- geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
(original)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
Thu Sep 30 22:13:01 2004
@@ -20,6 +20,7 @@
 import java.net.URI;
 import java.util.Map;
 import javax.naming.NamingException;
+import javax.naming.Reference;
 import javax.transaction.UserTransaction;
 
 import org.apache.geronimo.deployment.DeploymentException;
@@ -154,21 +155,18 @@
                 ejbLink = getJ2eeStringValue(ejbRef.getEjbLink());
             }
 
+            Reference ejbReference;
             if (ejbLink != null) {
-                try {
-                    builder.bind(ejbRefName, ejbRefContext.getEJBRemoteRef(uri, ejbLink,
isSession, home, remote));
-                } catch (NamingException e) {
-                    throw new DeploymentException("Unable to to bind ejb-ref: ejb-ref-name="
+ ejbRefName);
-                }
+                ejbReference = ejbRefContext.getEJBRemoteRef(uri, ejbLink, isSession, home,
remote);
+            } else if (remoteRef != null) {
+                ejbReference = ejbRefContext.getEJBRemoteRef(remoteRef.getTargetName(), isSession,
home, remote);
             } else {
-                if (remoteRef == null) {
-                    throw  new DeploymentException("No geronimo configuration for resource
ref named: " + ejbRefName);
-                }
-                try {
-                    builder.bind(ejbRefName, ejbRefContext.getEJBRemoteRef(remoteRef.getTargetName(),
isSession, home, remote));
-                } catch (NamingException e) {
-                    throw new DeploymentException("Invalid env-entry definition for name:
" + ejbRefName, e);
-                }
+                ejbReference = ejbRefContext.getImplicitEJBRemoteRef(uri, ejbRefName, isSession,
home, remote);
+            }
+            try {
+                builder.bind(ejbRefName, ejbReference);
+            } catch (NamingException e) {
+                throw new DeploymentException("Unable to to bind ejb-ref: ejb-ref-name="
+ ejbRefName);
             }
         }
     }
@@ -196,24 +194,19 @@
                 ejbLink = getJ2eeStringValue(ejbLocalRef.getEjbLink());
             }
 
+            Reference ejbReference;
             if (ejbLink != null) {
-                try {
-                    builder.bind(ejbRefName, ejbRefContext.getEJBLocalRef(uri, ejbLink, isSession,
localHome, local));
-                } catch (NamingException e) {
-                    throw new DeploymentException("Unable to to bind ejb-local-ref: ejb-ref-name="
+ ejbRefName);
-                }
+                ejbReference = ejbRefContext.getEJBLocalRef(uri, ejbLink, isSession, localHome,
local);
+            } else if (localRef != null) {
+                ejbReference = ejbRefContext.getEJBLocalRef(localRef.getTargetName(), isSession,
localHome, local);
             } else {
-                if (localRef == null) {
-                    throw  new DeploymentException("No geronimo configuration for resource
ref named: " + ejbRefName);
-                }
-                try {
-                    builder.bind(ejbRefName, ejbRefContext.getEJBLocalRef(localRef.getTargetName(),
isSession, localHome, local));
-                } catch (NamingException e) {
-                    throw new DeploymentException("Invalid env-entry definition for name:
" + ejbRefName, e);
-                }
+                ejbReference = ejbRefContext.getImplicitEJBLocalRef(uri, ejbLink, isSession,
localHome, local);
+            }
+            try {
+                builder.bind(ejbRefName, ejbReference);
+            } catch (NamingException e) {
+                throw new DeploymentException("Unable to to bind ejb-local-ref: ejb-ref-name="
+ ejbRefName);
             }
-
-
         }
     }
 

Mime
View raw message