djencks     2005/08/09 22:24:56

  Modified:    modules/openejb-builder/src/java/org/openejb/deployment
                        AbstractContainerBuilder.java EntityBuilder.java
                        MdbBuilder.java OpenEJBModuleBuilder.java
                        RemoteEJBReferenceBuilder.java SessionBuilder.java
  Added:       modules/openejb-builder/src/java/org/openejb/deployment
                        OpenEJBReferenceBuilder.java
  Log:

  GERONIMO-552 use querying gbeandatas for ejb and implicit ejb-refs. Also 
correct case of ejb container attribute names.
  
  Revision  Changes    Path
  1.15      +13 -14    
openejb/modules/openejb-builder/src/java/org/openejb/deployment/AbstractContainerBuilder.java
  
  Index: AbstractContainerBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/AbstractContainerBuilder.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- AbstractContainerBuilder.java     2 Jun 2005 02:57:00 -0000       1.14
  +++ AbstractContainerBuilder.java     10 Aug 2005 02:24:56 -0000      1.15
  @@ -62,7 +62,6 @@
   import org.apache.geronimo.transaction.TrackedConnectionAssociator;
   import org.apache.geronimo.transaction.context.TransactionContextManager;
   import org.apache.geronimo.transaction.context.UserTransactionImpl;
  -import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   import org.openejb.EJBContainer;
   import org.openejb.EJBInterfaceType;
   import org.openejb.GenericEJBContainer;
  @@ -495,20 +494,20 @@
                                               ObjectName timerName) throws 
