I have a project that does similar things as what you are looking for. However, my objects implements an interface that has a public Object get(Object key). Therefore, I can intersect the get() call in objects that implements that interface.
BSF really has no need to have such mechanism since BSF itself does not parse, execute, or evaluate scripts. When objects are registered with BSF, they are just passed to the script engine that is using BSF. My experience with BeanShell, JXEL, Groovy, and others is that they all have a mechanism (as you are looking for) where they use a HashMap to store values that are evaluated using associative array notations (i.e. hash.keyor hash[key]). vmatters On 4/15/07, Ludovic Drolez <[EMAIL PROTECTED]> wrote:
Vladimir Vivien wrote: > Ludovic, > Lookup documentation for the BSFManager. Beanshell manager will allow you > to register objects that are passed to the scripting language (as long as Vladimir, As I said before, I cannot use declareBean, because java objects are created dynamically. In the Groovy example below, there is a mecanism to intercept the get() method of the scripting language objects. But I cannot find one in BSF (e.g. instead of throwing a "name error" in jython, my custom get() method should be called to try to return an object external to the interpreter). Any ideas ? Ludovic. > 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] >> >> > -- 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]