cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Upayavira>
Subject Re: Scriptable objects with BeanShell
Date Mon, 24 Nov 2003 20:05:17 GMT
Bertrand Delacretaz wrote:

> 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] 
> Interpreter.html#getInterface(java.lang.Class)
> [2] 
> bshmanual.html#%22Dummy%22_Adapters_and_Incomplete_Interfaces
> [3]
 From looking at the BeanShell docs, the Java is definitely 'scripted' 
java, and lacks Java's object orientedness. Therefore, whilst you're 
coding in more or less Java, I can't see a great advantage of using 
BeanShell over using Rhino. They're both scripted, and thus not able to 
create clear interfaces. (In BeanShell you can implement interfaces, but 
to do so you have to use 'anonymous classes', which IMO doesn't produce 
attractive or easy to read code.

Therefore, I think, for my case, I'm just going to have to use Java for 
my objects, to use Unit Tests to test them (rather than bothering to 
test them in a servlet environment), and hope for the day when someone 
gets Christopher's CompilingClassLoader working so that I can easily 
debug Java code from within a servlet.

Regards, Upayavira

View raw message