Mhall wrote:
>>> Is there any way for a program to find out what are the beans created
>>> by the scripts and then retrieve them one by one (without hardcode the
>>> names)?
>>>       
>> Not at the moment. However, it would be questionable whether that was a
>> desirable feature at all, which may be surprising at first. Reasoning:
>> invoked scripts should only be able to address Java objects that were
>> made explicitly known to them by the controlling/invoking Java program.
>>     
>
> I think he's asking for the opposite actually, for the controlling/invoking 
> Java program to have access to objects created by the script.  I'm nearly 
> certain that BSF hands off to the script engine, and doesn't automatically 
> register everything the script engine does.  
>   
Oh, I see!
> That being said, BSF does add itself to the script's context, so I think you 
> can do something like $bsf.declareBean("myrubyvariable", $rubyvariable) from 
> within the ruby script, then fetch it using 
> BSFManager.lookupBean("myrubyvariable") from the Java code.
>   
Yes, that would be one thing to do. Other options would be to use a
pre-registered Map to use for scripts to exchange data with the Java
host. Also, it would be possible to return a Java String with delimited
index values used for registering with the BSF registry, which the Java
program could use to learn about them and being able to retrieve them
from the BSF registry. Another possibility would be to directly return a
Java object like a Map containing the data created/edited by the script,
meant for the Java host. There are quite a few possibilities to achieve
that...

> It would be nice if there was a BSFEvent or something when a script created a 
> new object/variable in it's context, I know I want something like that for my 
> application, but I don't think BSF is that aware enough of what the script 
> engine itself is doing to accomplish that.
>   
Yes, that would be something the script engine creator could  (should?)
provide.

Regards,

---rony

Reply via email to