You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stefan Klein <kl...@web.de> on 2004/01/04 11:16:42 UTC

Re: App level variable in flow

Upayavira,
 
> How do I store a java object in some application context or an 
> application level variable, just once during servlet container startup,
> 
> when I'm writing an app that uses flow?

Could you not write it as I component, include it in cocoon.roles so that
it'll be loaded automatically at startup and access it in flow via
cocoon.getComponent()?

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: App level variable in flow

Posted by Upayavira <uv...@upaya.co.uk>.
Stefan Klein wrote:

>Upayavira,
> 
>  
>
>>How do I store a java object in some application context or an 
>>application level variable, just once during servlet container startup,
>>
>>when I'm writing an app that uses flow?
>>    
>>
>
>Could you not write it as I component, include it in cocoon.roles so that
>it'll be loaded automatically at startup and access it in flow via
>cocoon.getComponent()?
>  
>
Yes, but flow is supposed to be lightweight, and doing that is a lot of 
work to do, and I'd like to avoid, if poss, any changes to the Cocoon 
webapp (otherwise, installing on new machines is hassle).

Jeremy suggested (on the dev list)  instantiating the object in the 
opening lines (outside methods) in flowscript:

if (cocoon.context.myObject == null) {
  cocoon.context.myObject = new Packages.mypackage.MyObject();
}

Then, the first time a flow is accessed after servlet startup, my object 
is created. From then on, it is available in memory.

That should be good enough for me, and it is only 2 1/2 lines of code, 
which is the kind of thing I had in mind!!

Reinhard also suggested using Context listeners that can be configured 
using web.xml, although I haven't looked into that approach.

Regards, Upayavira



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org