Title: [2558] branches/v2_1/openejb2/modules/core/src/java/org/openejb/proxy: Simplify enc config builder stuff.

Diff

Modified: branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/naming/RemoteEJBObjectFactory.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/naming/RemoteEJBObjectFactory.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/naming/RemoteEJBObjectFactory.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -103,6 +103,7 @@
             throw new IllegalStateException("Reference address must be a RemoteEJBRefAddr: " + addr);
         }
 
+        //TODO configid BROKEN
         String containerId = (String) addr.getContent();
         JNDIRequest req = new JNDIRequest(JNDIRequest.JNDI_LOOKUP, containerId);
 

Modified: branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/naming/RemoteEJBRefAddr.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/naming/RemoteEJBRefAddr.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/naming/RemoteEJBRefAddr.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -47,6 +47,8 @@
  */
 package org.openejb.client.naming;
 
+import org.apache.geronimo.gbean.AbstractNameQuery;
+
 import javax.naming.RefAddr;
 
 /**
@@ -54,9 +56,9 @@
  */
 public class RemoteEJBRefAddr extends RefAddr {
     private final static String TYPE = RemoteEJBRefAddr.class.getName();
-    private final String containerId;
+    private final AbstractNameQuery containerId;
 
-    public RemoteEJBRefAddr(String containerId) {
+    public RemoteEJBRefAddr(AbstractNameQuery containerId) {
         super(TYPE);
         this.containerId = containerId;
     }

Modified: branches/v2_1/openejb2/modules/core/src/java/org/openejb/proxy/EJBProxyReference.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/proxy/EJBProxyReference.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/proxy/EJBProxyReference.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -47,21 +47,26 @@
  */
 package org.openejb.proxy;
 
-import org.apache.geronimo.naming.reference.SimpleAwareReference;
+import org.apache.geronimo.naming.reference.ConfigurationAwareReference;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
 
+import javax.naming.NameNotFoundException;
+
 /**
  * @version $Revision$ $Date$
  */
-public class EJBProxyReference extends SimpleAwareReference {
-    public static EJBProxyReference createRemote(String containerId, boolean sessionBean, String homeInterfaceName, String remoteInterfaceName) {
-        return new EJBProxyReference(containerId, sessionBean, homeInterfaceName, remoteInterfaceName, null, null, false);
+public class EJBProxyReference extends ConfigurationAwareReference {
+    public static EJBProxyReference createRemote(Artifact configurationId, AbstractNameQuery abstractNameQuery, boolean sessionBean, String homeInterfaceName, String remoteInterfaceName) {
+        return new EJBProxyReference(configurationId, abstractNameQuery, sessionBean, homeInterfaceName, remoteInterfaceName, null, null, false);
     }
 
-    public static EJBProxyReference createLocal(String containerId, boolean sessionBean, String localHomeInterfaceName, String localInterfaceName) {
-        return new EJBProxyReference(containerId, sessionBean, null, null, localHomeInterfaceName, localInterfaceName, true);
+    public static EJBProxyReference createLocal(Artifact configurationId, AbstractNameQuery abstractNameQuery, boolean sessionBean, String localHomeInterfaceName, String localInterfaceName) {
+        return new EJBProxyReference(configurationId, abstractNameQuery, sessionBean, null, null, localHomeInterfaceName, localInterfaceName, true);
     }
 
-    private final String containerId;
     private final boolean isSessionBean;
     private final String remoteInterfaceName;
     private final String homeInterfaceName;
@@ -71,8 +76,8 @@
 
     private transient EJBProxyFactory proxyFactory;
 
-    private EJBProxyReference(String containerId, boolean sessionBean, String homeInterfaceName, String remoteInterfaceName, String localHomeInterfaceName, String localInterfaceName, boolean local) {
-        this.containerId = containerId;
+    private EJBProxyReference(Artifact configurationId, AbstractNameQuery containerQuery, boolean sessionBean, String homeInterfaceName, String remoteInterfaceName, String localHomeInterfaceName, String localInterfaceName, boolean local) {
+        super(configurationId, containerQuery);
         isSessionBean = sessionBean;
         this.remoteInterfaceName = remoteInterfaceName;
         this.homeInterfaceName = homeInterfaceName;
@@ -81,7 +86,7 @@
         isLocal = local;
     }
 
-    public Object getContent() {
+    public Object getContent() throws NameNotFoundException {
         EJBProxyFactory proxyFactory = getEJBProxyFactory();
         if (isLocal) {
             return proxyFactory.getEJBLocalHome();
@@ -90,7 +95,7 @@
         }
     }
 
-    private EJBProxyFactory getEJBProxyFactory() {
+    private EJBProxyFactory getEJBProxyFactory() throws NameNotFoundException {
         if (proxyFactory == null) {
             ClassLoader cl = getClassLoader();
             Class remoteInterface = loadClass(cl, remoteInterfaceName);
@@ -98,6 +103,14 @@
             Class localInterface = loadClass(cl, localInterfaceName);
             Class localHomeInterface = loadClass(cl, localHomeInterfaceName);
 
+
+            AbstractName configurationName;
+            try {
+                configurationName = resolveTargetName();
+            } catch (GBeanNotFoundException e) {
+                throw new NameNotFoundException("Could not resolve abstract name query " + abstractNameQuery + " in configuration " + getConfiguration().getId());
+            }
+            String containerId = configurationName.getObjectName().getCanonicalName();
             proxyFactory = new EJBProxyFactory(containerId,
                     isSessionBean,
                     remoteInterface,
@@ -119,7 +132,4 @@
         }
     }
 
-    public String getContainerId() {
-        return containerId;
-    }
-}
+}
\ No newline at end of file

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/EntityBuilder.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/EntityBuilder.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/EntityBuilder.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -162,11 +162,11 @@
                 String tssBeanLink = openejbEntityBean.getTssLink().trim();
                 URI moduleURI = ejbModule.getModuleURI();
                 String moduleType = NameFactory.EJB_MODULE;
-                tssBeanObjectName = ENCConfigBuilder.buildAbstractNameQuery(moduleURI == null? null: moduleURI.toString(), moduleType, tssBeanLink);
+                tssBeanObjectName = ENCConfigBuilder.buildAbstractNameQuery(null, moduleURI == null? null: moduleURI.toString(), moduleType, tssBeanLink);
                 try {
                     earContext.getConfiguration().findGBean(tssBeanObjectName);
                 } catch (GBeanNotFoundException e) {
-                    tssBeanObjectName = ENCConfigBuilder.buildAbstractNameQuery(null, null, tssBeanLink);
+                    tssBeanObjectName = ENCConfigBuilder.buildAbstractNameQuery(null, null, null, tssBeanLink);
                     try {
                         earContext.getConfiguration().findGBean(tssBeanObjectName);
                     } catch (GBeanNotFoundException e1) {
@@ -231,7 +231,7 @@
 
         Map context = ENCConfigBuilder.buildComponentContext(earContext, null, ejbModule, userTransaction, envEntries, ejbRefs, openejbEjbRefs, ejbLocalRefs, openejbEjbLocalRefs, resourceRefs, openejbResourceRefs, resourceEnvRefs, openejbResourceEnvRefs, messageDestinationRefs, serviceRefs, openejbServiceRefs, cl);
         builder.setComponentContext(context);
-        ENCConfigBuilder.setResourceEnvironment(earContext, ejbModule.getModuleURI(), builder, resourceRefs, openejbResourceRefs);
+        ENCConfigBuilder.setResourceEnvironment(ejbModule.getModuleURI(), builder, resourceRefs, openejbResourceRefs);
     }
 
     public void initContext(EARContext earContext, AbstractName moduleBaseName, URI moduleUri, ClassLoader cl, EnterpriseBeansType enterpriseBeans) throws DeploymentException {

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/MdbBuilder.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/MdbBuilder.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/MdbBuilder.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -86,7 +86,6 @@
 import org.apache.geronimo.xbeans.j2ee.ResourceRefType;
 import org.apache.geronimo.xbeans.j2ee.ServiceRefType;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Naming;
 import org.openejb.transaction.TransactionPolicySource;
 import org.openejb.xbeans.ejbjar.OpenejbActivationConfigPropertyType;
@@ -235,23 +234,16 @@
                                                String messageListenerInterfaceName,
                                                String containerId) throws DeploymentException {
         RefContext refContext = earContext.getRefContext();
-        AbstractNameQuery resourceAdapterNameQuery = getResourceAdapterId(resourceAdapter);
-        AbstractName resourceModuleName;
-        try {
-            AbstractName resourceAdapterName = earContext.getConfiguration().findGBean(resourceAdapterNameQuery);
-            resourceModuleName = getParent(getParent(resourceAdapterName, NameFactory.JCA_RESOURCE), NameFactory.RESOURCE_ADAPTER_MODULE);
+        AbstractNameQuery resourceAdapterModuleQuery = getResourceAdapterNameQuery(resourceAdapter, NameFactory.RESOURCE_ADAPTER_MODULE);
+        GBeanData activationSpecInfo = refContext.getActivationSpecInfo(resourceAdapterModuleQuery, messageListenerInterfaceName, earContext.getConfiguration());
 
-        } catch (GBeanNotFoundException e) {
-            throw new DeploymentException("Can not find resource adapter for message driven bean", e);
-        }
-        GBeanData activationSpecInfo = refContext.getActivationSpecInfo(resourceModuleName, messageListenerInterfaceName, earContext);
-
         if (activationSpecInfo == null) {
-            throw new DeploymentException("no activation spec found for resource adapter: " + resourceAdapterNameQuery + " and message listener type: " + messageListenerInterfaceName);
+            throw new DeploymentException("no activation spec found for resource adapter: " + resourceAdapterModuleQuery + " and message listener type: " + messageListenerInterfaceName);
         }
         activationSpecInfo = new GBeanData(activationSpecInfo);
         activationSpecInfo.setAttribute("containerId", containerId);
-        activationSpecInfo.setReferencePattern("ResourceAdapterWrapper", resourceAdapterNameQuery);
+        AbstractNameQuery resourceAdapterInstanceQuery = getResourceAdapterNameQuery(resourceAdapter, NameFactory.JCA_RESOURCE_ADAPTER);
+        activationSpecInfo.setReferencePattern("ResourceAdapterWrapper", resourceAdapterInstanceQuery);
         if (openejbActivationConfigProperties != null) {
             for (int i = 0; i < openejbActivationConfigProperties.length; i++) {
                 OpenejbActivationConfigPropertyType activationConfigProperty = openejbActivationConfigProperties[i];
@@ -298,12 +290,12 @@
         return new AbstractName(childName.getArtifact(), nameMap, parentObjectName);
     }
 
-    private static AbstractNameQuery getResourceAdapterId(GerResourceLocatorType resourceLocator) {
+    private static AbstractNameQuery getResourceAdapterNameQuery(GerResourceLocatorType resourceLocator, String type) {
         if (resourceLocator.isSetResourceLink()) {
-            return ENCConfigBuilder.buildAbstractNameQuery(null, NameFactory.JCA_RESOURCE_ADAPTER, resourceLocator.getResourceLink().trim());
+            return ENCConfigBuilder.buildAbstractNameQuery(null, null, type, resourceLocator.getResourceLink().trim());
         }
         //construct name from components
-        return ENCConfigBuilder.buildAbstractNameQuery(resourceLocator.getPattern(), NameFactory.JCA_RESOURCE_ADAPTER);
+        return ENCConfigBuilder.buildAbstractNameQuery(resourceLocator.getPattern(), type);
     }
 
     protected void processEnvironmentRefs(MDBContainerBuilder builder, EARContext earContext, EJBModule ejbModule, MessageDrivenBeanType messageDrivenBean, OpenejbMessageDrivenBeanType openejbMessageDrivenBean, UserTransaction userTransaction, ClassLoader cl) throws DeploymentException {
@@ -341,7 +333,7 @@
 
         Map context = ENCConfigBuilder.buildComponentContext(earContext, null, ejbModule, userTransaction, envEntries, ejbRefs, openejbEjbRefs, ejbLocalRefs, openejbEjbLocalRefs, resourceRefs, openejbResourceRefs, resourceEnvRefs, openejbResourceEnvRefs, messageDestinationRefs, serviceRefs, openejbServiceRefs, cl);
         builder.setComponentContext(context);
-        ENCConfigBuilder.setResourceEnvironment(earContext, ejbModule.getModuleURI(), builder, resourceRefs, openejbResourceRefs);
+        ENCConfigBuilder.setResourceEnvironment(ejbModule.getModuleURI(), builder, resourceRefs, openejbResourceRefs);
 
     }
 

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBModuleBuilder.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBModuleBuilder.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBModuleBuilder.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -519,7 +519,7 @@
     private static AbstractNameQuery getResourceContainerId(GerResourceLocatorType resourceLocator, EARContext earContext) throws GBeanNotFoundException {
         AbstractNameQuery resourceQuery;
         if (resourceLocator.isSetResourceLink()) {
-            resourceQuery = ENCConfigBuilder.buildAbstractNameQuery(null, NameFactory.JCA_MANAGED_CONNECTION_FACTORY, resourceLocator.getResourceLink().trim());
+            resourceQuery = ENCConfigBuilder.buildAbstractNameQuery(null, null, NameFactory.JCA_MANAGED_CONNECTION_FACTORY, resourceLocator.getResourceLink().trim());
         } else {
             //construct name from components
             resourceQuery = ENCConfigBuilder.buildAbstractNameQuery(resourceLocator.getPattern(), NameFactory.JCA_MANAGED_CONNECTION_FACTORY);

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBReferenceBuilder.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBReferenceBuilder.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBReferenceBuilder.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -47,118 +47,149 @@
  */
 package org.openejb.deployment;
 
-import java.net.URI;
-import java.util.Set;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Collections;
-import javax.naming.Reference;
-import javax.management.ObjectName;
-
-import org.apache.geronimo.j2ee.deployment.EJBReferenceBuilder;
-import org.apache.geronimo.j2ee.deployment.NamingContext;
-import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.common.UnresolvedEJBRefException;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.j2ee.deployment.EJBReferenceBuilder;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.openejb.corba.CORBAHandleDelegate;
+import org.openejb.corba.proxy.CORBAProxyReference;
 import org.openejb.proxy.EJBProxyReference;
 import org.openejb.proxy.ProxyInfo;
-import org.openejb.corba.proxy.CORBAProxyReference;
-import org.openejb.corba.CORBAHandleDelegate;
 
+import javax.naming.Reference;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * @version $Revision$ $Date$
  */
 public class OpenEJBReferenceBuilder implements EJBReferenceBuilder {
-    private final static AbstractNameQuery STATELESS = new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.STATELESS_SESSION_BEAN));
-    private final static AbstractNameQuery STATEFUL = new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.STATEFUL_SESSION_BEAN));
-    private final static AbstractNameQuery ENTITY = new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.ENTITY_BEAN));
+    private final static Map STATELESS = Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.STATELESS_SESSION_BEAN);
+    private final static Map STATEFUL = Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.STATEFUL_SESSION_BEAN);
+    private final static Map ENTITY = Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.ENTITY_BEAN);
 
-    public Reference createEJBLocalReference(String objectName, GBeanData gbeanData, boolean session, String localHome, String local) throws DeploymentException {
-        if (gbeanData != null) {
-            ProxyInfo proxyInfo = (ProxyInfo) gbeanData.getAttribute("proxyInfo");
-            if (proxyInfo == null) {
-                throw new IllegalStateException("BUG! no proxy info found in gbeanData: " + gbeanData);
-            }
-            if (!proxyInfo.getLocalHomeInterface().getName().equals(localHome)
-                    || !proxyInfo.getLocalInterface().getName().equals(local)) {
-                throw new DeploymentException("Reference interfaces do not match bean interfaces:\n" +
-                        "reference localHome: " + localHome + "\n" +
-                        "ejb localHome: " + proxyInfo.getLocalHomeInterface().getName() + "\n" +
-                        "reference local: " + local + "\n" +
-                        "ejb local: " + proxyInfo.getLocalInterface().getName());
-            }
+    private void checkLocalProxyInfo(AbstractNameQuery query, String localHome, String local, Configuration configuration) throws DeploymentException {
+        GBeanData gbeanData;
+        try {
+            gbeanData = configuration.findGBeanData(query);
+        } catch (GBeanNotFoundException e) {
+            throw new DeploymentException("Could not locate ejb matching " + query + " in configuration " + configuration.getId());
         }
-        return buildLocalReference(objectName, session, localHome, local);
+        ProxyInfo proxyInfo = (ProxyInfo) gbeanData.getAttribute("proxyInfo");
+        if (proxyInfo == null) {
+            throw new IllegalStateException("BUG! no proxy info found in gbeanData: " + gbeanData);
+        }
+        if (!proxyInfo.getLocalHomeInterface().getName().equals(localHome)
+                || !proxyInfo.getLocalInterface().getName().equals(local)) {
+            throw new DeploymentException("Reference interfaces do not match bean interfaces:\n" +
+                    "reference localHome: " + localHome + "\n" +
+                    "ejb localHome: " + proxyInfo.getLocalHomeInterface().getName() + "\n" +
+                    "reference local: " + local + "\n" +
+                    "ejb local: " + proxyInfo.getLocalInterface().getName());
+        }
     }
 
-    public Reference createEJBRemoteReference(String objectName, GBeanData gbeanData, boolean session, String home, String remote) throws DeploymentException {
-        if (gbeanData != null) {
-            ProxyInfo proxyInfo = (ProxyInfo) gbeanData.getAttribute("proxyInfo");
-            if (proxyInfo == null) {
-                throw new IllegalStateException("BUG! no proxy info found in gbeanData: " + gbeanData);
-            }
-            if (!proxyInfo.getHomeInterface().getName().equals(home)
-                    || !proxyInfo.getRemoteInterface().getName().equals(remote)) {
-                throw new DeploymentException("Reference interfaces do not match bean interfaces:\n" +
-                        "reference home: " + home + "\n" +
-                        "ejb home: " + proxyInfo.getHomeInterface().getName() + "\n" +
-                        "reference remote: " + remote + "\n" +
-                        "ejb remote: " + proxyInfo.getRemoteInterface().getName());
-            }
+    private void checkRemoteProxyInfo(AbstractNameQuery query, String home, String remote, Configuration configuration) throws DeploymentException {
+        GBeanData gbeanData;
+        try {
+            gbeanData = configuration.findGBeanData(query);
+        } catch (GBeanNotFoundException e) {
+            throw new DeploymentException("Could not locate ejb matching " + query + " in configuration " + configuration.getId());
         }
-        return buildRemoteReference(objectName, session, home, remote);
+        ProxyInfo proxyInfo = (ProxyInfo) gbeanData.getAttribute("proxyInfo");
+        if (proxyInfo == null) {
+            throw new IllegalStateException("BUG! no proxy info found in gbeanData: " + gbeanData);
+        }
+        if (!proxyInfo.getHomeInterface().getName().equals(home)
+                || !proxyInfo.getRemoteInterface().getName().equals(remote)) {
+            throw new DeploymentException("Reference interfaces do not match bean interfaces:\n" +
+                    "reference home: " + home + "\n" +
+                    "ejb home: " + proxyInfo.getHomeInterface().getName() + "\n" +
+                    "reference remote: " + remote + "\n" +
+                    "ejb remote: " + proxyInfo.getRemoteInterface().getName());
+        }
     }
 
-    public Reference createCORBAReference(Artifact configId, AbstractNameQuery containerNameQuery, URI nsCorbaloc, String objectName, String home) throws DeploymentException {
-        return new CORBAProxyReference(configId, containerNameQuery, nsCorbaloc, objectName, home);
+    public Reference createCORBAReference(Configuration configuration, AbstractNameQuery containerNameQuery, URI nsCorbaloc, String objectName, String home) throws DeploymentException {
+        try {
+            configuration.findGBean(containerNameQuery);
+        } catch (GBeanNotFoundException e) {
+            throw new DeploymentException("Could not find css bean matching " + containerNameQuery + " from configuration " + configuration.getId());
+        }
+        return new CORBAProxyReference(configuration.getId(), containerNameQuery, nsCorbaloc, objectName, home);
     }
 
     public Object createHandleDelegateReference() {
         return new CORBAHandleDelegate.HandleDelegateReference();
     }
 
-    public Reference getImplicitEJBRemoteRef(URI module, String refName, boolean isSession, String home, String remote, NamingContext context) throws DeploymentException {
-        boolean isRemote = true;
-        ObjectName match = getImplicitMatch(isSession, context, isRemote, home, remote, refName, module);
-        return buildRemoteReference(match.getCanonicalName(), isSession, home, remote);
+    public Reference createEJBRemoteRef(String requiredModule, String optionalModule, String name, Artifact targetConfigId, AbstractNameQuery query, boolean isSession, String home, String remote, Configuration configuration) throws DeploymentException {
+        AbstractNameQuery match;
+        if (query != null) {
+            checkRemoteProxyInfo(query, home, remote, configuration);
+            match = query;
+        } else if (name != null) {
+            //TODO configid HARD PART GOES HERE
+            match = null;
+        } else {
+            boolean isRemote = true;
+            String refName = null;//TODO consider whether to supply this info
+            match = getImplicitMatch(isSession, configuration, isRemote, home, remote, refName, optionalModule);
+        }
+        return buildRemoteReference(configuration.getId(), match, isSession, home, remote);
     }
 
-    public Reference getImplicitEJBLocalRef(URI module, String refName, boolean isSession, String localHome, String local, NamingContext context) throws DeploymentException {
-        boolean isRemote = false;
-        ObjectName match = getImplicitMatch(isSession, context, isRemote, localHome, local, refName, module);
-        return buildLocalReference(match.getCanonicalName(), isSession, localHome, local);
+    public Reference createEJBLocalRef(String requiredModule, String optionalModule, String name, Artifact targetConfigId, AbstractNameQuery query, boolean isSession, String localHome, String local, Configuration configuration) throws DeploymentException {
+        AbstractNameQuery match;
+        if (query != null) {
+            checkLocalProxyInfo(query, localHome, local, configuration);
+            match = query;
+        } else if (name != null) {
+            //TODO configid HARD PART GOES HERE
+            match = null;
+        } else {
+            boolean isRemote = true;
+            String refName = null;//TODO consider whether to supply this info
+            match = getImplicitMatch(isSession, configuration, isRemote, localHome, local, refName, optionalModule);
+        }
+        return buildLocalReference(configuration.getId(), match, isSession, localHome, local);
     }
 
-    protected Reference buildLocalReference(String objectName, boolean session, String localHome, String local) {
-        return EJBProxyReference.createLocal(objectName, session, localHome, local);
+    protected Reference buildLocalReference(Artifact configurationId, AbstractNameQuery abstractNameQuery, boolean session, String localHome, String local) {
+        return EJBProxyReference.createLocal(configurationId, abstractNameQuery, session, localHome, local);
     }
 
-    protected Reference buildRemoteReference(String objectName, boolean session, String home, String remote) {
-        return EJBProxyReference.createRemote(objectName, session, home, remote);
+    protected Reference buildRemoteReference(Artifact configurationId, AbstractNameQuery abstractNameQuery, boolean session, String home, String remote) {
+        return EJBProxyReference.createRemote(configurationId, abstractNameQuery, session, home, remote);
     }
 
-    private ObjectName getImplicitMatch(boolean isSession, NamingContext context, boolean isRemote, String home, String remote, String refName, URI module) throws DeploymentException {
+    private AbstractNameQuery getImplicitMatch(boolean isSession, Configuration context, boolean isRemote, String home, String remote, String refName, String module) throws DeploymentException {
         Set gbeans;
         if (isSession) {
-            gbeans = context.listGBeans(STATELESS);
-            gbeans.addAll(context.listGBeans(STATEFUL));
+            gbeans = context.findGBeans(new AbstractNameQuery(context.getId(), STATELESS));
+            gbeans.addAll(context.findGBeans(new AbstractNameQuery(context.getId(), STATEFUL)));
         } else {
-            gbeans = context.listGBeans(ENTITY);
+            gbeans = context.findGBeans(new AbstractNameQuery(context.getId(), ENTITY));
         }
         Collection matches = new ArrayList();
         for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
             AbstractName abstractName = (AbstractName) iterator.next();
             GBeanData data;
             try {
-                data = ""
+                data = "" AbstractNameQuery(abstractName));
             } catch (GBeanNotFoundException e) {
                 throw new DeploymentException("We just got this ejb name out of a query! It must be there!");
             }
@@ -169,23 +200,23 @@
         if (matches.isEmpty()) {
             throw new UnresolvedEJBRefException(refName, false, isSession, home, remote, false);
         }
-        ObjectName match;
+        AbstractName match;
         if (matches.size() == 1) {
-            match = (ObjectName) matches.iterator().next();
+            match = (AbstractName) matches.iterator().next();
         } else {
             for (Iterator iterator = matches.iterator(); iterator.hasNext();) {
-                ObjectName objectName = (ObjectName) iterator.next();
-                if (!(objectName.getKeyProperty(NameFactory.EJB_MODULE).equals(module.getPath()))) {
+                AbstractName objectName = (AbstractName) iterator.next();
+                if (!(objectName.getName().get(NameFactory.EJB_MODULE).equals(module))) {
                     iterator.remove();
                 }
             }
             if (matches.size() == 1) {
-                match = (ObjectName) matches.iterator().next();
+                match = (AbstractName) matches.iterator().next();
             } else {
                 throw new UnresolvedEJBRefException(refName, false, isSession, home, remote, matches.size() > 0);
             }
         }
-        return match;
+        return new AbstractNameQuery(match);
     }
 
     private boolean matchesProxyInfo(GBeanData data, boolean isRemote, String home, String remote) {

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/RemoteEJBReferenceBuilder.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/RemoteEJBReferenceBuilder.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/RemoteEJBReferenceBuilder.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -47,46 +47,30 @@
  */
 package org.openejb.deployment;
 
-import java.net.URI;
-import java.util.Set;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Iterator;
-import javax.management.ObjectName;
-import javax.naming.Reference;
-
 import org.apache.geronimo.common.DeploymentException;
-import org.apache.geronimo.common.UnresolvedEJBRefException;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.j2ee.deployment.EJBReferenceBuilder;
-import org.apache.geronimo.j2ee.deployment.NamingContext;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.kernel.jmx.JMXUtil;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
-
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.repository.Artifact;
 import org.openejb.client.naming.RemoteEJBObjectFactory;
 import org.openejb.client.naming.RemoteEJBRefAddr;
-import org.openejb.corba.CORBAHandleDelegate;
-import org.openejb.corba.proxy.CORBAProxyReference;
-import org.openejb.proxy.ProxyInfo;
 
+import javax.naming.Reference;
 
+
 /**
  */
 public class RemoteEJBReferenceBuilder extends OpenEJBReferenceBuilder {
 
-    public Reference createEJBLocalReference(String objectName, GBeanData gbeanData, boolean isSession, String localHome, String local) {
+    public Reference createEJBLocalRef(String requiredModule, String optionalModule, String name, Artifact targetConfigId, AbstractNameQuery query, boolean isSession, String localHome, String local, Configuration configuration) throws DeploymentException {
         throw new UnsupportedOperationException("Application client cannot have a local ejb ref");
     }
 
-    public Reference getImplicitEJBLocalRef(URI module, String refName, boolean isSession, String localHome, String local, NamingContext context) throws DeploymentException {
-        throw new UnsupportedOperationException("Application client cannot have a local ejb ref");
-    }
-
-    protected Reference buildRemoteReference(String objectName, boolean session, String home, String remote) {
-        RemoteEJBRefAddr addr = new RemoteEJBRefAddr(objectName);
+    protected Reference buildRemoteReference(Artifact configurationId, AbstractNameQuery abstractNameQuery, boolean session, String home, String remote) {
+        RemoteEJBRefAddr addr = new RemoteEJBRefAddr(abstractNameQuery);
         Reference reference = new Reference(null, addr, RemoteEJBObjectFactory.class.getName(), null);
         return reference;
     }
@@ -103,4 +87,5 @@
     public static GBeanInfo getGBeanInfo() {
         return GBEAN_INFO;
     }
+
 }

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/SessionBuilder.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/SessionBuilder.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/java/org/openejb/deployment/SessionBuilder.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -163,7 +163,7 @@
 
         Map context = ENCConfigBuilder.buildComponentContext(earContext, null, ejbModule, userTransaction, envEntries, ejbRefs, openejbEjbRefs, ejbLocalRefs, openejbEjbLocalRefs, resourceRefs, openejbResourceRefs, resourceEnvRefs, openejbResourceEnvRefs, messageDestinationRefs, serviceRefs, openejbServiceRefs, cl);
         builder.setComponentContext(context);
-        ENCConfigBuilder.setResourceEnvironment(earContext, ejbModule.getModuleURI(), builder, resourceRefs, openejbResourceRefs);
+        ENCConfigBuilder.setResourceEnvironment(ejbModule.getModuleURI(), builder, resourceRefs, openejbResourceRefs);
 
     }
 
@@ -311,11 +311,11 @@
                 String tssBeanLink = openejbSessionBean.getTssLink().trim();
                 URI moduleURI = ejbModule.getModuleURI();
                 String moduleType = NameFactory.EJB_MODULE;
-                tssBeanObjectName = ENCConfigBuilder.buildAbstractNameQuery(moduleURI == null? null: moduleURI.toString(), moduleType, tssBeanLink);
+                tssBeanObjectName = ENCConfigBuilder.buildAbstractNameQuery(null, moduleURI == null? null: moduleURI.toString(), moduleType, tssBeanLink);
                 try {
                     earContext.getConfiguration().findGBean(tssBeanObjectName);
                 } catch (GBeanNotFoundException e) {
-                    tssBeanObjectName = ENCConfigBuilder.buildAbstractNameQuery(null, null, tssBeanLink);
+                    tssBeanObjectName = ENCConfigBuilder.buildAbstractNameQuery(null, null, null, tssBeanLink);
                     try {
                         earContext.getConfiguration().findGBean(tssBeanObjectName);
                     } catch (GBeanNotFoundException e1) {

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/AbstractDeploymentTest.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/AbstractDeploymentTest.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/AbstractDeploymentTest.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -104,7 +104,7 @@
     public void testInClassLoaderInvoke() throws Exception {
         Object statelessHome;
         Object stateless;
-        EJBProxyReference proxyReference = EJBProxyReference.createRemote(STATELESS_BEAN_NAME.getCanonicalName(),
+        EJBProxyReference proxyReference = EJBProxyReference.createRemote(configurationId, STATELESS_BEAN_NAME.getCanonicalName(),
                         true,
                 "org.openejb.test.simple.slsb.SimpleStatelessSessionHome", "org.openejb.test.simple.slsb.SimpleStatelessSession");
         proxyReference.setKernel(getKernel());
@@ -118,7 +118,7 @@
     public void testCrossClassLoaderInvoke() throws Exception {
         Object statelessHome;
         Object stateless;
-        EJBProxyReference proxyReference = EJBProxyReference.createRemote(STATELESS_BEAN_NAME.getCanonicalName(),
+        EJBProxyReference proxyReference = EJBProxyReference.createRemote(configurationId, STATELESS_BEAN_NAME.getCanonicalName(),
                         true,
                 "org.openejb.test.simple.slsb.SimpleStatelessSessionHome", "org.openejb.test.simple.slsb.SimpleStatelessSession");
         proxyReference.setKernel(getKernel());

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/DeploymentTestContants.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/DeploymentTestContants.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/DeploymentTestContants.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -87,7 +87,7 @@
             return DeploymentHelper.RESOURCE_ADAPTER_NAME;
         }
 
-        public GBeanData locateActivationSpecInfo(GBeanData resourceAdapterModuleName, String messageListenerInterface) {
+        public GBeanData locateActivationSpecInfo(AbstractNameQuery resourceAdapterModuleName, String messageListenerInterface, Configuration configuration) {
             return DeploymentHelper.ACTIVATION_SPEC_INFO;
         }
 

Modified: branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/slsb/BasicStatelessContainerTest.java (2557 => 2558)

--- branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/slsb/BasicStatelessContainerTest.java	2006-03-14 21:21:35 UTC (rev 2557)
+++ branches/v2_1/openejb2/modules/openejb-builder/src/test/org/openejb/deployment/slsb/BasicStatelessContainerTest.java	2006-03-15 08:21:07 UTC (rev 2558)
@@ -72,7 +72,7 @@
     private GBeanData container;
 
     public void testCrossClInvocation() throws Throwable {
-        EJBProxyReference proxyReference = EJBProxyReference.createRemote(CONTAINER_NAME.getCanonicalName(),
+        EJBProxyReference proxyReference = EJBProxyReference.createRemote(configurationId, CONTAINER_NAME.getCanonicalName(),
                         true,
                 MockHome.class.getName(), MockRemote.class.getName());
         proxyReference.setKernel(kernel);

Reply via email to