Author: dain Date: Wed Sep 29 12:27:40 2004 New Revision: 47498 Added: geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java 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 - copied, changed from rev 47409, geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARContextTest.java geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/ClientCommandLine.java Removed: geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/ClientCommandLine.java geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARContextTest.java Modified: geronimo/trunk/modules/assembly/maven.xml geronimo/trunk/modules/assembly/project.xml geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml geronimo/trunk/modules/client-builder/project.xml geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java geronimo/trunk/modules/client/project.xml geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBReferenceBuilder.java geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java Log: Added static app client side jndi tree Moved ClientComandLine to system module and removed client jar from system classpath to resolve class loading issues Moved EJB ref index code from EJBContext to EJBRefContext
Modified: geronimo/trunk/modules/assembly/maven.xml ============================================================================== --- geronimo/trunk/modules/assembly/maven.xml (original) +++ geronimo/trunk/modules/assembly/maven.xml Wed Sep 29 12:27:40 2004 @@ -260,7 +260,7 @@ <ant:arg value="--outfile"/> <ant:arg value="${distDir}/bin/client.jar"/> <ant:arg value="--mainClass"/> - <ant:arg value="org.apache.geronimo.client.ClientCommandLine"/> + <ant:arg value="org.apache.geronimo.system.main.ClientCommandLine"/> <ant:arg value="--classPath"/> <ant:arg value="${client.classpath}"/> </ant:java> Modified: geronimo/trunk/modules/assembly/project.xml ============================================================================== --- geronimo/trunk/modules/assembly/project.xml (original) +++ geronimo/trunk/modules/assembly/project.xml Wed Sep 29 12:27:40 2004 @@ -71,8 +71,6 @@ <artifactId>geronimo-client</artifactId> <version>${pom.currentVersion}</version> <properties> - <lib>true</lib> - <client>true</client> <repository>true</repository> </properties> </dependency> Modified: geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml ============================================================================== --- geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml (original) +++ geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml Wed Sep 29 12:27:40 2004 @@ -63,10 +63,10 @@ <uri>tranql/jars/tranql-${tranql_version}.jar</uri> </dependency> - <gbean name="geronimo.client:type=JNDIContext" class="org.openejb.client.AppClientJNDIContext"> - <attribute name="host" type="java.lang.String">localhost</attribute> - <attribute name="port" type="int">4201</attribute> - </gbean> +<!-- <gbean name="geronimo.client:type=JNDIContext" class="org.openejb.client.AppClientJNDIContext">--> +<!-- <attribute name="host" type="java.lang.String">localhost</attribute>--> +<!-- <attribute name="port" type="int">4201</attribute>--> +<!-- </gbean>--> <!--client connector support--> <gbean name="geronimo.client:type=ThreadPool,name=DefaultThreadPool" class="org.apache.geronimo.pool.ThreadPool"> Modified: geronimo/trunk/modules/client-builder/project.xml ============================================================================== --- geronimo/trunk/modules/client-builder/project.xml (original) +++ geronimo/trunk/modules/client-builder/project.xml Wed Sep 29 12:27:40 2004 @@ -54,6 +54,12 @@ <type>plugin</type> </dependency> + <dependency> + <groupId>openejb</groupId> + <artifactId>openejb-core</artifactId> + <version>&openejb-version;</version> + </dependency> + <!-- needed for xmlbeans runtime--> <dependency> <groupId>xmlbeans</groupId> Modified: geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java ============================================================================== --- geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java (original) +++ geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java Wed Sep 29 12:27:40 2004 @@ -35,6 +35,7 @@ import java.util.jar.Manifest; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import javax.naming.Reference; import org.apache.geronimo.deployment.DeploymentException; import org.apache.geronimo.deployment.service.GBeanHelper; @@ -47,6 +48,8 @@ import org.apache.geronimo.gbean.jmx.GBeanMBean; import org.apache.geronimo.j2ee.deployment.AppClientModule; import org.apache.geronimo.j2ee.deployment.EARContext; +import org.apache.geronimo.j2ee.deployment.EJBRefContext; +import org.apache.geronimo.j2ee.deployment.EJBReferenceBuilder; import org.apache.geronimo.j2ee.deployment.Module; import org.apache.geronimo.j2ee.deployment.ModuleBuilder; import org.apache.geronimo.j2ee.management.impl.J2EEAppClientModuleImpl; @@ -68,6 +71,8 @@ import org.apache.geronimo.xbeans.j2ee.EjbLocalRefType; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; +import org.openejb.client.naming.RemoteEJBObjectFactory; +import org.openejb.client.naming.RemoteEJBRefAddr; /** @@ -272,6 +277,7 @@ } // create a gbean for the app client module and add it to the ear + ReadOnlyContext componentContext; GBeanMBean appClientModuleGBean = new GBeanMBean(J2EEAppClientModuleImpl.GBEAN_INFO, earClassLoader); try { appClientModuleGBean.setReferencePatterns("J2EEServer", Collections.singleton(earContext.getServerObjectName())); @@ -280,7 +286,7 @@ } appClientModuleGBean.setAttribute("deploymentDescriptor", null); - ReadOnlyContext componentContext = buildComponentContext(earContext, appClientModule, appClient, geronimoAppClient, earClassLoader); + componentContext = buildComponentContext(earContext, appClientModule, appClient, geronimoAppClient, earClassLoader); appClientModuleGBean.setAttribute("componentContext", componentContext); } catch (Exception e) { throw new DeploymentException("Unable to initialize AppClientModule GBean", e); @@ -296,10 +302,23 @@ // construct the app client deployment context... this is the same class used by the ear context try { + EJBReferenceBuilder ejbReferenceBuilder = new EJBReferenceBuilder() { + public Reference createEJBLocalReference(String objectName, boolean isSession, String localHome, String local) { + throw new UnsupportedOperationException("Application client cannot have a local ejb ref"); + } + + public Reference createEJBRemoteReference(String objectName, boolean isSession, String home, String remote) { + RemoteEJBRefAddr addr = new RemoteEJBRefAddr(objectName); + Reference reference = new Reference(null, addr, RemoteEJBObjectFactory.class.getName(), null); + return reference; + } + }; + URI configId = URI.create(geronimoAppClient.getConfigId()); appClientDeploymentContext = new EARContext(jos, configId, - ConfigurationModuleType.APP_CLIENT, PARENT_ID, + ConfigurationModuleType.APP_CLIENT, + PARENT_ID, kernel, clientDomainName, clientServerName, @@ -308,7 +327,7 @@ connectionTrackerObjectName, null, null, - null);//not sure if EJBReferenceBuilder should be used for this. + new EJBRefContext(earContext.getEJBRefContext(), ejbReferenceBuilder)); } catch (Exception e) { throw new DeploymentException("Could not create a deployment context for the app client", e); } @@ -393,13 +412,25 @@ } + // add the app client static jndi provider + ObjectName jndiContextName = ObjectName.getInstance("geronimo.client:type=StaticJndiContext"); + GBeanMBean jndiContextGBean = new GBeanMBean("org.apache.geronimo.client.StaticJndiContextPlugin", appClientClassLoader); + try { + + componentContext = buildComponentContext(appClientDeploymentContext, appClientModule, appClient, geronimoAppClient, earClassLoader); + jndiContextGBean.setAttribute("context", componentContext); + } catch (Exception e) { + throw new DeploymentException("Unable to initialize AppClientModule GBean", e); + } + appClientDeploymentContext.addGBean(jndiContextName, jndiContextGBean); + // finally add the app client container ObjectName appClienContainerName = ObjectName.getInstance("geronimo.client:type=ClientContainer"); GBeanMBean appClienContainerGBean = new GBeanMBean("org.apache.geronimo.client.AppClientContainer", appClientClassLoader); try { appClienContainerGBean.setAttribute("mainClassName", mainClasss); appClienContainerGBean.setAttribute("appClientModuleName", appClientModuleName); - appClienContainerGBean.setReferencePattern("JNDIContext", new ObjectName("geronimo.client:type=JNDIContext")); + appClienContainerGBean.setReferencePattern("JNDIContext", new ObjectName("geronimo.client:type=StaticJndiContext")); } catch (Exception e) { throw new DeploymentException("Unable to initialize AppClientModule GBean", e); } Modified: geronimo/trunk/modules/client/project.xml ============================================================================== --- geronimo/trunk/modules/client/project.xml (original) +++ geronimo/trunk/modules/client/project.xml Wed Sep 29 12:27:40 2004 @@ -49,6 +49,12 @@ <dependencies> <dependency> <groupId>geronimo</groupId> + <artifactId>geronimo-naming</artifactId> + <version>${pom.currentVersion}</version> + </dependency> + + <dependency> + <groupId>geronimo</groupId> <artifactId>geronimo-kernel</artifactId> <version>${pom.currentVersion}</version> </dependency> Modified: geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java ============================================================================== --- geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java (original) +++ geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java Wed Sep 29 12:27:40 2004 @@ -78,6 +78,7 @@ } else if (cause instanceof Error) { throwable = cause; } + throwable = new Error(e); } finally { jndiContext.stopClient(appClientModuleName); Added: geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java ============================================================================== --- (empty file) +++ geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java Wed Sep 29 12:27:40 2004 @@ -0,0 +1,65 @@ +/** + * + * 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.client; + +import javax.management.ObjectName; +import javax.naming.InitialContext; + +import org.apache.geronimo.naming.java.ReadOnlyContext; +import org.apache.geronimo.naming.java.RootContext; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.gbean.GBeanInfoFactory; + +/** + * @version $Rev$ $Date$ + */ +public class StaticJndiContextPlugin implements AppClientPlugin { + private final ReadOnlyContext context; + + public StaticJndiContextPlugin(ReadOnlyContext context) { + this.context = context; + } + + public void startClient(ObjectName appClientModuleName) throws Exception { + RootContext.setComponentContext(context); + System.setProperty("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory"); + System.setProperty("java.naming.factory.url.pkgs", "org.apache.geronimo.naming"); +// System.setProperty("java.naming.provider.url", "rmi://localhost:1099"); + new InitialContext().lookup("java:comp/env"); + } + + public void stopClient(ObjectName appClientModuleName) throws Exception { + RootContext.setComponentContext(null); + } + + public static final GBeanInfo GBEAN_INFO; + + static { + GBeanInfoFactory infoFactory = new GBeanInfoFactory(StaticJndiContextPlugin.class); + + infoFactory.addAttribute("context", ReadOnlyContext.class, true); + infoFactory.addInterface(AppClientPlugin.class); + + infoFactory.setConstructor(new String[]{"context"}); + + GBEAN_INFO = infoFactory.getBeanInfo(); + } + + public static GBeanInfo getGBeanInfo() { + return GBEAN_INFO; + } +} Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java (original) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java Wed Sep 29 12:27:40 2004 @@ -265,7 +265,8 @@ transactionContextManagerObjectName, connectionTrackerObjectName, transactionalTimerObjectName, - nonTransactionalTimerObjectName, ejbReferenceBuilder); + nonTransactionalTimerObjectName, + new EJBRefContext(ejbReferenceBuilder)); } catch (MalformedObjectNameException e) { throw new DeploymentException(e); } Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java (original) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java Wed Sep 29 12:27:40 2004 @@ -17,15 +17,12 @@ package org.apache.geronimo.j2ee.deployment; import java.net.URI; -import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.jar.JarOutputStream; - import javax.management.MalformedObjectNameException; import javax.management.ObjectName; -import javax.naming.Reference; import org.apache.geronimo.deployment.DeploymentContext; import org.apache.geronimo.deployment.DeploymentException; @@ -35,9 +32,7 @@ /** * @version $Rev$ $Date$ */ -public class EARContext extends DeploymentContext implements EJBReferenceBuilder { - private final Map ejbRefs = new HashMap(); - private final Map ejbLocalRefs = new HashMap(); +public class EARContext extends DeploymentContext { private final Map resourceAdapterModules = new HashMap(); private final Map activationSpecInfos = new HashMap(); private final String j2eeDomainName; @@ -53,9 +48,9 @@ private final ObjectName transactedTimerName; private final ObjectName nonTransactedTimerName; - private final EJBReferenceBuilder ejbReferenceBuilder; + private final EJBRefContext ejbRefContext; - public EARContext(JarOutputStream jos, URI id, ConfigurationModuleType moduleType, URI parentID, Kernel kernel, String j2eeDomainName, String j2eeServerName, String j2eeApplicationName, ObjectName transactionContextManagerObjectName, ObjectName connectionTrackerObjectName, ObjectName transactedTimerName, ObjectName nonTransactedTimerName, EJBReferenceBuilder ejbReferenceBuilder) throws MalformedObjectNameException, DeploymentException { + public EARContext(JarOutputStream jos, URI id, ConfigurationModuleType moduleType, URI parentID, Kernel kernel, String j2eeDomainName, String j2eeServerName, String j2eeApplicationName, ObjectName transactionContextManagerObjectName, ObjectName connectionTrackerObjectName, ObjectName transactedTimerName, ObjectName nonTransactedTimerName, EJBRefContext ejbRefContext) throws MalformedObjectNameException, DeploymentException { super(jos, id, moduleType, parentID, kernel); this.j2eeDomainName = j2eeDomainName; this.j2eeServerName = j2eeServerName; @@ -100,7 +95,7 @@ this.connectionTrackerObjectName = connectionTrackerObjectName; this.transactedTimerName = transactedTimerName; this.nonTransactedTimerName = nonTransactedTimerName; - this.ejbReferenceBuilder = ejbReferenceBuilder; + this.ejbRefContext = ejbRefContext; } public String getJ2EEDomainName() { @@ -143,71 +138,8 @@ return nonTransactedTimerName; } - public void addEJBRef(URI modulePath, String name, Object reference) throws DeploymentException { - Map references = (Map) ejbRefs.get(name); - if (references == null || references.isEmpty()) { - references = new HashMap(); - ejbRefs.put(name, references); - } - addRef(modulePath, name, reference, references); - } - - public void addEJBLocalRef(URI modulePath, String name, Object reference) throws DeploymentException { - Map references = (Map) ejbLocalRefs.get(name); - if (references == null || references.isEmpty()) { - references = new HashMap(); - ejbLocalRefs.put(name, references); - } - addRef(modulePath, name, reference, references); - } - - private void addRef(URI modulePath, String name, Object reference, Map references) throws DeploymentException { - try { - URI ejbURI = new URI(null, null, modulePath.getPath(), name); - references.put(ejbURI, reference); - } catch (URISyntaxException e) { - throw new DeploymentException(e); - } - } - - public Object getEJBRef(URI module, String ejbLink) throws DeploymentException { - String name = ejbLink.substring(ejbLink.lastIndexOf('#') + 1); - return getRef(module, ejbLink, (Map) ejbRefs.get(name)); - } - - public Object getEJBLocalRef(URI module, String ejbLink) throws DeploymentException { - String name = ejbLink.substring(ejbLink.lastIndexOf('#') + 1); - return getRef(module, ejbLink, (Map) ejbLocalRefs.get(name)); - } - - private Object getRef(URI module, String ejbLink, Map references) throws AmbiguousEJBRefException, UnknownEJBRefException { - if (references == null || references.isEmpty()) { - throw new UnknownEJBRefException(ejbLink); - } - if (ejbLink.indexOf('#') < 0) { - // non absolute reference - if (references.size() != 1) { - // check for an ejb in the current module - Object ejbRef = references.get(module.resolve("#" + ejbLink)); - if (ejbRef == null) { - throw new AmbiguousEJBRefException(ejbLink); - } - return ejbRef; - } - Object ejbRef = references.values().iterator().next(); - if (ejbRef == null) { - throw new UnknownEJBRefException(ejbLink); - } - return ejbRef; - } else { - // absolute reference ../relative/path/Module#EJBName - URI ejbURI = module.resolve(ejbLink).normalize(); - Object ejbRef = references.get(ejbURI); - if (ejbRef == null) { - throw new UnknownEJBRefException(ejbLink); - } - return ejbRef; - } + public EJBRefContext getEJBRefContext() { + return ejbRefContext; } public void addResourceAdapter(String resourceAdapterName, String resourceAdapterModule, Map activationSpecInfoMap) { @@ -223,19 +155,5 @@ public String getResourceAdapterModule(String resourceAdapterName) { return (String) resourceAdapterModules.get(resourceAdapterName); - } - - public Reference createEJBLocalReference(String objectName, boolean isSession, String localHome, String local) throws DeploymentException { - if (ejbReferenceBuilder != null) { - return ejbReferenceBuilder.createEJBLocalReference(objectName, isSession, localHome, local); - } - throw new DeploymentException("No ejb reference builder"); - } - - public Reference createEJBRemoteReference(String objectName, boolean isSession, String home, String remote) throws DeploymentException { - if (ejbReferenceBuilder != null) { - return ejbReferenceBuilder.createEJBRemoteReference(objectName, isSession, home, remote); - } - throw new DeploymentException("No ejb reference builder"); } } Added: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefContext.java ============================================================================== --- (empty file) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBRefContext.java Wed Sep 29 12:27:40 2004 @@ -0,0 +1,155 @@ +/** + * + * 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 java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +import javax.naming.Reference; + +import org.apache.geronimo.deployment.DeploymentException; + +/** + * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $ + */ +public class EJBRefContext { + private final EJBReferenceBuilder ejbReferenceBuilder; + private final Map ejbRemoteIndex; + private final Map ejbLocalIndex; + + public EJBRefContext(EJBReferenceBuilder ejbReferenceBuilder) { + assert ejbReferenceBuilder != null: "ejbReferenceBuilder is null"; + + ejbRemoteIndex = new HashMap(); + ejbLocalIndex = new HashMap(); + this.ejbReferenceBuilder = ejbReferenceBuilder; + } + + public EJBRefContext(EJBRefContext ejbRefContext, EJBReferenceBuilder ejbReferenceBuilder) { + assert ejbReferenceBuilder != null: "ejbReferenceBuilder is null"; + assert ejbRefContext != null: "ejbRefContext is null"; + + this.ejbReferenceBuilder = ejbReferenceBuilder; + this.ejbRemoteIndex = ejbRefContext.ejbRemoteIndex; + this.ejbLocalIndex = ejbRefContext.ejbLocalIndex; + } + + public EJBReferenceBuilder getEjbReferenceBuilder() { + return ejbReferenceBuilder; + } + + public Map getEJBRemoteIndex() { + return ejbRemoteIndex; + } + + public Map getEJBLocalIndex() { + return ejbLocalIndex; + } + + public void addEJBRemoteId(URI modulePath, String name, String containerId) 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); + } + + public void addEJBLocalId(URI modulePath, String name, String containerId) 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); + } + + private void addEJBId(URI modulePath, String name, String containerId, Map references) throws DeploymentException { + try { + URI ejbURI = new URI(null, null, modulePath.getPath(), name); + references.put(ejbURI, containerId); + } catch (URISyntaxException e) { + throw new DeploymentException(e); + } + } + + public Reference getEJBRemoteRef(String objectName, boolean isSession, String home, String remote) throws DeploymentException { + if (ejbReferenceBuilder == null) { + throw new DeploymentException("No ejb reference builder"); + } + return ejbReferenceBuilder.createEJBRemoteReference(objectName, isSession, home, remote); + } + + public Reference getEJBLocalRef(String objectName, boolean isSession, String localHome, String local) throws DeploymentException { + if (ejbReferenceBuilder == null) { + throw new DeploymentException("No ejb reference builder"); + } + return ejbReferenceBuilder.createEJBLocalReference(objectName, isSession, localHome, local); + } + + public Reference getEJBRemoteRef(URI module, String ejbLink, boolean isSession, String home, String remote) throws DeploymentException { + String name = ejbLink.substring(ejbLink.lastIndexOf('#') + 1); + String containerId = getContainerId(module, ejbLink, (Map) ejbRemoteIndex.get(name)); + return getEJBRemoteRef(containerId, isSession, home, remote); + } + + public Reference getEJBLocalRef(URI module, String ejbLink, boolean isSession, String localHome, String local) throws DeploymentException { + String name = ejbLink.substring(ejbLink.lastIndexOf('#') + 1); + String containerId = getContainerId(module, ejbLink, (Map) ejbLocalIndex.get(name)); + return getEJBLocalRef(containerId, isSession, localHome, local); + } + + private String getContainerId(URI module, String ejbLink, Map references) throws AmbiguousEJBRefException, UnknownEJBRefException { + if (references == null || references.isEmpty()) { + throw new UnknownEJBRefException(ejbLink); + } + + // is this an absolute reference ../relative/path/Module#EJBName + if (ejbLink.indexOf('#') >= 0) { + URI ejbURI = module.resolve(ejbLink).normalize(); + String ejbRef = (String) references.get(ejbURI); + if (ejbRef == null) { + throw new UnknownEJBRefException(ejbLink); + } + return ejbRef; + } + + // + // relative reference + // + + // if there is only one ejb with that name, use it + if (references.size() == 1) { + String ejbRef = (String) references.values().iterator().next(); + if (ejbRef == null) { + throw new UnknownEJBRefException(ejbLink); + } + return ejbRef; + } + + // We got more then one ejb with that name. Try to find an ejb in the current module with that name + String ejbRef = (String) references.get(module.resolve("#" + ejbLink)); + if (ejbRef != null) { + return ejbRef; + } + + // there is more then one ejb with the specifiec name + throw new AmbiguousEJBRefException(ejbLink); + } +} Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBReferenceBuilder.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBReferenceBuilder.java (original) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EJBReferenceBuilder.java Wed Sep 29 12:27:40 2004 @@ -16,9 +16,9 @@ */ package org.apache.geronimo.j2ee.deployment; -import org.apache.geronimo.deployment.DeploymentException; - import javax.naming.Reference; + +import org.apache.geronimo.deployment.DeploymentException; /** * @version $Rev$ $Date$ Copied: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java (from rev 47409, geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARContextTest.java) ============================================================================== --- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARContextTest.java (original) +++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java Wed Sep 29 12:27:40 2004 @@ -17,20 +17,15 @@ package org.apache.geronimo.j2ee.deployment; import java.io.File; -import java.io.FileOutputStream; import java.net.URI; -import java.util.jar.JarOutputStream; - -import javax.management.ObjectName; - -import org.apache.geronimo.kernel.config.ConfigurationModuleType; +import javax.naming.Reference; import junit.framework.TestCase; /** * @version $Rev$ $Date$ */ -public class EARContextTest extends TestCase { +public class EJBRefContextTest extends TestCase { private final URI coffee = URI.create("some/path/coffee.jar"); private final URI language = URI.create("some/where/language.jar"); private final URI car = URI.create("foo/bar/car.jar"); @@ -50,27 +45,27 @@ private final String car_enzo = "car_enzo"; private final String car_enzo_local = "car_enzo_local"; private File carFile; - private EARContext earContext; + private EJBRefContext ejbRefContext; public void testSimpleRefs() throws Exception { - assertEquals(coffee_peaberry, earContext.getEJBRef(coffee, "peaberry")); - assertEquals(coffee_peaberry_local, earContext.getEJBLocalRef(coffee, "peaberry")); + assertReferenceEqual(coffee_peaberry, ejbRefContext.getEJBRemoteRef(coffee, "peaberry", true, null, null)); + assertReferenceEqual(coffee_peaberry_local, ejbRefContext.getEJBLocalRef(coffee, "peaberry", true, null, null)); } public void testAmbiguousRefs() throws Exception { - assertEquals(coffee_java, earContext.getEJBRef(coffee, "java")); - assertEquals(coffee_java_local, earContext.getEJBLocalRef(coffee, "java")); - assertEquals(language_java, earContext.getEJBRef(language, "java")); - assertEquals(language_java_local, earContext.getEJBLocalRef(language, "java")); + assertReferenceEqual(coffee_java, ejbRefContext.getEJBRemoteRef(coffee, "java", true, null, null)); + assertReferenceEqual(coffee_java_local, ejbRefContext.getEJBLocalRef(coffee, "java", true, null, null)); + assertReferenceEqual(language_java, ejbRefContext.getEJBRemoteRef(language, "java", true, null, null)); + assertReferenceEqual(language_java_local, ejbRefContext.getEJBLocalRef(language, "java", true, null, null)); try { - earContext.getEJBRef(car, "java"); + ejbRefContext.getEJBRemoteRef(car, "java", true, null, null); fail("should have thrown an AmbiguousEJBRefException"); } catch (AmbiguousEJBRefException e) { // good } try { - earContext.getEJBLocalRef(car, "java"); + ejbRefContext.getEJBLocalRef(car, "java", true, null, null); fail("should have thrown an AmbiguousEJBRefException"); } catch (AmbiguousEJBRefException e) { // good @@ -78,51 +73,51 @@ } public void testRelativeRefs() throws Exception { - assertEquals(car_enzo, earContext.getEJBRef(coffee, "../../foo/bar/car.jar#enzo")); - assertEquals(car_enzo_local, earContext.getEJBLocalRef(coffee, "../../foo/bar/car.jar#enzo")); - assertEquals(car_enzo, earContext.getEJBRef(coffee, "./../funk/../../foo/bar/car.jar#enzo")); - assertEquals(car_enzo_local, earContext.getEJBLocalRef(coffee, "./../funk/../../foo/bar/car.jar#enzo")); - assertEquals(coffee_java, earContext.getEJBRef(coffee, "./coffee.jar#java")); - assertEquals(coffee_java_local, earContext.getEJBLocalRef(coffee, "./coffee.jar#java")); - assertEquals(coffee_java, earContext.getEJBRef(coffee, "coffee.jar#java")); - assertEquals(coffee_java_local, earContext.getEJBLocalRef(coffee, "coffee.jar#java")); + assertReferenceEqual(car_enzo, ejbRefContext.getEJBRemoteRef(coffee, "../../foo/bar/car.jar#enzo", true, null, null)); + assertReferenceEqual(car_enzo_local, ejbRefContext.getEJBLocalRef(coffee, "../../foo/bar/car.jar#enzo", true, null, null)); + assertReferenceEqual(car_enzo, ejbRefContext.getEJBRemoteRef(coffee, "./../funk/../../foo/bar/car.jar#enzo", true, null, null)); + assertReferenceEqual(car_enzo_local, ejbRefContext.getEJBLocalRef(coffee, "./../funk/../../foo/bar/car.jar#enzo", true, null, null)); + assertReferenceEqual(coffee_java, ejbRefContext.getEJBRemoteRef(coffee, "./coffee.jar#java", true, null, null)); + assertReferenceEqual(coffee_java_local, ejbRefContext.getEJBLocalRef(coffee, "./coffee.jar#java", true, null, null)); + assertReferenceEqual(coffee_java, ejbRefContext.getEJBRemoteRef(coffee, "coffee.jar#java", true, null, null)); + assertReferenceEqual(coffee_java_local, ejbRefContext.getEJBLocalRef(coffee, "coffee.jar#java", true, null, null)); try { - earContext.getEJBRef(coffee, "not_exist.jar#blah"); + ejbRefContext.getEJBRemoteRef(coffee, "not_exist.jar#blah", true, null, null); fail("should have thrown an UnknownEJBRefException"); } catch (UnknownEJBRefException e) { // good } try { - earContext.getEJBLocalRef(coffee, "not_exist.jar#blah"); + ejbRefContext.getEJBLocalRef(coffee, "not_exist.jar#blah", true, null, null); fail("should have thrown an UnknownEJBRefException"); } catch (UnknownEJBRefException e) { // good } try { - earContext.getEJBRef(coffee, "coffee.jar#blah"); + ejbRefContext.getEJBRemoteRef(coffee, "coffee.jar#blah", true, null, null); fail("should have thrown an UnknownEJBRefException"); } catch (UnknownEJBRefException e) { // good } try { - earContext.getEJBLocalRef(coffee, "coffee.jar#blah"); + ejbRefContext.getEJBLocalRef(coffee, "coffee.jar#blah", true, null, null); fail("should have thrown an UnknownEJBRefException"); } catch (UnknownEJBRefException e) { // good } try { - earContext.getEJBRef(coffee, "../../../../foo/bar/car.jar#enzo"); + ejbRefContext.getEJBRemoteRef(coffee, "../../../../foo/bar/car.jar#enzo", true, null, null); fail("should have thrown an UnknownEJBRefException"); } catch (UnknownEJBRefException e) { // good } try { - earContext.getEJBLocalRef(coffee, "../../../../foo/bar/car.jar#enzo"); + ejbRefContext.getEJBLocalRef(coffee, "../../../../foo/bar/car.jar#enzo", true, null, null); fail("should have thrown an UnknownEJBRefException"); } catch (UnknownEJBRefException e) { // good @@ -131,37 +126,51 @@ protected void setUp() throws Exception { carFile = File.createTempFile("EARTest", ".car"); - earContext = new EARContext(new JarOutputStream(new FileOutputStream(carFile)), - URI.create("configId"), - ConfigurationModuleType.EAR, - URI.create("parentId"), - null, - "j2eeDomain", - "j2eeServer", - "j2eeApplicationName", - ObjectName.getInstance("j2eeDomain:type=TransactionManager"), - ObjectName.getInstance("j2eeDomain:type=ConnectionTracker"), - ObjectName.getInstance("j2eeDomain:type=TransactionalTimer"), - ObjectName.getInstance("j2eeDomain:type=NonTransactionalTimer"), - null); - - earContext.addEJBRef(coffee, "peaberry", coffee_peaberry); - earContext.addEJBLocalRef(coffee, "peaberry", coffee_peaberry_local); - earContext.addEJBRef(coffee, "java", coffee_java); - earContext.addEJBLocalRef(coffee, "java", coffee_java_local); - - earContext.addEJBRef(language, "lisp", language_lisp); - earContext.addEJBLocalRef(language, "lisp", language_lisp_local); - earContext.addEJBRef(language, "java", language_java); - earContext.addEJBLocalRef(language, "java", language_java_local); - - earContext.addEJBRef(car, "gt", car_gt); - earContext.addEJBLocalRef(car, "gt", car_gt_local); - earContext.addEJBRef(car, "enzo", car_enzo); - earContext.addEJBLocalRef(car, "enzo", car_enzo_local); + ejbRefContext = new EJBRefContext(new EJBReferenceBuilder() { + public Reference createEJBLocalReference(String objectName, boolean isSession, String localHome, String local) { + return new FakeReference(objectName); + } + + public Reference createEJBRemoteReference(String objectName, boolean isSession, String home, String remote) { + return new FakeReference(objectName); + } + }); + + 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); } protected void tearDown() throws Exception { carFile.delete(); + } + + private void assertReferenceEqual(String expected, Reference reference) { + FakeReference fakeReference = (FakeReference)reference; + String containerId = null; + if (fakeReference != null) { + containerId = fakeReference.containerId; + } + assertEquals(expected, containerId); + } + + private class FakeReference extends Reference { + private String containerId; + + public FakeReference(String containerId) { + super(null); + this.containerId = containerId; + } } } 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 Wed Sep 29 12:27:40 2004 @@ -32,6 +32,7 @@ import org.apache.geronimo.naming.java.ReadOnlyContext; import org.apache.geronimo.naming.jmx.JMXReferenceFactory; import org.apache.geronimo.j2ee.deployment.EARContext; +import org.apache.geronimo.j2ee.deployment.EJBRefContext; /** * @@ -128,6 +129,7 @@ } public static void addEJBRefs(EARContext earContext, URI uri, EjbRefType[] ejbRefs, Map ejbRefMap, ClassLoader cl, ComponentContextBuilder builder) throws DeploymentException { + EJBRefContext ejbRefContext = earContext.getEJBRefContext(); for (int i = 0; i < ejbRefs.length; i++) { EjbRefType ejbRef = ejbRefs[i]; @@ -144,7 +146,7 @@ String ejbLink = getJ2eeStringValue(ejbRef.getEjbLink()); if (ejbLink != null) { try { - builder.bind(ejbRefName, earContext.getEJBRef(uri, ejbLink)); + 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); } @@ -154,7 +156,7 @@ throw new DeploymentException("No geronimo configuration for resource ref named: " + ejbRefName); } try { - builder.bind(ejbRefName, earContext.createEJBRemoteReference(remoteRef.getTargetName(), isSession, home, remote)); + builder.bind(ejbRefName, ejbRefContext.getEJBRemoteRef(remoteRef.getTargetName(), isSession, home, remote)); } catch (NamingException e) { throw new DeploymentException("Invalid env-entry definition for name: " + ejbRefName, e); } @@ -164,6 +166,7 @@ } public static void addEJBLocalRefs(EARContext earContext, URI uri, EjbLocalRefType[] ejbLocalRefs, Map ejbLocalRefMap, ClassLoader cl, ComponentContextBuilder builder) throws DeploymentException { + EJBRefContext ejbRefContext = earContext.getEJBRefContext(); for (int i = 0; i < ejbLocalRefs.length; i++) { EjbLocalRefType ejbLocalRef = ejbLocalRefs[i]; @@ -180,7 +183,7 @@ String ejbLink = getJ2eeStringValue(ejbLocalRef.getEjbLink()); if (ejbLink != null) { try { - builder.bind(ejbRefName, earContext.getEJBLocalRef(uri, ejbLink)); + 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); } @@ -190,7 +193,7 @@ throw new DeploymentException("No geronimo configuration for resource ref named: " + ejbRefName); } try { - builder.bind(ejbRefName, earContext.createEJBLocalReference(localRef.getTargetName(), isSession, localHome, local)); + builder.bind(ejbRefName, ejbRefContext.getEJBLocalRef(localRef.getTargetName(), isSession, localHome, local)); } catch (NamingException e) { throw new DeploymentException("Invalid env-entry definition for name: " + ejbRefName, e); } Added: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/ClientCommandLine.java ============================================================================== --- (empty file) +++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/ClientCommandLine.java Wed Sep 29 12:27:40 2004 @@ -0,0 +1,55 @@ +/** + * + * 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.system.main; + +import java.net.URI; +import java.util.Collections; +import javax.management.ObjectName; + +import org.apache.geronimo.system.main.CommandLine; +import org.apache.geronimo.system.main.ExceptionUtil; + +/** + * @version $Revision$ $Date$ + */ +public class ClientCommandLine extends CommandLine { + /** + * Command line entry point called by executable jar + * @param args command line args + */ + public static void main(String[] args) { + log.info("Client startup begun"); + try { + URI configuration = new URI(args[0]); + String[] clientArgs = new String[args.length -1]; + System.arraycopy(args, 1, clientArgs, 0, clientArgs.length); + new ClientCommandLine(configuration, clientArgs); + + log.info("Client shutdown completed"); + } catch (Exception e) { + ExceptionUtil.trimStackTrace(e); + e.printStackTrace(); + System.exit(2); + throw new AssertionError(); + } + } + + + public ClientCommandLine(URI configuration, String[] args) throws Exception { + super(Collections.singletonList(configuration), new ObjectName("geronimo.client:type=ClientContainer"), "main", args); + } +}