Exception {
   
           GBeanData gbean = new GBeanData(GenericEJBContainer.GBEAN_INFO);
  -        gbean.setAttribute("ContainerID", getContainerId());
  -        gbean.setAttribute("EJBName", getEJBName());
  -        gbean.setAttribute("ProxyInfo", createProxyInfo());
  -        gbean.setAttribute("Signatures", signatures);
  -        gbean.setAttribute("ContextFactory", contextFactory);
  -        gbean.setAttribute("InterceptorBuilder", interceptorBuilder);
  -        gbean.setAttribute("Pool", pool);
  +        gbean.setAttribute("containerID", getContainerId());
  +        gbean.setAttribute("ejbName", getEJBName());
  +        gbean.setAttribute("proxyInfo", createProxyInfo());
  +        gbean.setAttribute("signatures", signatures);
  +        gbean.setAttribute("contextFactory", contextFactory);
  +        gbean.setAttribute("interceptorBuilder", interceptorBuilder);
  +        gbean.setAttribute("pool", pool);
           gbean.setAttribute("componentContext", getComponentContext());
  -        gbean.setAttribute("UserTransaction", getUserTransaction());
  -        gbean.setAttribute("JndiNames", getJndiNames());
  -        gbean.setAttribute("LocalJndiNames", getLocalJndiNames());
  +        gbean.setAttribute("userTransaction", getUserTransaction());
  +        gbean.setAttribute("jndiNames", getJndiNames());
  +        gbean.setAttribute("localJndiNames", getLocalJndiNames());
           gbean.setReferencePattern("Timer", timerName);
  -        gbean.setAttribute("DefaultPrincipal", getDefaultPrincipal());
  -        gbean.setAttribute("RunAsSubject", getRunAs());
  +        gbean.setAttribute("defaultPrincipal", getDefaultPrincipal());
  +        gbean.setAttribute("runAsSubject", getRunAs());
           gbean.setAttribute("homeTxPolicyConfig", getHomeTxPolicyConfig());
           gbean.setAttribute("remoteTxPolicyConfig", 
getRemoteTxPolicyConfig());
   
  
  
  
  1.20      +50 -22    
openejb/modules/openejb-builder/src/java/org/openejb/deployment/EntityBuilder.java
  
  Index: EntityBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/EntityBuilder.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- EntityBuilder.java        14 Jun 2005 18:44:45 -0000      1.19
  +++ EntityBuilder.java        10 Aug 2005 02:24:56 -0000      1.20
  @@ -50,7 +50,6 @@
   import java.net.URI;
   import java.security.Permissions;
   import java.util.Map;
  -import java.util.Set;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   import javax.transaction.UserTransaction;
  @@ -62,6 +61,7 @@
   import org.apache.geronimo.j2ee.deployment.RefContext;
   import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
  +import org.apache.geronimo.kernel.ClassLoading;
   import org.apache.geronimo.naming.deployment.ENCConfigBuilder;
   import org.apache.geronimo.security.deployment.SecurityConfiguration;
   import org.apache.geronimo.security.jacc.ComponentPermissions;
  @@ -80,6 +80,9 @@
   import org.apache.geronimo.xbeans.j2ee.ResourceEnvRefType;
   import org.apache.geronimo.xbeans.j2ee.ResourceRefType;
   import org.apache.geronimo.xbeans.j2ee.ServiceRefType;
  +import org.openejb.EJBComponentType;
  +import org.openejb.GenericEJBContainer;
  +import org.openejb.proxy.ProxyInfo;
   import org.openejb.transaction.TransactionPolicySource;
   import org.openejb.xbeans.ejbjar.OpenejbEntityBeanType;
   import org.openejb.xbeans.ejbjar.OpenejbTssType;
  @@ -96,11 +99,11 @@
           for (int i = 0; i < bmpEntityBeans.length; i++) {
               EntityBeanType entityBean = bmpEntityBeans[i];
   
  -            if 
(!"Bean".equals(entityBean.getPersistenceType().getStringValue())) {
  +            if 
(!"Bean".equals(entityBean.getPersistenceType().getStringValue().trim())) {
                   continue;
               }
   
  -            OpenejbEntityBeanType openejbEntityBean = 
(OpenejbEntityBeanType) 
openejbBeans.get(entityBean.getEjbName().getStringValue());
  +            OpenejbEntityBeanType openejbEntityBean = 
(OpenejbEntityBeanType) 
openejbBeans.get(entityBean.getEjbName().getStringValue().trim());
               ObjectName entityObjectName = 
createEJBObjectName(moduleJ2eeContext, entityBean);
   
               GBeanData entityGBean = createBean(earContext, ejbModule, 
entityObjectName, entityBean, openejbEntityBean, componentPermissions, 
transactionPolicyHelper, cl, policyContextID);
  @@ -109,7 +112,7 @@
       }
   
       public GBeanData createBean(EARContext earContext, EJBModule ejbModule, 
ObjectName containerObjectName, EntityBeanType entityBean, 
OpenejbEntityBeanType openejbEntityBean, ComponentPermissions 
componentPermissions, TransactionPolicyHelper transactionPolicyHelper, 
ClassLoader cl, String policyContextID) throws DeploymentException {
  -        String ejbName = entityBean.getEjbName().getStringValue();
  +        String ejbName = entityBean.getEjbName().getStringValue().trim();
   
           BMPContainerBuilder builder = new BMPContainerBuilder();
           builder.setClassLoader(cl);
  @@ -154,7 +157,10 @@
                   }
               } else if (openejbEntityBean.isSetTssLink()) {
                   String tssBeanLink = openejbEntityBean.getTssLink().trim();
  -                tssBeanObjectName = 
earContext.getRefContext().locateComponent(tssBeanLink, NameFactory.CORBA_TSS, 
earContext.getJ2eeContext(), earContext, "TSS GBean");
  +                //todo check this is correct
  +                URI moduleURI = null;
  +                String moduleType = null;
  +                tssBeanObjectName = 
earContext.getRefContext().locateComponentName(tssBeanLink, moduleURI, 
moduleType, NameFactory.CORBA_TSS, earContext.getJ2eeContext(), earContext, 
"TSS GBean");
               } else if (openejbEntityBean.isSetTss()) {
                   OpenejbTssType tss = openejbEntityBean.getTss();
                   try {
  @@ -227,46 +233,68 @@
   
           MessageDestinationRefType[] messageDestinationRefs = 
entityBean.getMessageDestinationRefArray();
   
  -        Map context = ENCConfigBuilder.buildComponentContext(earContext, 
ejbModule, userTransaction, envEntries, ejbRefs, openejbEjbRefs, ejbLocalRefs, 
openejbEjbLocalRefs, resourceRefs, openejbResourceRefs, resourceEnvRefs, 
openejbResourceEnvRefs, messageDestinationRefs, serviceRefs, 
openejbServiceRefs, cl);
  +        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);
       }
   
  -    public void initContext(RefContext refContext, J2eeContext 
moduleJ2eeContext, URI moduleUri, ClassLoader cl, EnterpriseBeansType 
enterpriseBeans, Set interfaces) throws DeploymentException {
  +    public void initContext(EARContext earContext, J2eeContext 
moduleJ2eeContext, URI moduleUri, ClassLoader cl, EnterpriseBeansType 
enterpriseBeans) throws DeploymentException {
           // Entity Beans
  +        RefContext refContext = earContext.getRefContext();
           EntityBeanType[] entityBeans = enterpriseBeans.getEntityArray();
           for (int i = 0; i < entityBeans.length; i++) {
               EntityBeanType entityBean = entityBeans[i];
               String ejbName = entityBean.getEjbName().getStringValue();
   
               ObjectName entityObjectName = 
createEJBObjectName(moduleJ2eeContext, entityBean);
  +            GBeanData gbean = new GBeanData(entityObjectName, 
GenericEJBContainer.GBEAN_INFO);
  +
  +            Class homeInterface = null;
  +            Class remoteInterface = null;
  +            Class localHomeInterface = null;
  +            Class localObjectInterface = null;
   
               // ejb-ref
               if (entityBean.isSetRemote()) {
  -                String remote = 
OpenEJBModuleBuilder.getJ2eeStringValue(entityBean.getRemote());
  -                ENCConfigBuilder.assureEJBObjectInterface(remote, cl);
  +                String remote = 
entityBean.getRemote().getStringValue().trim();
  +                remoteInterface = 
ENCConfigBuilder.assureEJBObjectInterface(remote, cl);
   
  -                String home = 
OpenEJBModuleBuilder.getJ2eeStringValue(entityBean.getHome());
  -                ENCConfigBuilder.assureEJBHomeInterface(home, cl);
  +                String home = entityBean.getHome().getStringValue().trim();
  +                homeInterface = 
ENCConfigBuilder.assureEJBHomeInterface(home, cl);
   
  -                interfaces.add(remote);
  -                interfaces.add(home);
  -
  -                String objectName = entityObjectName.getCanonicalName();
  -                refContext.addEJBRemoteId(moduleUri, ejbName, objectName, 
false, home, remote);
  +//                String objectName = entityObjectName.getCanonicalName();
  +//                refContext.addEJBRemoteId(moduleUri, ejbName, objectName, 
false, home, remote);
               }
   
               // ejb-local-ref
               if (entityBean.isSetLocal()) {
  -                String local = 
OpenEJBModuleBuilder.getJ2eeStringValue(entityBean.getLocal());
  -                ENCConfigBuilder.assureEJBLocalObjectInterface(local, cl);
  +                String local = entityBean.getLocal().getStringValue().trim();
  +                localObjectInterface = 
ENCConfigBuilder.assureEJBLocalObjectInterface(local, cl);
   
  -                String localHome = 
OpenEJBModuleBuilder.getJ2eeStringValue(entityBean.getLocalHome());
  -                ENCConfigBuilder.assureEJBLocalHomeInterface(localHome, cl);
  +                String localHome = 
entityBean.getLocalHome().getStringValue().trim();
  +                localHomeInterface = 
ENCConfigBuilder.assureEJBLocalHomeInterface(localHome, cl);
   
  -                String objectName = entityObjectName.getCanonicalName();
  -                refContext.addEJBLocalId(moduleUri, ejbName, objectName, 
false, localHome, local);
  +//                String objectName = entityObjectName.getCanonicalName();
  +//                refContext.addEJBLocalId(moduleUri, ejbName, objectName, 
false, localHome, local);
  +            }
  +            int componentType = 
entityBean.getPersistenceType().getStringValue().trim().equals("Bean")? 
EJBComponentType.BMP_ENTITY: EJBComponentType.CMP_ENTITY;
  +            String className = 
entityBean.getPrimKeyClass().getStringValue().trim();
  +                    Class primaryKeyClass = null;
  +            try {
  +                primaryKeyClass = ClassLoading.loadClass(className, cl);
  +            } catch (ClassNotFoundException e) {
  +                throw new DeploymentException("Could not load primary key 
class: " + className + " for entity: " + entityObjectName);
               }
  +            ProxyInfo proxyInfo = new ProxyInfo(componentType,
  +                    entityObjectName.getCanonicalName(),
  +                    homeInterface,
  +                    remoteInterface,
  +                    localHomeInterface,
  +                    localObjectInterface,
  +                    null,
  +                    primaryKeyClass);
  +            gbean.setAttribute("proxyInfo", proxyInfo);
  +            earContext.addGBean(gbean);
           }
       }
   
  
  
  
  1.24      +1 -1      
openejb/modules/openejb-builder/src/java/org/openejb/deployment/MdbBuilder.java
  
  Index: MdbBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/MdbBuilder.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- MdbBuilder.java   27 Jul 2005 20:40:16 -0000      1.23
  +++ MdbBuilder.java   10 Aug 2005 02:24:56 -0000      1.24
  @@ -337,7 +337,7 @@
   
           MessageDestinationRefType[] messageDestinationRefs = 
messageDrivenBean.getMessageDestinationRefArray();
   
  -        Map context = ENCConfigBuilder.buildComponentContext(earContext, 
ejbModule, userTransaction, envEntries, ejbRefs, openejbEjbRefs, ejbLocalRefs, 
openejbEjbLocalRefs, resourceRefs, openejbResourceRefs, resourceEnvRefs, 
openejbResourceEnvRefs, messageDestinationRefs, serviceRefs, 
openejbServiceRefs, cl);
  +        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);
   
  
  
  
  1.50      +13 -26    
