Question about custom namespace

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about custom namespace

Brian Deng
I am using the bsh Interpreter as a scripting engine within a web application.
We have an object model where the object attributes are accessible to the interpreted
bsh code. To accomplish this I've created a sub-class of NameSpace, overridden
various methods, and then pass my custom namespace to the Interpreter.eval() method.
One problem I've run across is that my custom namespace doesn't get called for symbols
that are within blocks of code unless they are prefixed by "this.". For example:

This works:

return myCustomAttribute + "_Test";

and this works:

if (someBooleanAttribute) {
   return this.myCustomAttribute + "_Test";
}

but this doesn't work:

if (someBooleanAttribute) {
   return myCustomAttribute + "_Test";
}

Is this a bug? Shouldn't the global namespace be called if the symbol is not found within
the block's namespace?

Another thing I'd like to do is use the parser to perform syntax checks from our development
environment, Currently I'm interpreting the code snippets using default values for the namespace,
but ideally I'd like to run it through the parser and check symbols against my namespace. This
doesn't seem possible at the moment because the classes the parser uses are all protected.
Is there a way around this?

Thanks,
  -B

bdeng.vcf (178 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Question about custom namespace

Brian Deng
I believe I've found the answer to my own question. There are a few different methods that
can be overridden. There are the public methods getVariable(String name, boolean recurse)
and getVariable(String name). Then there's the protected method
getVariableImpl(String name, boolean recurse). It seems that the BlockNameSpace code
only calls the getVariableImpl method. I've added an override for this method in my
subclass, but in order for things to work properly I've had to make one of the Variable
ctor's public so I can return a Variable instead of an Object.

This seems like a bug to me. Should I file one?

-B

Brian Deng wrote:

> I am using the bsh Interpreter as a scripting engine within a web
> application.
> We have an object model where the object attributes are accessible to
> the interpreted
> bsh code. To accomplish this I've created a sub-class of NameSpace,
> overridden
> various methods, and then pass my custom namespace to the
> Interpreter.eval() method.
> One problem I've run across is that my custom namespace doesn't get
> called for symbols
> that are within blocks of code unless they are prefixed by "this.". For
> example:
>
> This works:
>
> return myCustomAttribute + "_Test";
>
> and this works:
>
> if (someBooleanAttribute) {
>   return this.myCustomAttribute + "_Test";
> }
>
> but this doesn't work:
>
> if (someBooleanAttribute) {
>   return myCustomAttribute + "_Test";
> }
>
> Is this a bug? Shouldn't the global namespace be called if the symbol is
> not found within
> the block's namespace?
>
> Another thing I'd like to do is use the parser to perform syntax checks
> from our development
> environment, Currently I'm interpreting the code snippets using default
> values for the namespace,
> but ideally I'd like to run it through the parser and check symbols
> against my namespace. This
> doesn't seem possible at the moment because the classes the parser uses
> are all protected.
> Is there a way around this?
>
> Thanks,
>  -B

bdeng.vcf (178 bytes) Download Attachment