geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java ReadOnlyContext.java
Date Tue, 09 Dec 2003 05:03:49 GMT
dblevins    2003/12/08 21:03:49

  Modified:    modules/core/src/java/org/apache/geronimo/naming/java
                        ReadOnlyContext.java
  Log:
  Added support to do lookups from other Context implementations.  In other words,
  sub-contexts under the context which aren't ReadOnlyContext implementations.
  
  Revision  Changes    Path
  1.7       +23 -3     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ReadOnlyContext.java	16 Nov 2003 05:24:38 -0000	1.6
  +++ ReadOnlyContext.java	9 Dec 2003 05:03:49 -0000	1.7
  @@ -87,7 +87,7 @@
    * resolution phase performed by the JVM takes considerably longer, so for
    * optimum performance lookups should be coded like:</p>
    * <code>
  - *   Context componentContext = new InitialContext().lookup("java:comp");
  + *   Context componentContext = (Context)new InitialContext().lookup("java:comp");
    *   String envEntry = (String) componentContext.lookup("env/myEntry");
    *   String envEntry2 = (String) componentContext.lookup("env/myEntry2");
    * </code>
  @@ -122,7 +122,11 @@
       }
   
       ReadOnlyContext(Hashtable env) {
  +        if (env == null) {
  +            this.env = new Hashtable();
  +        } else {
           this.env = new Hashtable(env);
  +        }
           this.bindings = Collections.EMPTY_MAP;
           this.treeBindings = Collections.EMPTY_MAP;
       }
  @@ -159,8 +163,24 @@
                       throw new NamingException("scheme " + scheme + " not recognized");
                   }
                   return ctx.lookup(name);
  +            } else {
  +                // Split out the first name of the path
  +                // and look for it in the bindings map.
  +                CompositeName path = new CompositeName(name);
  +
  +                if (path.size() == 0) {
  +                    return this;
  +                } else {
  +                    Object obj = bindings.get(path.get(0));
  +                    if (obj == null){
  +                        throw new NameNotFoundException(name);
  +                    } else if (obj instanceof Context && path.size() > 1){
  +                        Context subContext = (Context) obj;
  +                        obj = subContext.lookup(path.getSuffix(1));
  +                    }
  +                    return obj;
  +                }
               }
  -            throw new NameNotFoundException(name);
           }
           if (result instanceof LinkRef) {
               LinkRef ref = (LinkRef) result;
  
  
  

Mime
View raw message