cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <>
Subject Re: Introducing IOC for Java classes created in flowscript
Date Fri, 21 Nov 2003 17:47:53 GMT
Andreas Hartmann wrote:

> Sylvain Wallez wrote:
> [...]
>> Example:
>>  var foo = new Foo();
>>  cocoon.setupObject(foo);
>>  foo.doIt("blah");
> This looks quite interesting and definitely useful.
> But I've got a question:
> When I obtain a component in a flowscript, I have to release it before 
> sendPage(). So, if my foo object uses components, does it have to 
> release them before a sendPage() occurs in a script?

Sure, unless, of course, when you know that these components are ThreadSafe.

So the wisest way is IMO to lookup as late as possible and release as 
soon as possible. Ideally, both should be in the same method.

But there are cases when this is not possible (because of some state to 
keep), and then an explicit release method is needed.

> class Foo implements Serviceable {
>     public void service(ServiceManager manager) {
>         myComponent = (MyComponent)
>             manager.lookup(MyComponent.ROLE);
>     }
>     ...
> }
> cocoon.summonObject(;
> foo.doIt("blah");
> foo.releaseComponents();
> cocoon.sendPageAndWait(...);
> Is this correct?

Yes, but in that case, you'll have to be careful to no more use "foo" 
after sendPageAndWait().

And Avalon provides the Disposable interface just for this. The contract 
is that after dispose(), no other method will be called on a component. 
So this is where all cleanup is done.

Now what about adding a "disposeObject" on "cocoon" that would be the 
counterpart of "setupObject"? It would call it's dispose() method if it 
implements the Disposable interface.

We'll end up with 3 new methods on "cocoon":
- setupObject(object),
- createObject(classname) (or summon, new, instanciate)
- disposeObject(object).

What do you think?


Sylvain Wallez                                  Anyware Technologies 
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -

View raw message