>
> Revisiting this after a few weeks... :-)
>
> On Mar 31, 2004, at 11:48 PM, Jean-Christophe Kermagoret wrote:
>
> > Mark Lundquist wrote:
> >
> >> OK, so I would like to pass a parameter in to my Cocoon
> application
> >> via a context attribute (because I can set that in my Jetty
> >> configuration file). How do I access a context attribute
> from within
> >> one of my Java classes?
> >>
> >> Thx-a-lot,
> >> mark
> >>
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> > Hi Mark,
> > have you tried something like that ? It's a javascript code
> but java
> > code is almost the same.
> >
> > /**
> > * Example :
> > * getContextValue("authentication","/authentication/ID");
> > * getContextValue("authentication","/authentication/role");
> > * getContextValue("authentication","/authentication/data/user");
> > **/
> > function getContextValue(contextPath, path) {
> > var contextMan =
> > cocoon.getComponent(Packages.
> > org.apache.cocoon.webapps.session.ContextManager.ROLE);
> > var context = contextMan.getContext(contextPath);
> >
> > return context.getXML(path).getTextContent();
> > }
>
> That's all great, except that it all depends on the FOM. In
> plain old
> Java I don't have cocoon.getComponent().
>
> I know the answer should be simple: to be a client of ContextManager,
> just be an Avalon component that implements Serviceable, then you get
> your ServiceManager from service() and you can call
> lookup(org.apache.cocoon.webapps.session.ContextManager.ROLE) on it.
> But I'm having trouble figuring out how to get this solution to fit
> with what I've got...
>
> My domain objects are all written as plain old regular Java classes,
> with flowscript gluing them to the sitemap. To give a little
> context... the class that needs to be able to access a
> servlet context
> attribute is factory for Hibernate sessions, and the attribute is an
> "instance" name for the application that will be used to
> derive a JNDI
> path for the datasource, to be passed to the Hibernate
> configuration.
> The factory has static methods to get/create and close an associated
> resource (a ThreadLocal hibernate Sesssion).
>
> So, turning this factory into an Avalon component just pushes my
> problem back one level, because now how do the factory's
> clients access
> it? As POPOs they have no ServiceManager and are unable to
> look up the
> factory component, just as the factory component had been unable to
> look up ContextManager when it was POJ!
>
> BTW I have zero experience with Avalon components (or any other kind
> for that matter)... I suppose the right way to have done my project
> would have been to use components from the get-go, but that
> would have
> been just beyond the level of learning curve for me to
> tolerate at the
> time.
>
> So, how do I solve this problem? I could use a singleton,
> which seems
> way hacky... any ideas?
One solution that has been proposed on this list before is to create a
simple Avalon component that implements Serviceable. Then give this
component a static method called getServiceManager(). Now any POJO can get
a ServiceManager and use it to retrieve any other components it wants.
>
> thx,
> mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New
Jersey, USA 08889), and/or its affiliates (which may be known outside the
United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan as
Banyu) that may be confidential, proprietary copyrighted and/or legally
privileged. It is intended solely for the use of the individual or entity
named on this message. If you are not the intended recipient, and have
received this message in error, please notify us immediately by reply e-mail
and then delete it from your system.
------------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]