Ok I've moved this over to the developers list. What you
describe is what I'd like to do. It appears to me that
Interpreter.eval() returns a proxy from java.lang.reflect
which is what I'm trying to serialize. I'd be happy to do
the work if you or anyone can give me some pointers
in roughly the right direction.
----- Original Message -----
From: "Pat" <pat@...>
To: "Rick Kitts" <rkitts@...>;
Sent: Thursday, February 28, 2002 3:01 PM
Subject: Re: [Beanshell-users] Serializing from Java?
> On Thu, Feb 28, 2002 at 02:36:21PM -0800, Rick Kitts wrote:
> > Hello. I'm hoping someone here can help me.
> > I'm trying to serialize an bsh interpreted object
> > and, while that seems to go fine, deserializing and
> > then using the object is problematic. Basically
> > here's what I'm doing:
> > Object o = new Interprerter.eval(reader); // Eval the script and get the
> > object
> > o.serialize(); // This is shorthand for open an
> > etc...
> > o = deserialize(); // Shorthand also
> > o.bshMethod(); // Try to get the shell to execute something
> > This last line of course throws an NPE since the interpreter is not
> > bound. What I'm wondering is if there is a way to bind the object
> > from Java as opposed to having to call into a different script and
> > call bind() there.
> First, I have tested the basic ability to serialize bsh objects from
> As you may have seen, from within a bsh script you could do:
> save( this, "file.ser");
> obj = load("file.ser");
> The load() and save() commands simply do what your shorthand above does,
> except that the load adds a check to see if the object is a bsh object
> and binds it back to the interpreter:
> // bind bsh objects into the caller's namespace
> if ( obj instanceof bsh.This )
> bind( obj, this.caller.namespace );
> The meaning of the "binding" is to connect the bsh object back to the
> namespace... It's detached upon serialization so that when you seriaize a
> object it doesn't drag the whole interpreter with it...
> Now, I think what you want to do is to serialize the whole interpreter
> outside... from Java.
> I haven't tested that... but I think I see the problem. The interpreter
> needs to rebind the objects when it is deserialized and it doesn't do
> I'll make a note that that needs to be fixed.
> If you want to talk more about it we might want to move the discussion
> to the developer list.