Rickard �berg wrote:
> This means that all you have to do to use java:comp/ is to, well, start
> using it. The first thing you'd want to do during initialization of it,
> for example, is to create the "env" subcontext, like this:
> Context ctx = (Context)new InitialContext().lookup("java:comp");
> ctx.createSubcontext("env");

One further example. Let's say you have two components with two
different classloaders wanting two different namespaces:
Thread.setContextClassLoader(loader1);
Context ctx = (Context)new InitialContext().lookup("java:comp");
ctx.createSubcontext("env");
ctx.bind("foo","bar"); // Bind java:comp/env/foo to bar in component 1's
namespace

Thread.setContextClassLoader(loader2);
Context ctx = (Context)new InitialContext().lookup("java:comp");
ctx.createSubcontext("env"); // No env currently in loader2's namespace,
so create it
ctx.bind("foo","xyzzy"); // Bind java:comp/env/foo to xyzzy in component
2's namespace

Thread.setContextClassLoader(loader1);
new InitialContext().lookup("java:comp/env/foo"); // Result is "bar"
Thread.setContextClassLoader(loader2);
new InitialContext().lookup("java:comp/env/foo"); // Result is "xyzzy"

Do you see? Pretty easy to use IMO...

/Rickard

-- 
Rickard �berg

Email: [EMAIL PROTECTED]
http://www.telkel.com
http://www.jboss.org
http://www.dreambean.com


Reply via email to