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 = (IMyBizObject)BSFWrapper.createObject(IMyBizObject.class,"MyBusinessScri pt.bsl");

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 Interpreter
...
// 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,
-Bertrand


[1] http://www.beanshell.org/javadoc/bsh/ Interpreter.html#getInterface(java.lang.Class)


[2] http://www.beanshell.org/manual/ bshmanual.html#%22Dummy%22_Adapters_and_Incomplete_Interfaces

[3] http://www.beanshell.org/license.html

Reply via email to