Re: Dynamic variable binding in Bean Shell
Pat <[email protected]>
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <[email protected]> |
On Fri, May 21, 2004 at 09:12:54AM +0200, Franco Graziosi wrote:
>
> Supposing, for example I have the following interface:
>
> interface ScriptValueProvider {
> /**
> * Returns the allowed value or Primitive.VOID
> */
> Object getValueForName(String varName);
> }
>
> I would like the script invoke such provider whenever it cannot find a value,
> before throwing an error.
>
> My first question is is this possible?
It should be easy to do, though I'm not 100% sure it can be done without
a small modification to the source... You mention that you tried modifying
NameSpace. It seems that overriding getVariableImpl() or perhaps
getImportedVar() (a logical place to put it) would be all that is necessary.
Now, if you don't want to maintain a modified version of BeanShell then I think
you can just subclass bsh.NameSpace, add your code and then call the BeanShell
command setNameSpace() in your script (or before calling your user's script)
to get your namespace used.
This functionality would be trivial to provide and we should probably add a
general interface like this or some other mechanism to an upcoming release of
BeanShell. We currently have the invoke() meta-method that allows scripts to
dynamically handle method names used in the namespace, so there should be some
way to dynamically handle variables... Perhaps just allowing a scripted
getVariable(name) to override the built in functionality in a namespace.
Pat
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click