Ludovic,
Lookup documentation for the BSFManager.  Beanshell manager will allow you
to register objects that are passed to the scripting language (as long as
the language is using BSF).  For instance:

BSFManager mgr = new BSFManager();
mgr.declareBean(name, val, val.class);

This code will register an object val with a key name in the BSF object
registry.  If your dynamic language supports hash (i.e. "map.Key" or
"map[key]") such as your groovy example you should be able to access your
values at runtime.

Your issue may be with Jython.  Make sure that Jython supports Map (hash)
variable access.

vmatters.

On 4/14/07, Ludovic Drolez <[EMAIL PROTECTED]> wrote:

Hi !

I'm currently trying to add BSF+Jython support in the ZK framework
(www.zkoss.org). To make this I need to have a method called, each
time the scripting language tried to get the value of a variable.

For example the Groovy support in ZK is done this way:

=======================================
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
...
public void init(Page owner, String zslang) {
  super.init(owner, zslang);

  _global = new Binding(new Variables());
  _ip = new GroovyShell(_global);
}
//An inner class of GroovyInterpreter
private class Variables extends HashMap {
  public Object get(Object key) {
    Object val = super.get(key);
    if (val != null || containsKey(key) || !(key instanceof String))
      return val;
    return getFromNamespace((String)key); //provided by GenericInterpreter
  }
}
=======================================
(More can be read here:
http://www.zkoss.org/smalltalks/addinterpreter/addinterpreter.dsp)

So with groovy, you can register an 'object container' to intercept
accesses. If the object is already set in the scripting language, then
return it, but if it is not set, it tries to return a ZK object with the
same name (using the ZK method getFromNamespace()).

I do not see how it could be done with BSF. I cannot register new BSF
Beans,
because, new ZK objects can be created at any time, so I do not know their
names to register them. I need something dynamic, something which is
called
just before the scripting language tried to use an object.

Did I miss something in BSF, or do I need to use the Jython API instead ?

Best regards,

--
Ludovic Drolez.

http://zaurus.palmopensource.com    - The Zaurus Open Source Portal
http://www.drolez.com      - Personal site - Linux and PalmOS stuff

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to