openejb/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBModuleBuilder.java
  
  Index: OpenEJBModuleBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBModuleBuilder.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- OpenEJBModuleBuilder.java 23 Jul 2005 05:57:31 -0000      1.49
  +++ OpenEJBModuleBuilder.java 10 Aug 2005 02:24:56 -0000      1.50
  @@ -63,12 +63,15 @@
   import java.util.List;
   import java.util.ArrayList;
   import java.util.Collections;
  +import java.util.Collection;
  +import java.util.Iterator;
   import java.util.jar.JarFile;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   import javax.naming.Reference;
   
   import org.apache.geronimo.common.DeploymentException;
  +import org.apache.geronimo.common.UnresolvedEJBRefException;
   import org.apache.geronimo.deployment.service.ServiceConfigBuilder;
   import org.apache.geronimo.deployment.util.DeploymentUtil;
   import org.apache.geronimo.deployment.xbeans.DependencyType;
  @@ -83,12 +86,14 @@
   import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
   import org.apache.geronimo.j2ee.deployment.RefContext;
   import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
  +import org.apache.geronimo.j2ee.deployment.NamingContext;
   import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
   import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   import org.apache.geronimo.kernel.repository.Repository;
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.kernel.GBeanNotFoundException;
  +import org.apache.geronimo.kernel.jmx.JMXUtil;
   import org.apache.geronimo.schema.SchemaConversionUtils;
   import org.apache.geronimo.security.deployment.SecurityBuilder;
   import org.apache.geronimo.security.deployment.SecurityConfiguration;
  @@ -110,6 +115,7 @@
   import org.openejb.deployment.pkgen.TranQLPKGenBuilder;
   import org.openejb.proxy.EJBProxyFactory;
   import org.openejb.proxy.EJBProxyReference;
  +import org.openejb.proxy.ProxyInfo;
   import org.openejb.xbeans.ejbjar.OpenejbEntityBeanType;
   import org.openejb.xbeans.ejbjar.OpenejbMessageDrivenBeanType;
   import org.openejb.xbeans.ejbjar.OpenejbOpenejbJarDocument;
  @@ -136,7 +142,7 @@
    *
    * @version $Revision$ $Date$
    */
  -public class OpenEJBModuleBuilder implements ModuleBuilder, 
