geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java ContextBuilderTest.java
Date Thu, 13 Nov 2003 04:30:56 GMT
djencks     2003/11/12 20:30:56

  Modified:    modules/core/src/java/org/apache/geronimo/client
                        Launcher.java
               modules/core/src/java/org/apache/geronimo/naming/java
                        ComponentContextBuilder.java ReadOnlyContext.java
               modules/core/src/test/org/apache/geronimo/naming/java
                        ContextBuilderTest.java
  Added:       modules/core/src/java/org/apache/geronimo/naming/java
                        ReferenceFactory.java
  Log:
  Use references to the jmx namespace to look up ejbs and resources in the java:comp local
context.  The references are supplied by a ReferenceFactory, making the reference scheme pluggable.
  
  Revision  Changes    Path
  1.9       +6 -2      incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/Launcher.java
  
  Index: Launcher.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/Launcher.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Launcher.java	19 Oct 2003 01:56:13 -0000	1.8
  +++ Launcher.java	13 Nov 2003 04:30:56 -0000	1.9
  @@ -91,6 +91,8 @@
   import org.apache.geronimo.kernel.jmx.JMXUtil;
   import org.apache.geronimo.naming.java.ComponentContextBuilder;
   import org.apache.geronimo.naming.java.ReadOnlyContext;
  +import org.apache.geronimo.naming.java.ReferenceFactory;
  +import org.apache.geronimo.naming.jmx.JMXReferenceFactory;
   import org.apache.geronimo.proxy.ProxyInvocation;
   import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
   import org.apache.geronimo.transaction.manager.UserTransactionImpl;
  @@ -206,7 +208,9 @@
   
           UserTransaction userTransaction = txnManager == null ? null : new UserTransactionImpl(txnManager);
           ApplicationClient appClient = loadAppClientDescriptor();
  -        ReadOnlyContext compContext = new ComponentContextBuilder(userTransaction).buildContext(appClient);
  +        ReferenceFactory referenceFactory = new JMXReferenceFactory(kernel.getMBeanServerId());
  +
  +        ReadOnlyContext compContext = new ComponentContextBuilder(referenceFactory, userTransaction).buildContext(appClient);
   
           AppClientContainer clientMBean = new AppClientContainer(clientURL, mainClassName,
compContext);
           clientName = JMXUtil.getObjectName("geronimo.client:url=" + ObjectName.quote(clientURL.toString()));
  
  
  
  1.9       +21 -11    incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
  
  Index: ComponentContextBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ComponentContextBuilder.java	15 Oct 2003 02:53:26 -0000	1.8
  +++ ComponentContextBuilder.java	13 Nov 2003 04:30:56 -0000	1.9
  @@ -60,11 +60,14 @@
   import java.util.HashMap;
   import java.util.Map;
   import javax.naming.LinkRef;
  +import javax.naming.Reference;
  +import javax.naming.NamingException;
   import javax.transaction.UserTransaction;
   
   import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbRef;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDIEnvironmentRefs;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceRef;
  +import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDILocator;
   import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
   import org.apache.geronimo.kernel.deployment.DeploymentException;
   
  @@ -74,14 +77,13 @@
    * @version $Revision$ $Date$
    */
   public class ComponentContextBuilder {
  -    private final UserTransaction userTransaction;
   
  -    public ComponentContextBuilder() {
  -        userTransaction = null;
  -    }
  +    private final ReferenceFactory referenceFactory;
  +    private final UserTransaction userTransaction;
   
  -    public ComponentContextBuilder(UserTransaction userTransaction) {
  +    public ComponentContextBuilder(ReferenceFactory referenceFactory, UserTransaction userTransaction)
{
           this.userTransaction = userTransaction;
  +        this.referenceFactory = referenceFactory;
       }
   
       /**
  @@ -144,19 +146,23 @@
           }
       }
   
  -    private static void buildEJBRefs(Map envMap, EjbRef[] ejbRefs) {
  +    private void buildEJBRefs(Map envMap, EjbRef[] ejbRefs) throws DeploymentException
{
           for (int i = 0; i < ejbRefs.length; i++) {
               EjbRef ejbRef = ejbRefs[i];
               String name = ejbRef.getEJBRefName();
  -            String jndiName = ejbRef.getJndiName();
  -            LinkRef ref = new LinkRef(jndiName);
  +            Reference ref = null;
  +            try {
  +                ref = referenceFactory.getReference(ejbRef, ejbRef.getEJBRefType());
  +            } catch (NamingException e) {
  +                throw new DeploymentException("Could not construct reference to " + ejbRef.getJndiName());
  +            }
               if (envMap.put(name, ref) != null) {
                   throw new AssertionError("Duplicate entry for env-entry " + name);
               }
           }
       }
   
  -    private static void buildResourceRefs(Map envMap, ResourceRef[] resRefs) throws DeploymentException
{
  +    private void buildResourceRefs(Map envMap, ResourceRef[] resRefs) throws DeploymentException
{
           for (int i=0; i < resRefs.length; i++) {
               ResourceRef resRef = resRefs[i];
               String name = resRef.getResRefName();
  @@ -169,7 +175,11 @@
                       throw new DeploymentException("Invalid URL for resource-ref "+name,
e);
                   }
               } else {
  -                throw new DeploymentException("Cannot create resource-ref for "+name+",
unknown type "+type);
  +                try {
  +                    ref = referenceFactory.getReference(resRef, "ConnectionFactory");
  +                } catch (NamingException e) {
  +                    throw new DeploymentException("Could not construct reference to " +
resRef.getJndiName());
  +                }
               }
               if (envMap.put(name, ref) != null) {
                   throw new AssertionError("Duplicate entry for resource-ref " + name);
  
  
  
  1.5       +2 -2      incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java
  
  Index: ReadOnlyContext.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReadOnlyContext.java	4 Sep 2003 05:16:17 -0000	1.4
  +++ ReadOnlyContext.java	13 Nov 2003 04:30:56 -0000	1.5
  @@ -215,7 +215,7 @@
       }
   
       public Object lookupLink(Name name) throws NamingException {
  -        return lookupLink(name);
  +        return lookupLink(name.toString());
       }
   
       public NamingEnumeration list(Name name) throws NamingException {
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ReferenceFactory.java
  
  Index: ReferenceFactory.java
  ===================================================================
  package org.apache.geronimo.naming.java;
  
  import javax.naming.Reference;
  import javax.naming.NamingException;
  
  import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDILocator;
  
  /**
   * 
   *
   * @version $VERSION$ Nov 12, 2003$
   * 
   * */
  public interface ReferenceFactory {
  
      Reference getReference(JNDILocator locator, String type) throws NamingException;
  }
  
  
  
  1.7       +57 -6     incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java
  
  Index: ContextBuilderTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContextBuilderTest.java	15 Oct 2003 02:53:26 -0000	1.6
  +++ ContextBuilderTest.java	13 Nov 2003 04:30:56 -0000	1.7
  @@ -58,14 +58,21 @@
   import java.net.URL;
   import javax.naming.Context;
   import javax.naming.NameNotFoundException;
  +import javax.naming.InitialContext;
   import javax.transaction.UserTransaction;
  +import javax.management.ObjectName;
   
   import junit.framework.TestCase;
  +import junit.framework.Test;
   import org.apache.geronimo.deployment.model.geronimo.appclient.ApplicationClient;
   import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbRef;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceRef;
  +import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbLocalRef;
   import org.apache.geronimo.transaction.manager.UserTransactionImpl;
  +import org.apache.geronimo.kernel.jmx.JMXKernel;
  +import org.apache.geronimo.naming.jmx.JMXReferenceFactory;
  +import org.apache.geronimo.naming.jmx.TestObject;
   
   /**
    *
  @@ -73,10 +80,22 @@
    * @version $Revision$ $Date$
    */
   public class ContextBuilderTest extends TestCase {
  +    private static final String objectName1 = "geronimo.test:name=test1";
  +    private static final String objectName2 = "geronimo.test:name=test2";
  +
       private ApplicationClient client;
       private Context compCtx;
  +    private JMXKernel kernel;
  +    private ReferenceFactory referenceFactory;
  +    private TestObject testObject1 = new TestObject(new Object());
  +    private TestObject testObject2 = new TestObject(new Object());
   
       protected void setUp() throws Exception {
  +        kernel = new JMXKernel("geronimo.test");
  +        kernel.getMBeanServer().registerMBean(testObject1, ObjectName.getInstance(objectName1));
  +        kernel.getMBeanServer().registerMBean(testObject2, ObjectName.getInstance(objectName2));
  +
  +        referenceFactory = new JMXReferenceFactory(kernel.getMBeanServerId());
           client = new ApplicationClient();
           EnvEntry stringEntry = new EnvEntry();
           stringEntry.setEnvEntryName("string");
  @@ -87,24 +106,44 @@
           intEntry.setEnvEntryType("java.lang.Integer");
           intEntry.setEnvEntryValue("12345");
   
  +        EjbRef ejbRef = new EjbRef();
  +        ejbRef.setEJBRefName("here/there/EJB1");
  +        ejbRef.setEJBRefType("Home");
  +        ejbRef.setJndiName(objectName1);
  +
  +        //EjbLocalRef ejbLocalRef = new EjbLocalRef();
  +        EjbRef ejbLocalRef = new EjbRef();
  +        ejbLocalRef.setEJBRefName("local/here/LocalEJB2");
  +        ejbLocalRef.setEJBRefType("LocalHome");
  +        ejbLocalRef.setJndiName(objectName2);
  +
           ResourceRef urlRef = new ResourceRef();
           urlRef.setResRefName("url/testURL");
           urlRef.setResType(URL.class.getName());
           urlRef.setJndiName("http://localhost/path");
  +
  +        ResourceRef cfRef = new ResourceRef();
  +        cfRef.setResRefName("DefaultCF");
  +        cfRef.setJndiName(objectName1);
  +
           client.setEnvEntry(new EnvEntry[] { stringEntry, intEntry });
  -        client.setEJBRef(new EjbRef[0]);
  -        client.setResourceRef(new ResourceRef[] { urlRef });
  +        //client.setEJBRef(new EjbRef[] {ejbRef});
  +        client.setEJBRef(new EjbRef[] {ejbRef, ejbLocalRef});
  +        //client.setEJBLocalRef(new EjbLocalRef[] {ejbLocalRef});
  +
  +
  +        client.setResourceRef(new ResourceRef[] { urlRef, cfRef });
       }
   
       public void testEnvEntries() throws Exception {
  -        compCtx = new ComponentContextBuilder().buildContext(client);
  +        compCtx = new ComponentContextBuilder(referenceFactory, null).buildContext(client);
           assertEquals("Hello World", compCtx.lookup("env/string"));
           assertEquals(new Integer(12345), compCtx.lookup("env/int"));
           assertEquals(new URL("http://localhost/path"), compCtx.lookup("env/url/testURL"));
       }
   
       public void testUserTransaction() throws Exception {
  -        compCtx = new ComponentContextBuilder().buildContext(client);
  +        compCtx = new ComponentContextBuilder(referenceFactory, null).buildContext(client);
           try {
               compCtx.lookup("UserTransaction");
               fail("Expected NameNotFoundException");
  @@ -113,7 +152,19 @@
           }
   
           UserTransaction userTransaction = new UserTransactionImpl(null);
  -        compCtx = new ComponentContextBuilder(userTransaction).buildContext(client);
  +        compCtx = new ComponentContextBuilder(referenceFactory, userTransaction).buildContext(client);
           assertEquals(userTransaction, compCtx.lookup("UserTransaction"));
  +    }
  +
  +    public void testEJBRefs() throws Exception {
  +        ReadOnlyContext compContext = new ComponentContextBuilder(referenceFactory, null).buildContext(client);
  +        RootContext.setComponentContext(compContext);
  +        InitialContext initialContext = new InitialContext();
  +        assertEquals("Expected object from testObject1", testObject1.getEJBHome(),
  +                initialContext.lookup("java:comp/env/here/there/EJB1"));
  +        assertEquals("Expected object from testObject2", testObject2.getEJBLocalHome(),
  +                initialContext.lookup("java:comp/env/local/here/LocalEJB2"));
  +        assertEquals("Expected object from testObject1", testObject1.getConnectionFactory(),
  +                initialContext.lookup("java:comp/env/DefaultCF"));
       }
   }
  
  
  

Mime
View raw message