jakarta-bsf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitry Goldenberg" <dmitry.goldenb...@weblayers.com>
Subject RE: BSF integration sample code - ?
Date Mon, 01 May 2006 21:52:49 GMT
Thanks, Jaime.
 
Well, let's say I have a set of Java API's as follows:
 
public List<String> getItemNames(String arg1, String arg2);
public Item findItem(String arg1);
 
on my class MyEngine.  I imagine I'd need to do a declareBean on MyEngine.  But what do I
do inside my scripts to execute these two methods and process their results?  Say, in JavaScript
or Jython?
 
Thanks.
- Dmitry

________________________________

From: Jaime Garza [mailto:Jaime.Garza@newScale.com]
Sent: Mon 5/1/2006 5:48 PM
To: Bean Scripting Framework users
Subject: RE: BSF integration sample code - ?



The only thing I would add to Rony's answer is the capability to declare
"Beans" into your language, and the automatic loading of certain
"predefined" languages, so the call to load the scripting engine may not
be even needed.  To declare beans you create a java class with standard
getters and setters and other additional methods.  The getter/setter
combinations work like properties in your language, and your methods can
be called as functions.  I usually do javascript and BeanShell
integrations and I can use these properties as if they were variables,
and call the other methods in my declared beans as function calls, plus
these two languages would be preloaded if you drop the right jar in the
class path.  The biggest trick is finding the right jar to drop with
your integration, and it is usually a really simple google search.

The function to declare these beans is  BSFManager.declareBean and with
that you are set.  That is pretty much all the work needed for a very
basic integration.

- Jaime

-----Original Message-----
From: Rony G. Flatscher [mailto:Rony.Flatscher@wu-wien.ac.at]
Sent: Monday, May 01, 2006 2:36 PM
To: Bean Scripting Framework users
Subject: Re: BSF integration sample code - ?

Hi Dimitry,
> I am new to BSF. Can anyone point me at any BSF integration samples as
far as the usage of BSFManager/BSFEngine classes is concerned?
>  
Not sure, what you are looking for, here's a minimal Java program
employing BSF (to invoke a scripting language interpreter to execute the

supplied program).

------------- cut here -------------
import com.ibm.bsf.*;   // BSF support
import java.io.*;       // exception handling

public class TestSimpleExec {

  public static void main (String[] args) throws IOException
  {
    try {
      BSFManager mgr  = new BSFManager ();
      BSFEngine  rexx = mgr.loadScriptingEngine("rexx");
      String     rexxCode = "SAY 'Rexx was here!'";

      rexx.exec ("rexx", 0, 0, rexxCode);

    } catch (BSFException e) { e.printStackTrace(); }
  }
}
------------- cut here -------------


The above works with Rexx (if interested, get ooRexx from
<http://www.ooRexx.org>, and the BSF4Rexx-package containing the latest
build of the BSF-package including the Rexx-language at
<http://wi.wu-wien.ac.at/rgf/rexx/bsf4rexx/current/>: please read
carefully the readmeBSF.txt-file!).

Hope that helps,

---rony


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org





Mime
View raw message