EJBReferenceBuilder {
  +public class OpenEJBModuleBuilder implements ModuleBuilder {
   
       private final URI defaultParentId;
       private final ObjectName listener;
  @@ -328,30 +334,12 @@
           EjbJarType ejbJar = (EjbJarType) ejbModule.getSpecDD();
           EnterpriseBeansType enterpriseBeans = ejbJar.getEnterpriseBeans();
   
  -        Set interfaces = new HashSet();
  -        RefContext refContext = earContext.getRefContext();
  -        sessionBuilder.initContext(refContext, moduleJ2eeContext, moduleUri, 
cl, enterpriseBeans, interfaces);
  -        entityBuilder.initContext(refContext, moduleJ2eeContext, moduleUri, 
cl, enterpriseBeans, interfaces);
  +        sessionBuilder.initContext(earContext, moduleJ2eeContext, moduleUri, 
cl, enterpriseBeans);
  +        entityBuilder.initContext(earContext, moduleJ2eeContext, moduleUri, 
cl, enterpriseBeans);
           mdbBuilder.initContext(cl, enterpriseBeans);
   
       }
   
  -    public Reference createEJBLocalReference(String objectName, boolean 
session, String localHome, String local) {
  -        return EJBProxyReference.createLocal(objectName, session, local, 
localHome);
  -    }
  -
  -    public Reference createEJBRemoteReference(String objectName, boolean 
session, String home, String remote) {
  -        return EJBProxyReference.createRemote(objectName, session, remote, 
home);
  -    }
  -
  -    public Reference createCORBAReference(URI corbaURL, String objectName, 
ObjectName containerName, String home) throws DeploymentException {
  -        return new CORBAProxyReference(corbaURL, objectName, containerName, 
home);
  -    }
  -
  -    public Object createHandleDelegateReference() {
  -        return new CORBAHandleDelegate.HandleDelegateReference();
  -    }
  -
       public CMPEntityBuilder getCmpEntityBuilder() {
           return cmpEntityBuilder;
       }
  @@ -475,15 +463,15 @@
           Set beans = new HashSet();
           EntityBeanType[] ebs = enterpriseBeans.getEntityArray();
           for (int i = 0; i < ebs.length; i++) {
  -            beans.add(ebs[i].getEjbName().getStringValue());
  +            beans.add(ebs[i].getEjbName().getStringValue().trim());
           }
           SessionBeanType[] sbs = enterpriseBeans.getSessionArray();
           for (int i = 0; i < sbs.length; i++) {
  -            beans.add(sbs[i].getEjbName().getStringValue());
  +            beans.add(sbs[i].getEjbName().getStringValue().trim());
           }
           MessageDrivenBeanType[] mbs = 
enterpriseBeans.getMessageDrivenArray();
           for (int i = 0; i < mbs.length; i++) {
  -            beans.add(mbs[i].getEjbName().getStringValue());
  +            beans.add(mbs[i].getEjbName().getStringValue().trim());
           }
   
           // create an index of the openejb ejb configurations by ejb-name
  @@ -648,7 +636,6 @@
           infoBuilder.addReference("WebServiceBuilder", 
WebServiceBuilder.class, NameFactory.MODULE_BUILDER);
           infoBuilder.addReference("Repository", Repository.class, 
NameFactory.GERONIMO_SERVICE);
           infoBuilder.addInterface(ModuleBuilder.class);
  -        infoBuilder.addInterface(EJBReferenceBuilder.class);
           infoBuilder.addAttribute("kernel", Kernel.class, false);
   
           infoBuilder.setConstructor(new String[]{"defaultParentId", 
"listener", "WebServiceLinkTemplate", "WebServiceBuilder", "Repository", 
"kernel"});
  
  
  
  1.6       +17 -11    
openejb/modules/openejb-builder/src/java/org/openejb/deployment/RemoteEJBReferenceBuilder.java
  
  Index: RemoteEJBReferenceBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/RemoteEJBReferenceBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RemoteEJBReferenceBuilder.java    8 Mar 2005 04:08:30 -0000       1.5
  +++ RemoteEJBReferenceBuilder.java    10 Aug 2005 02:24:56 -0000      1.6
  @@ -48,41 +48,47 @@
   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.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.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;
   
   
   /**
    */
  -public class RemoteEJBReferenceBuilder implements EJBReferenceBuilder {
  +public class RemoteEJBReferenceBuilder extends OpenEJBReferenceBuilder {
   
  -    public Reference createEJBLocalReference(String objectName, boolean 
isSession, String localHome, String local) {
  +    public Reference createEJBLocalReference(String objectName, GBeanData 
gbeanData, 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) {
  +    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);
           Reference reference = new Reference(null, addr, 
RemoteEJBObjectFactory.class.getName(), null);
           return reference;
  -    }
  -
  -    public Reference createCORBAReference(URI corbaURL, String objectName, 
ObjectName containerName, String home) throws DeploymentException {
  -        return new CORBAProxyReference(corbaURL, objectName, containerName, 
home);
  -    }
  -
  -    public Object createHandleDelegateReference() {
  -        return new CORBAHandleDelegate.HandleDelegateReference();
       }
   
       public static final GBeanInfo GBEAN_INFO;
  
  
  
  1.31      +40 -24    
openejb/modules/openejb-builder/src/java/org/openejb/deployment/SessionBuilder.java
  
  Index: SessionBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/SessionBuilder.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- SessionBuilder.java       23 Jul 2005 05:57:31 -0000      1.30
  +++ SessionBuilder.java       10 Aug 2005 02:24:56 -0000      1.31
  @@ -47,15 +47,11 @@
    */
   package org.openejb.deployment;
   
  -import java.net.MalformedURLException;
   import java.net.URI;
   import java.net.URL;
   import java.security.Permissions;
  -import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
  -import java.util.Set;
  -import java.util.Iterator;
   import java.util.jar.JarFile;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
  @@ -96,7 +92,10 @@
   import org.apache.geronimo.xbeans.j2ee.WebserviceDescriptionType;
   import org.apache.geronimo.xbeans.j2ee.WebservicesDocument;
   import org.apache.xmlbeans.XmlException;
  +import org.openejb.EJBComponentType;
  +import org.openejb.GenericEJBContainer;
   import org.openejb.dispatch.InterfaceMethodSignature;
  +import org.openejb.proxy.ProxyInfo;
   import org.openejb.slsb.HandlerChainConfiguration;
   import org.openejb.transaction.TransactionPolicySource;
   import org.openejb.transaction.TransactionPolicyType;
  @@ -165,7 +164,7 @@
   
           MessageDestinationRefType[] messageDestinationRefs = 
sessionBean.getMessageDestinationRefArray();
   
  -        Map context = ENCConfigBuilder.buildComponentContext(earContext, 
ejbModule, userTransaction, envEntries, ejbRefs, openejbEjbRefs, ejbLocalRefs, 
openejbEjbLocalRefs, resourceRefs, openejbResourceRefs, resourceEnvRefs, 
openejbResourceEnvRefs, messageDestinationRefs, serviceRefs, 
openejbServiceRefs, cl);
  +        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);
   
  @@ -302,7 +301,10 @@
                   }
               } else if (openejbSessionBean.isSetTssLink()) {
                   String tssBeanLink = openejbSessionBean.getTssLink().trim();
  -                tssBeanObjectName = 
earContext.getRefContext().locateComponent(tssBeanLink, NameFactory.CORBA_TSS, 
earContext.getJ2eeContext(), earContext, "TSS GBean");
  +                //todo check this is correct
  +                URI moduleURI = null;
  +                String moduleType = null;
  +                tssBeanObjectName = 
earContext.getRefContext().locateComponentName(tssBeanLink, moduleURI, 
moduleType, NameFactory.CORBA_TSS, earContext.getJ2eeContext(), earContext, 
"TSS GBean");
               } else if (openejbSessionBean.isSetTss()) {
                   OpenejbTssType tss = openejbSessionBean.getTss();
                   try {
  @@ -373,41 +375,55 @@
           }
       }
   
  -    public void initContext(RefContext refContext, J2eeContext 
moduleJ2eeContext, URI moduleUri, ClassLoader cl, EnterpriseBeansType 
enterpriseBeans, Set interfaces) throws DeploymentException {
  +    public void initContext(EARContext earContext, J2eeContext 
moduleJ2eeContext, URI moduleUri, ClassLoader cl, EnterpriseBeansType 
enterpriseBeans) throws DeploymentException {
           // Session Beans
  +        RefContext refContext = earContext.getRefContext();
           SessionBeanType[] sessionBeans = enterpriseBeans.getSessionArray();
           for (int i = 0; i < sessionBeans.length; i++) {
               SessionBeanType sessionBean = sessionBeans[i];
               String ejbName = sessionBean.getEjbName().getStringValue();
   
               ObjectName sessionObjectName = 
createEJBObjectName(moduleJ2eeContext, sessionBean);
  +            GBeanData gbean = new GBeanData(sessionObjectName, 
GenericEJBContainer.GBEAN_INFO);
   
  +            Class homeInterface = null;
  +            Class remoteInterface = null;
  +            Class localHomeInterface = null;
  +            Class localObjectInterface = null;
               // ejb-ref
               if (sessionBean.isSetRemote()) {
  -                String remote = 
OpenEJBModuleBuilder.getJ2eeStringValue(sessionBean.getRemote());
  -                ENCConfigBuilder.assureEJBObjectInterface(remote, cl);
  +                String remote =  
sessionBean.getRemote().getStringValue().trim();
  +                remoteInterface = 
ENCConfigBuilder.assureEJBObjectInterface(remote, cl);
   
  -                String home = 
OpenEJBModuleBuilder.getJ2eeStringValue(sessionBean.getHome());
  -                ENCConfigBuilder.assureEJBHomeInterface(home, cl);
  -
  -                interfaces.add(remote);
  -                interfaces.add(home);
  -
  -                String objectName = sessionObjectName.getCanonicalName();
  -                refContext.addEJBRemoteId(moduleUri, ejbName, objectName, 
true, home, remote);
  +                String home = sessionBean.getHome().getStringValue().trim();
  +                homeInterface = 
ENCConfigBuilder.assureEJBHomeInterface(home, cl);
  +                //TODO remove
  +//                String objectName = sessionObjectName.getCanonicalName();
  +//                refContext.addEJBRemoteId(moduleUri, ejbName, objectName, 
true, home, remote);
               }
   
               // ejb-local-ref
               if (sessionBean.isSetLocal()) {
  -                String local = 
OpenEJBModuleBuilder.getJ2eeStringValue(sessionBean.getLocal());
  -                ENCConfigBuilder.assureEJBLocalObjectInterface(local, cl);
  -
  -                String localHome = 
OpenEJBModuleBuilder.getJ2eeStringValue(sessionBean.getLocalHome());
  -                ENCConfigBuilder.assureEJBLocalHomeInterface(localHome, cl);
  +                String local = 
sessionBean.getLocal().getStringValue().trim();
  +                localObjectInterface = 
ENCConfigBuilder.assureEJBLocalObjectInterface(local, cl);
   
  -                String objectName = sessionObjectName.getCanonicalName();
  -                refContext.addEJBLocalId(moduleUri, ejbName, objectName, 
true, localHome, local);
  +                String localHome = 
sessionBean.getLocalHome().getStringValue().trim();
  +                localHomeInterface = 
ENCConfigBuilder.assureEJBLocalHomeInterface(localHome, cl);
  +                //TODO remove
  +//                String objectName = sessionObjectName.getCanonicalName();
  +//                refContext.addEJBLocalId(moduleUri, ejbName, objectName, 
true, localHome, local);
               }
  +            int componentType = 
sessionBean.getSessionType().getStringValue().trim().equals("Stateless")? 
EJBComponentType.STATELESS: EJBComponentType.STATEFUL;
  +            ProxyInfo proxyInfo = new ProxyInfo(componentType,
  +                    sessionObjectName.getCanonicalName(),
  +                    homeInterface,
  +                    remoteInterface,
  +                    localHomeInterface,
  +                    localObjectInterface,
  +                    null,
  +                    null);
  +            gbean.setAttribute("proxyInfo", proxyInfo);
  +            earContext.addGBean(gbean);
           }
       }
   
  
  
  
  1.1                  
