You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Leo Sutic <le...@inspireinfrastructure.com> on 2001/09/06 19:22:18 UTC

excalibur.naming

All,

I am trying to use the excalibur.naming package, but I am having severe
problems with the in-memory naming system.

    DefaultConfiguration config = new DefaultConfiguration("roles", "");
    DefaultConfiguration timeComponent = new DefaultConfiguration("role",
"roles");
    timeComponent.addAttribute("role", Time.ROLE);
    timeComponent.addAttribute("class", TimeComponent.class.getName());
    config.addChild(timeComponent);

    Hashtable environment = new Hashtable();
    environment.put(Context.INITIAL_CONTEXT_FACTORY,
    			  MemoryInitialContextFactory.class.getName());

    Context initialContext = new InitialContext(environment);
    Context ctx = initialContext.createSubcontext("org");
    ctx = ctx.createSubcontext("apache");
    ctx = ctx.createSubcontext("cocoon");
    ctx = ctx.createSubcontext("samples");
    ctx = ctx.createSubcontext("parentcm");
    ctx.rebind("ParentCMConfiguration", config);

    initialContext = new InitialContext(environment);

initialContext.lookup("org/apache/cocoon/samples/parentcm/ParentCMConfigurat
ion");

The last line results in a name not bound exception: org.

I looked at the code, and the statement new InitialContext(environment)
really does create two different namespaces. The contexts obtained via the
MemoryInitialContextFactory are thus not persistent - they are more like a
hierarchical HashMap.

So, how does one use this package? I need to store one object from one class
and pick it up in another, without passing the InitialContext across.

/LS


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: excalibur.naming

Posted by Peter Donald <do...@apache.org>.
On Fri, 7 Sep 2001 03:22, Leo Sutic wrote:
> All,
>
> I am trying to use the excalibur.naming package, but I am having severe
> problems with the in-memory naming system.
>
>     DefaultConfiguration config = new DefaultConfiguration("roles", "");
>     DefaultConfiguration timeComponent = new DefaultConfiguration("role",
> "roles");
>     timeComponent.addAttribute("role", Time.ROLE);
>     timeComponent.addAttribute("class", TimeComponent.class.getName());
>     config.addChild(timeComponent);
>
>     Hashtable environment = new Hashtable();
>     environment.put(Context.INITIAL_CONTEXT_FACTORY,
>     			  MemoryInitialContextFactory.class.getName());
>
>     Context initialContext = new InitialContext(environment);
>     Context ctx = initialContext.createSubcontext("org");
>     ctx = ctx.createSubcontext("apache");
>     ctx = ctx.createSubcontext("cocoon");
>     ctx = ctx.createSubcontext("samples");
>     ctx = ctx.createSubcontext("parentcm");
>     ctx.rebind("ParentCMConfiguration", config);
>
>     initialContext = new InitialContext(environment);
>
> initialContext.lookup("org/apache/cocoon/samples/parentcm/ParentCMConfigura
>t ion");
>
> The last line results in a name not bound exception: org.
>
> I looked at the code, and the statement new InitialContext(environment)
> really does create two different namespaces. The contexts obtained via the
> MemoryInitialContextFactory are thus not persistent - they are more like a
> hierarchical HashMap.

yep ;)

> So, how does one use this package? 

exactly like a hierarchial HashMap if you use MemoryContext ;) RMIContext 
allows remote contexts however that requires sophisticated mechanisms to get 
references to each object which you probably don't want to do.

> I need to store one object from one
> class and pick it up in another, without passing the InitialContext across.

In that case it is probably best to create a customized version of 
MemoryInitialContextFactory that stores it in a static (or inheritable 
thread-local) variable.

-- 
Cheers,

Pete

-------------------------------------------------------
To fight and conquer in all your battles is not supreme 
excellence; supreme excellence consists in breaking the 
enemy's resistance without fighting. - Sun Tzu, 300 B.C.
-------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org