cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <sylv...@apache.org>
Subject Introducing IOC for Java classes created in flowscript
Date Thu, 20 Nov 2003 15:29:58 GMT
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



Mime
View raw message