Re: How can I call Beanshell methods from Java?
Alexey Zinger <inline_four-/[email protected]> Wed, 15 Apr 2009 07:10:57 -0700 (PDT)
| Newsgroups | gmane.comp.java.beanshell.user |
|---|---|
| Message-ID | <[email protected]> |
You can. Just like in the example given, you'll need to set up an instance of Interpreter, call the source method to load your bsh file and then manipulate variables and invoke methods:
import bsh.Interpreter;
Interpreter i = new Interpreter(); // Construct an interpreter
i.source("somefile.bsh");
i.set("foo", 5); // Set variables
i.set("date", new Date() );
Object result = i.eval("doSomething(foo, date)"); // invoke doSomething
Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net
http://wcollage.sourceforge.net
--- On Wed, 4/15/09, Sid Kar <[email protected]> wrote:
> From: Sid Kar <[email protected]>
> Subject: Re: [Beanshell-users] How can I call Beanshell methods from Java?
> To: "David A. Lee" <[email protected]>
> Cc: beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> Date: Wednesday, April 15, 2009, 9:51 AM
> Thank you David,
>
> If I have for example 10 methods in my script file, after
> loading it, can I
> call a specific method?
>
> Sid
>
> On Wed, Apr 15, 2009 at 9:47 AM, David A. Lee
> <[email protected]> wrote:
>
> >
> >
> http://www.beanshell.org/manual/quickstart.html#Calling_BeanShell_From_Your_Application
> >
> >
> >
> >
> > How can I call a method scripted in Beanshell script
> (externally saved
> >> file
> >> loaded in Java using Interpreter)?
> >>
> >> I wish to define a PDF file structure (using
> iText) in a beanshell script,
> >> in different methods, such as PDF Title, Table
> Header, Table Rows, Trailer
> >> and so on, and then call them as needed from my
> Java bean. This will
> >> basically allow me to define my PDF file structure
> externally in the
> >> beanshell script, but will allow me to plugin the
> data from my Java bean
> >> (more secure).
> >>
> >> Thank you
> >> Sid
> >>
> >>
> ------------------------------------------------------------------------------
> >> This SF.net email is sponsored by:
> >> High Quality Requirements in a Collaborative
> Environment.
> >> Download a free trial of Rational Requirements
> Composer Now!
> >> http://p.sf.net/sfu/www-ibm-com
> >> _______________________________________________
> >> Beanshell-users mailing list
> >> Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> >>
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
> >>
> >>
> >
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer
> Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> Beanshell-users mailing list
> Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com