openejb/modules/openejb-builder/src/java/org/openejb/deployment/OpenEJBReferenceBuilder.java
  
  Index: OpenEJBReferenceBuilder.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  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.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.GBeanData;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoBuilder;
  import org.apache.geronimo.kernel.GBeanNotFoundException;
  import org.apache.geronimo.kernel.jmx.JMXUtil;
  import org.openejb.proxy.EJBProxyReference;
  import org.openejb.proxy.ProxyInfo;
  import org.openejb.corba.proxy.CORBAProxyReference;
  import org.openejb.corba.CORBAHandleDelegate;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2005/08/10 02:24:56 $
   */
  public class OpenEJBReferenceBuilder implements EJBReferenceBuilder {
      private final static ObjectName STATELESS = 
JMXUtil.getObjectName("*:j2eeType=StatelessSessionBean,*");
      private final static ObjectName STATEFUL = 
JMXUtil.getObjectName("*:j2eeType=StatefulSessionBean,*");
      private final static ObjectName ENTITY = 
JMXUtil.getObjectName("*:j2eeType=EntityBean,*");
  
      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());
              }
          }
          return buildLocalReference(objectName, session, localHome, local);
      }
  
      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());
              }
          }
          return buildRemoteReference(objectName, session, home, remote);
      }
  
      public Reference createCORBAReference(URI corbaURL, String objectName, 
ObjectName containerName, String home) throws DeploymentException {
          return new CORBAProxyReference(corbaURL, objectName, containerName, 
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 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);
      }
  
      protected Reference buildLocalReference(String objectName, boolean 
session, String localHome, String local) {
          return EJBProxyReference.createLocal(objectName, session, localHome, 
local);
      }
  
      protected Reference buildRemoteReference(String objectName, boolean 
session, String home, String remote) {
          return EJBProxyReference.createRemote(objectName, session, home, 
remote);
      }
  
      private ObjectName getImplicitMatch(boolean isSession, NamingContext 
context, boolean isRemote, String home, String remote, String refName, URI 
module) throws DeploymentException {
          Set gbeans;
          if (isSession) {
              gbeans = context.listGBeans(STATELESS);
              gbeans.addAll(context.listGBeans(STATEFUL));
          } else {
              gbeans = context.listGBeans(ENTITY);
          }
          Collection matches = new ArrayList();
          for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
              ObjectName objectName = (ObjectName) iterator.next();
              GBeanData data = null;
              try {
                  data = context.getGBeanInstance(objectName);
              } catch (GBeanNotFoundException e) {
                  throw new DeploymentException("We just got this ejb name out 
of a query! It must be there!");
              }
              if (matchesProxyInfo(data, isRemote, home, remote)) {
                  matches.add(objectName);
              }
          }
          if (matches.isEmpty()) {
              throw new UnresolvedEJBRefException(refName, false, isSession, 
home, remote, false);
          }
          ObjectName match;
          if (matches.size() == 1) {
              match = (ObjectName) 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()))) 
{
                      iterator.remove();
                  }
              }
              if (matches.size() == 1) {
                  match = (ObjectName) matches.iterator().next();
              } else {
                  throw new UnresolvedEJBRefException(refName, false, 
isSession, home, remote, matches.size() > 0);
              }
          }
          return match;
      }
  
      private boolean matchesProxyInfo(GBeanData data, boolean isRemote, String 
home, String remote) {
          ProxyInfo proxyInfo = (ProxyInfo) data.getAttribute("proxyInfo");
          if (isRemote) {
              return proxyInfo.getHomeInterface().getName().equals(home)
                      && 
proxyInfo.getRemoteInterface().getName().equals(remote);
          } else {
              return proxyInfo.getLocalHomeInterface().getName().equals(home)
                      && proxyInfo.getLocalInterface().getName().equals(remote);
          }
      }
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          GBeanInfoBuilder infoFactory = new 
GBeanInfoBuilder(OpenEJBReferenceBuilder.class, NameFactory.MODULE_BUILDER); 
//TODO decide what type this should be
          infoFactory.addInterface(EJBReferenceBuilder.class);
  
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  
  }
  
  
  

Reply via email to