Hi all,

Flowscript currently gives two means to use Java classes: use components (cocoon.getComponent()) or simply create a Java object and use it (new MyClass()). As it's not very convenient to create a new component and install it in cocoon.xconf just to call Java code from the flow, the second solution is often used.

But a problem comes when these Java objects need to access e.g. request parameters, session attributes, components, etc: the only way is to pass them the "cocoon" object that provides this access.

But "cocoon" is of class "FOM_Cocoon" which is very specific to the internals of flowscript and linking code to this specific class isn't IMO a good thing to do. Furthermore, accessing elements of the object model through getters isn't consistent with the way it's usually done in other Cocoon code and violates IOC.

So I added a new method to "cocoon" that sets up an object just as if it were an Avalon component by honoring the various lifecycle interfaces.

Some useful lifecycle interfaces to implement are of course LogEnabled and Serviceable, but also Contextualizable, which gives access to the object model through the ContextHelper class.

Example:
 var foo = new Foo();
 cocoon.setupObject(foo);
 foo.doIt("blah");

This way of setting up object respects IOC, avoids using the very specific "FOM_Cocoon" class and gently educates people to the good things provided by Avalon.

WDYT?

Sylvain

--
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com




Reply via email to