cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bertrand Delacretaz <>
Subject Scriptable objects with BeanShell (was: Introducing IOC for Java classes created in flowscript)
Date Sat, 22 Nov 2003 12:33:02 GMT

Le Vendredi, 21 nov 2003, à 22:20 Europe/Zurich, Upayavira a écrit :

> Bertrand Delacretaz wrote:
>> ...This means that BeanShell (dunno if BSF does this too) scripts  
>> could be called from flow *and* interpreted *and* implement Avalon or  
>> Cocoon interfaces. I haven't thought about all implications but it  
>> might be a nice intermediate solution between limited interpreted  
>> stuff and full-blown java coding.
> Can you say more about how you do this? Give some examples? I would  
> find that very useful.

Still in wildthoughts mode here, I haven't tested this:

1) A BeanShellWrapper Component initializes BeanShell and provides some  
useful beans that scripts can access (similar to what the current  
ScriptGenerator does).

Maybe BSF instead of BeanShell (as BSF can use BeanShell as a script  
engine anyway), but I don't know if BSF does all this.

2) BeanShellWrapper provides methods for flowscripts to retrieve  
scriptable objects, something like:

   IMyBizObject =  

At this point the BeanShell "dynamic adapter" feature [1] [2] is used  
to provide an object of the specified interface, something like:

   // in BeanShellWrapper:
   public Object createObject(Class clazz,String scriptFilename) {
      // first load scriptFilename in the (or a new) BeanShell  
     // then cast the interpreter as required, it will call the  
appropriate methods in
     // the script if they exist and complain if not
     return interpreter.getInterface(clazz);

See what I mean? This is only a rough sketch, there are certainly a lot  
of "details" to consider. But it looks like all the essential elements  
are here.

I'm also not sure if one of the BeanShell licenses [3] are ok for  
distributing with Cocoon, but mocks could be used if it is not the case.

Hope this helps,




View raw message