Re: Loading .java Files

"David Lee" <[email protected]> Sun, 26 Jun 2011 07:56:26 -0400
Newsgroups gmane.comp.java.beanshell.user
Message-ID <[email protected]>
Ok you are using "eval".  The terminology ".java" confused me.
You are loading  a "beanshell" file  not a "java" file.  Although they are
often similar.

If you want to invoke a non-static method in a class you do it the same way
in beanshell as you do in java.
you need to instantiate the class to invoke the method.
    
    new Foo().bar()

I dont think you can do this with BSHMethod.invoke()
(You can with eval)

My prefered method of executing bsh from within java is to use the Interface
methods.
 e.g.
     (ICampaignScript) mInterpreter.getInterface(ICampaignScript.class);

then you can call bsh methods directly via the interface.

but again this only calls 'top level' methods.   To create classes and call
them you need to run eval() or to expose a top level method which calls
them.
I dont know of any way directly from the java API to do it.










----------------------------------------
David A. Lee
[email protected]
http://www.xmlsh.org


-----Original Message-----
From: [email protected] [mailto:[email protected]] 
Sent: Sunday, June 26, 2011 7:41 AM
To: 'David Lee'
Subject: RE: [Beanshell-users] Loading .java Files


Hi David,

I use interpreter.eval(<content of .java file as string>).
I also tried interpreter.source(<path to java file>).

When it is in a class - how can i access its methods? I want to invoke them
via BshMethod#invoke(..).

Thank you

> By what mechanism are you "loading" a java file ?
> and yes the behavior is right.
> If a method is in a class then it's not in the global 
> namespace it's in a
> class.
> 
> 
> ----------------------------------------
> David A. Lee
> [email protected]
> http://www.xmlsh.org
> 
> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] 
> Sent: Sunday, June 26, 2011 6:50 AM
> To: beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> Subject: [Beanshell-users] Loading .java Files
> 
> Hi,
> 
> when I load a complete .java File, the global namespace has 
> no methods:
> 
> public class Foo() {
>   void bar() {
>     //
>   }
> }
> 
> When I load this, the namespace has the method bar():
> 
> //public class Foo() {
>   void bar() {
>     //
>   }
> //}
> 
> Is this a bug or by design?
> 
> Thank you
> 
> 
> --------------------------------------------------------------
> --------------
> --
> All of the data generated in your IT infrastructure is 
> seriously valuable.
> Why? It contains a definitive record of application 
> performance, security 
> threats, fraudulent activity, and more. Splunk takes this 
> data and makes 
> sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-d2d-c2
> _______________________________________________
> Beanshell-users mailing list
> Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
> 


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2