On Tuesday, December 9, 2003, at 10:40 AM, David Blevins wrote:
On Mon, Dec 08, 2003 at 09:43:39PM -0800, David Jencks wrote:I'm sorry, I don't understand all about jndi.
Could you give an example of what this is for, and how it differs from binding into the read only context refs whose targets are in say the jmx context?
The ReadOnlyContext is used by the OpenEJB nova containers, so there is no jmx anything going on.
At least when deployed in geronimo, ejb-refs, ejb-links, and resource-refs are done by binding a reference into the jmx jndi context. A name in this context essentially is an object name + operation name, and the the lookup is done by returning the result of the operation.
The situation is that I need to add another Context implementation, one built by OpenEJB, into the ReadOnlyContext of an EJBContainer.
Doing this by instantiating the ReadOnlyContext with a Map, where one of the values is the non-ReadOnlyContext context object. Lookups to the respective name need to be delegated to that context object.
Would you get the same effect by listing the OpenEJB context and binding everything you found into the ReadOnly context?
Does this have the effect of making the ReadOnlyContext mutable, in that you can look up whatever happens to be currently bound in the subcontext?
It could if the Context added allowed bind operations, but in this case it doesn't. The neat thing is that the "outside" context is only checked if the lookup failed against the ReadOnlyContext, so everything in the ReadOnlyContext essentially trumps the outside context. This is useful for the UserTransaction object.
So, is a typical name you might look up something like java:/comp/env/geronimo/read/only/openejb/context/actualobject
where the "context shift" occurs between 'only' and 'openejb'?
And... If I write some kind of mutable context, that say looked up connection factories in jmx based on knowing most of their object name and the operation to use, I could bind this into the ReadOnlyContext?
many thanks david jencks
-David Blevins
Thanks david jencks
On Monday, December 8, 2003, at 09:03 PM, [EMAIL PROTECTED] wrote:
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;
