Re: A newbie question related to using bsh

KUN LI <[email protected]> Wed, 5 Aug 2009 17:50:19 +0200
Newsgroups gmane.comp.java.beanshell.user
Message-ID <[email protected]>
 If you can know the type of every script or get his type by a method, use =
a HashMap, with a key who is his type.
HashMap<String, Object>   myScripts =3D new HashMap();

for(...){
 Object result =3D bsh.Interpreter().source(BshFileName);
 String type =3D getType(result);
 myScripts.put(type, result);
 }

now you could get each result with a key (his type).

Kun LI




> Date: Wed, 5 Aug 2009 15:40:52 +0000
> From: javadeveloper999-/[email protected]
> To: Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> Subject: Re: [Beanshell-users] A newbie question related to using bsh
> =

> =

> But how if those scripts would return variant types? For instance, there =
are 3 bsh scripts I want to collect. So in the Java application I might sca=
n the dir and use =

> =

> for(...){
> Object result =3D bsh.Interpreter().source(BshFileNames);
> }
> =

> So the result object would be different kind of type e.g. class A, class =
B and Class C. =

> =

> Is there any chance that I can cast them dynamically?
> =

> Thanks to reply my question.
> =

> --- On Wed, 5/8/09, KUN LI <[email protected]> wrote:
> =

> > From: KUN LI <[email protected]>
> > Subject: RE: [Beanshell-users] A newbie question related to using bsh
> > To: javadeveloper999-/[email protected], "beanshell - users" <beanshell-users@=
lists.sourceforge.net>
> > Date: Wednesday, 5 August, 2009, 3:34 PM
> > =

> > =

> > =

> > #yiv1311021128 .hmmessage P
> > {
> > margin:0px;padding:0px;}
> > #yiv1311021128 {
> > font-size:10pt;font-family:Verdana;}
> > =

> > =

> >  =

> > You can use "Collection" which can be a
> > "List" or "Vector".
> > =

> > Example:
> > =

> > Collection<A> results =3D new Arraylist();
> > =

> > results.add(result);
> > =

> > Kun LI
> > =

> > =

> > =

> > =

> > > Date: Wed, 5 Aug 2009 15:22:02 +0000
> > > From: javadeveloper999-/[email protected]
> > > To: Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> > > Subject: [Beanshell-users] A newbie question related
> > to using bsh
> > > =

> > > =

> > > I read the doc at
> > http://www.beanshell.org/examples/callscript.html. But this
> > arises me a question. How can I cast the result object into
> > the type I want? For instance, in the script I finally have
> > type A created, then in the Java application I obtained
> > using the following statement
> > > =

> > > Object result =3D new
> > bsh.Interpreter().source("myscript.bsh");
> > > =

> > > I can cast result to A if I only have one script e.g.
> > > =

> > > A a =3D (A) result;
> > > =

> > > However, how if I want to collect many scripts once
> > and then cast all object collected into type desired?
> > > =

> > > Is there any way I can achieve this?
> > > =

> > > Thanks for help.
> > > =

> > > =

> > > =

> > > =

> > >       =

> > > =

> > >
> > -----------------------------------------------------------------------=
-------
> > > Let Crystal Reports handle the reporting - Free
> > Crystal Reports 2008 30-Day =

> > > trial. Simplify your report design, integration and
> > deployment - and focus on =

> > > what you do best, core application coding. Discover
> > what's new with =

> > > Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> > > _______________________________________________
> > > Beanshell-users mailing list
> > > Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> > >
> > https://lists.sourceforge.net/lists/listinfo/beanshell-users
> > =

> > Discutez sur Messenger o=F9 que vous soyez ! Mettez
> > Messenger sur votre mobile ! =

> > =

> =

> =

>       =

> =

> -------------------------------------------------------------------------=
-----
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-D=
ay =

> trial. Simplify your report design, integration and deployment - and focu=
s on =

> what you do best, core application coding. Discover what's new with =

> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Beanshell-users mailing list
> Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/beanshell-users

_________________________________________________________________
D=E9couvrez toutes les possibilit=E9s de communication avec vos proches
http://www.microsoft.com/windows/windowslive/default.aspx
---------------------------------------------------------------------------=
---
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day =

trial. Simplify your report design, integration and deployment - and focus =
on =

what you do best, core application coding. Discover what's new with =

Crystal Reports now.  http://p.sf.net/sfu/bobj-july