geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java BasicContextTest.java ContextBuilderTest.java
Date Thu, 04 Sep 2003 05:16:18 GMT
jboynes     2003/09/03 22:16:18

  Modified:    modules/core/src/java/org/apache/geronimo/client
                        AppClientContainer.java
               modules/core/src/java/org/apache/geronimo/naming/java
                        ComponentContextBuilder.java
                        ComponentContextInterceptor.java
                        javaURLContextFactory.java ReadOnlyContext.java
                        RootContext.java
               modules/core/src/test/org/apache/geronimo/naming/java
                        BasicContextTest.java ContextBuilderTest.java
  Log:
  Support for ejb-ref in java: ENC
  AppClient support to use ejb-ref - tested against JBoss 3.2.1
  Remote EJB name is currently hard coded - depends on GERONIMO-10 and I don't want to confuse
the patches
  
  Revision  Changes    Path
  1.4       +9 -9      incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/AppClientContainer.java
  
  Index: AppClientContainer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/AppClientContainer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AppClientContainer.java	3 Sep 2003 16:02:05 -0000	1.3
  +++ AppClientContainer.java	4 Sep 2003 05:16:17 -0000	1.4
  @@ -58,12 +58,12 @@
   import java.lang.reflect.Method;
   import java.net.URL;
   import java.net.URLClassLoader;
  -
   import javax.naming.Context;
   
   import org.apache.geronimo.common.AbstractRPCContainer;
   import org.apache.geronimo.deployment.DeploymentException;
   import org.apache.geronimo.naming.java.ComponentContextInterceptor;
  +import org.apache.geronimo.naming.java.ReadOnlyContext;
   
   /**
    *
  @@ -77,32 +77,32 @@
   
       private String mainClassName;
       private URL clientURL;
  -    private Context compContext;
  +    private ReadOnlyContext compContext;
   
       public AppClientContainer() throws DeploymentException {
       }
  -    
  +
       /**
        * @jmx:managed-attribute
        */
       public void setMainClassName(String className) {
           mainClassName = className;
       }
  -    
  +
       /**
        * @jmx:managed-attribute
        */
       public String getMainClassName() {
           return mainClassName;
       }
  -    
  +
       /**
        * @jmx:managed-attribute
        */
       public URL getClientURL() {
           return clientURL;
       }
  -    
  +
       /**
        * @jmx:managed-attribute
        */
  @@ -113,14 +113,14 @@
       /**
        * @jmx:managed-attribute
        */
  -    public Context getComponentContext() {
  +    public ReadOnlyContext getComponentContext() {
           return compContext;
       }
   
       /**
        * @jmx:managed-attribute
        */
  -    public void setComponentContext(Context compContext) {
  +    public void setComponentContext(ReadOnlyContext compContext) {
           this.compContext = compContext;
       }
   
  
  
  
  1.2       +21 -7     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComponentContextBuilder.java	3 Sep 2003 16:02:05 -0000	1.1
  +++ ComponentContextBuilder.java	4 Sep 2003 05:16:17 -0000	1.2
  @@ -58,14 +58,16 @@
   import java.util.HashMap;
   import java.util.Map;
   import javax.naming.Context;
  +import javax.naming.LinkRef;
   
   import org.apache.geronimo.deployment.DeploymentException;
  +import org.apache.geronimo.deployment.model.j2ee.EJBRef;
   import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
   import org.apache.geronimo.deployment.model.j2ee.JNDIEnvironmentRefs;
   
   /**
  - * 
  - * 
  + *
  + *
    * @version $Revision$ $Date$
    */
   public class ComponentContextBuilder {
  @@ -78,6 +80,7 @@
       public static Context buildContext(JNDIEnvironmentRefs refs) throws DeploymentException
{
           Map envMap = new HashMap();
           buildEnvEntries(envMap, refs.getEnvEntry());
  +        buildEJBRefs(envMap, refs.getEJBRef());
   
           Map compMap = new HashMap();
           compMap.put("env", new ReadOnlyContext(envMap));
  @@ -85,7 +88,7 @@
       }
   
       private static void buildEnvEntries(Map envMap, EnvEntry[] envEntries) throws DeploymentException
{
  -        for (int i=0; i < envEntries.length; i++) {
  +        for (int i = 0; i < envEntries.length; i++) {
               EnvEntry entry = envEntries[i];
               String name = entry.getEnvEntryName();
               String type = entry.getEnvEntryType();
  @@ -113,13 +116,24 @@
                   } else if ("java.lang.Double".equals(type)) {
                       mapEntry = Double.valueOf(value);
                   } else {
  -                    throw new AssertionError("Invalid class for env-entry "+name+", "+type);
  +                    throw new AssertionError("Invalid class for env-entry " + name + ",
" + type);
                   }
               } catch (NumberFormatException e) {
  -                throw new DeploymentException("Invalid numeric value for env-entry "+name+",
value="+value);
  +                throw new DeploymentException("Invalid numeric value for env-entry " +
name + ", value=" + value);
               }
               if (envMap.put(name, mapEntry) != null) {
  -                throw new AssertionError("Duplicate entry for env-entry "+name);
  +                throw new AssertionError("Duplicate entry for env-entry " + name);
  +            }
  +        }
  +    }
  +
  +    private static void buildEJBRefs(Map envMap, EJBRef[] ejbRefs) {
  +        for (int i = 0; i < ejbRefs.length; i++) {
  +            EJBRef ejbRef = ejbRefs[i];
  +            String name = ejbRef.getEJBRefName();
  +            LinkRef ref = new LinkRef("jnp://localhost/TestEJB");
  +            if (envMap.put(name, ref) != null) {
  +                throw new AssertionError("Duplicate entry for env-entry " + name);
               }
           }
       }
  
  
  
  1.3       +5 -7      incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ComponentContextInterceptor.java
  
  Index: ComponentContextInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ComponentContextInterceptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ComponentContextInterceptor.java	26 Aug 2003 22:11:24 -0000	1.2
  +++ ComponentContextInterceptor.java	4 Sep 2003 05:16:17 -0000	1.3
  @@ -55,8 +55,6 @@
    */
   package org.apache.geronimo.naming.java;
   
  -import javax.naming.Context;
  -
   import org.apache.geronimo.common.AbstractInterceptor;
   import org.apache.geronimo.common.Invocation;
   import org.apache.geronimo.common.InvocationResult;
  @@ -64,22 +62,22 @@
   /**
    * An interceptor that pushes the current component's java:comp context into
    * the java: JNDI namespace
  - * 
  + *
    * @version $Revision$ $Date$
    */
   public class ComponentContextInterceptor extends AbstractInterceptor {
  -    private final Context compContext;
  +    private final ReadOnlyContext compContext;
   
       /**
        * Constructor specifying the components JNDI Context (java:comp)
        * @param compContext the component's JNDI Context
        */
  -    public ComponentContextInterceptor(Context compContext) {
  +    public ComponentContextInterceptor(ReadOnlyContext compContext) {
           this.compContext = compContext;
       }
   
       public InvocationResult invoke(Invocation invocation) throws Throwable {
  -        Context oldContext = RootContext.getComponentContext();
  +        ReadOnlyContext oldContext = RootContext.getComponentContext();
           try {
               RootContext.setComponentContext(compContext);
               return getNext().invoke(invocation);
  
  
  
  1.2       +2 -4      incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/javaURLContextFactory.java
  
  Index: javaURLContextFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/javaURLContextFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- javaURLContextFactory.java	20 Aug 2003 23:28:53 -0000	1.1
  +++ javaURLContextFactory.java	4 Sep 2003 05:16:17 -0000	1.2
  @@ -67,8 +67,6 @@
    * @version $Revision$ $Date$
    */
   public class javaURLContextFactory implements ObjectFactory {
  -    private static final Context ROOT_CONTEXT = new RootContext();
  -
       /**
        * Return a Context that is able to resolve names in the java: namespace.
        * The root context, "java:" is always returned. This is a specific
  @@ -82,7 +80,7 @@
        */
       public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment)
throws Exception {
           if (obj == null) {
  -            return ROOT_CONTEXT;
  +            return new RootContext(environment);
           } else {
               throw new OperationNotSupportedException();
           }
  
  
  
  1.4       +36 -25    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ReadOnlyContext.java	3 Sep 2003 17:21:16 -0000	1.3
  +++ ReadOnlyContext.java	4 Sep 2003 05:16:17 -0000	1.4
  @@ -55,6 +55,7 @@
    */
   package org.apache.geronimo.naming.java;
   
  +import java.util.Collections;
   import java.util.HashMap;
   import java.util.Hashtable;
   import java.util.Iterator;
  @@ -62,6 +63,7 @@
   import javax.naming.Binding;
   import javax.naming.CompositeName;
   import javax.naming.Context;
  +import javax.naming.LinkRef;
   import javax.naming.Name;
   import javax.naming.NameClassPair;
   import javax.naming.NameNotFoundException;
  @@ -70,7 +72,6 @@
   import javax.naming.NamingException;
   import javax.naming.NotContextException;
   import javax.naming.OperationNotSupportedException;
  -import javax.naming.LinkRef;
   import javax.naming.spi.NamingManager;
   
   /**
  @@ -94,12 +95,7 @@
    * @version $Revision$ $Date$
    */
   public class ReadOnlyContext implements Context {
  -    private static final Hashtable ENVIRONMENT = new Hashtable();
  -
  -    static {
  -        ENVIRONMENT.put(Context.URL_PKG_PREFIXES, "org.apache.geronimo.naming");
  -    }
  -
  +    private final Hashtable env;        // environment for this context
       private final Map bindings;         // bindings at my level
       private final Map treeBindings;     // all bindings under me
   
  @@ -108,6 +104,7 @@
        * @param bindings the bindings for this level; may include sub-contexts
        */
       public ReadOnlyContext(Map bindings) {
  +        this.env = new Hashtable();
           this.bindings = new HashMap(bindings);
           treeBindings = new HashMap(bindings);
           for (Iterator i = bindings.entrySet().iterator(); i.hasNext();) {
  @@ -115,15 +112,39 @@
               Object value = entry.getValue();
               if (value instanceof ReadOnlyContext) {
                   String key = (String) entry.getKey() + '/';
  -                Map subBindings = ((ReadOnlyContext)value).treeBindings;
  +                Map subBindings = ((ReadOnlyContext) value).treeBindings;
                   for (Iterator j = subBindings.entrySet().iterator(); j.hasNext();) {
                       Map.Entry subEntry = (Map.Entry) j.next();
  -                    treeBindings.put(key+subEntry.getKey(), subEntry.getValue());
  +                    treeBindings.put(key + subEntry.getKey(), subEntry.getValue());
                   }
               }
           }
       }
   
  +    ReadOnlyContext(Hashtable env) {
  +        this.env = new Hashtable(env);
  +        this.bindings = Collections.EMPTY_MAP;
  +        this.treeBindings = Collections.EMPTY_MAP;
  +    }
  +
  +    ReadOnlyContext(ReadOnlyContext clone, Hashtable env) {
  +        this.bindings = clone.bindings;
  +        this.treeBindings = clone.treeBindings;
  +        this.env = new Hashtable(env);
  +    }
  +
  +    public Object addToEnvironment(String propName, Object propVal) throws NamingException
{
  +        return env.put(propName, propVal);
  +    }
  +
  +    public Hashtable getEnvironment() throws NamingException {
  +        return (Hashtable) env.clone();
  +    }
  +
  +    public Object removeFromEnvironment(String propName) throws NamingException {
  +        return env.remove(propName);
  +    }
  +
       public Object lookup(String name) throws NamingException {
           if (name.length() == 0) {
               return this;
  @@ -133,7 +154,7 @@
               int pos = name.indexOf(':');
               if (pos > 0) {
                   String scheme = name.substring(0, pos);
  -                Context ctx = NamingManager.getURLContext(scheme, ENVIRONMENT);
  +                Context ctx = NamingManager.getURLContext(scheme, env);
                   if (ctx == null) {
                       throw new NamingException();
                   }
  @@ -143,8 +164,10 @@
           }
           if (result instanceof LinkRef) {
               LinkRef ref = (LinkRef) result;
  -            String link = (String) ref.get("LinkAddress").getContent();
  -            result = lookup(link);
  +            result = lookup(ref.getLinkName());
  +        }
  +        if (result instanceof ReadOnlyContext) {
  +            result = new ReadOnlyContext((ReadOnlyContext) result, env);
           }
           return result;
       }
  @@ -203,10 +226,6 @@
           return listBindings(name.toString());
       }
   
  -    public Object addToEnvironment(String propName, Object propVal) throws NamingException
{
  -        throw new OperationNotSupportedException();
  -    }
  -
       public void bind(Name name, Object obj) throws NamingException {
           throw new OperationNotSupportedException();
       }
  @@ -235,10 +254,6 @@
           throw new OperationNotSupportedException();
       }
   
  -    public Hashtable getEnvironment() throws NamingException {
  -        return ENVIRONMENT;
  -    }
  -
       public String getNameInNamespace() throws NamingException {
           throw new OperationNotSupportedException();
       }
  @@ -256,10 +271,6 @@
       }
   
       public void rebind(String name, Object obj) throws NamingException {
  -        throw new OperationNotSupportedException();
  -    }
  -
  -    public Object removeFromEnvironment(String propName) throws NamingException {
           throw new OperationNotSupportedException();
       }
   
  
  
  
  1.3       +9 -9      incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/RootContext.java
  
  Index: RootContext.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/RootContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RootContext.java	23 Aug 2003 22:13:15 -0000	1.2
  +++ RootContext.java	4 Sep 2003 05:16:17 -0000	1.3
  @@ -55,8 +55,7 @@
    */
   package org.apache.geronimo.naming.java;
   
  -import java.util.Collections;
  -import javax.naming.Context;
  +import java.util.Hashtable;
   import javax.naming.NameNotFoundException;
   import javax.naming.NamingException;
   
  @@ -70,8 +69,8 @@
   public class RootContext extends ReadOnlyContext {
       private static ThreadLocal compContext = new ThreadLocal();
   
  -    public RootContext() {
  -        super(Collections.EMPTY_MAP);
  +    RootContext(Hashtable env) {
  +        super(env);
       }
   
       public Object lookup(String name) throws NamingException {
  @@ -81,11 +80,12 @@
                   return this;
               }
   
  -            Context compCtx = (Context) compContext.get();
  +            ReadOnlyContext compCtx = (ReadOnlyContext) compContext.get();
               if (compCtx == null) {
                   // the component context was not set for this thread
                   throw new NameNotFoundException();
               }
  +            compCtx = new ReadOnlyContext(compCtx, getEnvironment());
   
               if ("comp".equals(name)) {
                   return compCtx;
  @@ -103,7 +103,7 @@
        * for all lookups of "java:comp"
        * @param ctx the current components context
        */
  -    public static void setComponentContext(Context ctx) {
  +    public static void setComponentContext(ReadOnlyContext ctx) {
           compContext.set(ctx);
       }
   
  @@ -111,7 +111,7 @@
        * Get the component context for the current thread.
        * @return the current components context
        */
  -    public static Context getComponentContext() {
  -        return (Context) compContext.get();
  +    public static ReadOnlyContext getComponentContext() {
  +        return (ReadOnlyContext) compContext.get();
       }
   }
  
  
  
  1.5       +10 -9     incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java/BasicContextTest.java
  
  Index: BasicContextTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java/BasicContextTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BasicContextTest.java	3 Sep 2003 17:21:16 -0000	1.4
  +++ BasicContextTest.java	4 Sep 2003 05:16:18 -0000	1.5
  @@ -60,6 +60,7 @@
   import java.util.Map;
   import java.util.Properties;
   import java.util.NoSuchElementException;
  +import java.util.Hashtable;
   
   import javax.naming.Binding;
   import javax.naming.CompositeName;
  @@ -77,7 +78,7 @@
   
   /**
   * Unit tests for basic ops on an {@link InitialContext}.
  - * 
  + *
    * @version $Revision$ $Date$
    */
   public class BasicContextTest extends TestCase {
  @@ -109,7 +110,7 @@
   
           assertEquals(envContext, envContext.lookup(""));
       }
  -    
  +
       public void testSchemeLookup() throws NamingException {
           envContext.lookup("dns:apache.org");
           assertEquals("Hello", envContext.lookup("java:comp/env/hello"));
  @@ -187,14 +188,14 @@
       public void testSpeed() throws NamingException {
           StopWatch watch = new StopWatch();
           Context comp = (Context) initialContext.lookup("java:comp");
  -        
  +
           watch.start();
           for (int i=0; i < 1000000; i++) {
               // initialContext.lookup("java:comp/hello"); // this is sloooow due to scheme
resolution
               // envContext.lookup("hello");
               comp.lookup("env/hello");
           }
  -        
  +
           System.out.println("lookup(String): " + watch.toDuration());
       }
   
  @@ -208,12 +209,12 @@
           envBinding.put("hello", "Hello");
           envBinding.put("world", "Hello World");
           envBinding.put("link", new LinkRef("java:comp/env/hello"));
  -        envContext = new ReadOnlyContext(envBinding);
  +        compBinding.put("env", new ReadOnlyContext(envBinding));
  +        RootContext.setComponentContext(new ReadOnlyContext(compBinding));
   
  -        compBinding.put("env", envContext);
  -        compContext = new ReadOnlyContext(compBinding);
  +        compContext = (Context) initialContext.lookup("java:comp");
  +        envContext = (Context) initialContext.lookup("java:comp/env");
   
           syntax = new Properties();
  -        RootContext.setComponentContext(compContext);
       }
   }
  
  
  
  1.2       +5 -3      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContextBuilderTest.java	3 Sep 2003 16:02:06 -0000	1.1
  +++ ContextBuilderTest.java	4 Sep 2003 05:16:18 -0000	1.2
  @@ -60,10 +60,11 @@
   import junit.framework.TestCase;
   import org.apache.geronimo.deployment.model.appclient.ApplicationClient;
   import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
  +import org.apache.geronimo.deployment.model.j2ee.EJBRef;
   
   /**
  - * 
  - * 
  + *
  + *
    * @version $Revision$ $Date$
    */
   public class ContextBuilderTest extends TestCase {
  @@ -80,6 +81,7 @@
           intEntry.setEnvEntryType("java.lang.Integer");
           intEntry.setEnvEntryValue("12345");
           client.setEnvEntry(new EnvEntry[] { stringEntry, intEntry });
  +        client.setEJBRef(new EJBRef[0]);
       }
   
       public void testEnvEntries() throws Exception {
  
  
  

Mime
View raw message