You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by Wi...@schneider.com on 2003/01/08 23:01:11 UTC

NetRexx 2.x / BSF2.3 issue getting "current" BSFManager instance...

... from within the Rexx script.  The problem seems to be that
when I call into (BSFManager.exec() or BSFManager.eval(); they
seem to act the same in this respect) the script, the only way I
can figure to get a valid reference to a BSFManager is to instantiate
one within the script, which, of course, doesn't know beans about the
Java classes  I've painstakingly tried to expose to the script.

I have tried both declaring and registering a Java class from
within my app:
     // ... deletia

     bsfMan.declareBean("invoice", invoice, Invoice.class);
     // bsfMan.registerBean("invoice", invoice);
     // ... deletia

(The 2nd is theoretically redundant so I've commented it out, though
I seem to get identical results using either or both.)

I  have a Rexx script:
     import com.schneider.slps.rexxrules.Invoice
     import org.apache.bsf.BSFManager

     class rules
     method main(args=String[]) public static
           /* deletia...*/

     method CheckForDups public static
                      /* Important stuff omitted, see below */
           myInvoice = Invoice bsf.lookupBean("invoice")     /* !!!Not
working!!! */

           if (myInvoice == null) then
              return 'None'
                     /* Actual important stuff below deleted.... */


So, in order to get NetRexxC to resolve the bsf ref in the line commented
/* !!!Not Working!!! */ I have tried:

     bsf = BSFManager   /* According to the .java.keep file this creates an
                                                            instance of a
ref to a BSFManager and sets it to null */
                bsf = BSFManager() /* Instantiates a new one */

I can theoretically avoid this whole issue if I've called declareBean(),
and interestingly,
the symbol "invoice" does seem recognizable to the NetRexx compiler if I
remove all
declarations from the Rexx script, but as a TYPE, not an instance of class
"Invoice".
So, unless I can figure out some way for the Rexx script to just know that
"invoice" means
the one I registered w/ the BSFManager, I need to do a lookupBean().
Therefore, what I
seem to need is some third choice that lets me say "the BSFManager I'm
running in", and
I don't know what that looks like.   The really ugly workaround I'm using
depends on a static
instance var:

                      myInvoice = Invoice.currentInvoice;

but I'm sure that  this is not what the authors intended.  Being new to
both BSF & Rexx I'm
probably missing something really simple, so any pointers to good resources
for either
would be much appreciated, as would any insight into this problem.

 What I'm trying to do, BTW, is to develop a "poor man's rules engine"
callable from within
J2EE code.  The idea is that as much of the business logic as possible
could be separated
out into a higher-level, user-presentable language structure.  Rexx looked
like a good choice,
but given that NetRexx must first be translated into Java anyway, BSF might
not be a good fit for this.
(I could simply have users write Rexx, and use ANT to compile this into
Java classes which we
simply load along w/ the rest of our J2EE infrastructure).  Ultimately it'd
be nice to use a Java
implementation of the Rete algorithm (there seem to be several), or
implement our own
Observer / Observable pattern to make it act more like a real rules engine,
but the first iteration
would simply fire NetRexx "rules" at predetermined points in the regular
Java processing.
Any comments or insights would be welcome.

Keith
--------------------------------------------
W. Keith Wingate
Schneider Logistics
708-647-4346
WingateK@Schneider.com



Re: NetRexx 2.x / BSF2.3 issue getting "current" BSFManager instance...

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Keith:

>... from within the Rexx script.  The problem seems to be that
>when I call into (BSFManager.exec() or BSFManager.eval(); they
>seem to act the same in this respect) the script, the only way I
>can figure to get a valid reference to a BSFManager is to instantiate
>one within the script, which, of course, doesn't know beans about the
>Java classes  I've painstakingly tried to expose to the script.
>
Hmm, in the samples of the IBM forerunner of BSF there is a short 
example with NetRexx:

------------------------------------------- cut here 
--------------------------------------
/* pick up the center panel bean */
p = java.awt.Panel bsf.lookupBean("centerPanel");

/* set the layout manager to border */
p.setLayout(java.awt.BorderLayout());

/* add a few things */
p.add("Center", java.awt.Label("Middle from NetRexx"));
p.add("North", java.awt.TextField("north text from NetRexx"));
p.add("South", java.awt.TextField("south text from NetRexx"));
p.add("East", java.awt.Button("inner east from NetRexx"));
p.add("West", java.awt.Button("inner west from NetRexx"));

/* configure p a bit */
p.setBackground(java.awt.Color(255, 0, 0));

/* configure the frame that p is in */
f = java.awt.Frame p.getParent();
f.setTitle("Hello from NetRexx (title reset from NetRexx)");
------------------------------------------- cut here 
--------------------------------------

So the called NetRexx program seems to have the object "bsf" implicitly 
available to
it and able to use it for lookup purposes.

---

Here's a version of pure Rexx (runs e.g. with the free and open source 
Regina Rexx interpreter on any of its many platforms (cf. 
<http://regina-rexx.sourceforge.net>) using 'bsf4rexx' (this interface 
requires to denote the needed datatypes explicitly), a trailing comma 
indicates that the statement continues on the next line:

------------------------------------------- cut here 
--------------------------------------
/* to be put: "samples/scriptedui/ui.rex"    */
/* pick up the center panel bean, Rexx program modelled after ui.nrx */
p = bsf("lookupBean", "centerPanel")

/* set the layout manager to border */
call bsf "invoke", p, "setLayout", "obj", bsf("registerBean", "", 
"java.awt.BorderLayout")

/* add a few things */
call bsf "invoke", p, "add", "str", "Center", "obj",,  
         bsf("registerBean", "", "java.awt.Label", "str", "Middle from 
Rexx")
call bsf "invoke", p, "add", "str", "North", "obj",,
         bsf("registerBean", "", "java.awt.Label", "str", "North text 
from Rexx")
call bsf "invoke", p, "add", "str", "South", "obj",,
         bsf("registerBean", "", "java.awt.Label", "str", "South from Rexx")
call bsf "invoke", p, "add", "str", "East", "obj",,
         bsf("registerBean", "", "java.awt.Label", "str", "Inner east 
from Rexx")
call bsf "invoke", p, "add", "str", "West", "obj",,
         bsf("registerBean", "", "java.awt.Label", "str", "Inner west 
from Rexx")

/* configure p a bit */
call bsf "invoke", p, "setBackground", "obj", bsf("getStaticValue", 
"java.awt.Color", "yellow")

/* configure the frame that p is in */
f = bsf("invoke", p, "getParent")
call bsf "invoke", f, "setTitle", "str", "Hello from REXX (title reset 
from Rexx)"
------------------------------------------- cut here 
--------------------------------------



Here's a version of the object-oriented version of Rexx as produced by 
IBM (free for Linux
and included in OS/2 Warp resp. eComStation, trial packages for the 
Windows version)
(cf. <http://www.software.ibm.com/ad/obj-rexx/>), the message operator 
is the tilde (~):

------------------------------------------- cut here 
--------------------------------------
/* to be put: "samples/scriptedui/ui-oo.rex"    */
/* pick up the center panel bean, Object Rexx program modelled after 
ui.nrx */
p = .bsf~lookupBean("centerPanel")

/* set the layout manager to border */
p~setLayout("obj", .bsf~new("java.awt.BorderLayout"))

/* add a few things */
p~add("str", "Center", "obj", .bsf~new("java.awt.Label", "str", "Middle 
from Object Rexx"))
p~add("str", "North",  "obj", .bsf~new("java.awt.Label", "str", "North 
text from Object Rexx"))
p~add("str", "South",  "obj", .bsf~new("java.awt.Label", "str", "South 
text from Object Rexx"))
p~add("str", "East",   "obj", .bsf~new("java.awt.Label", "str", "Inner 
east text from Object Rexx"))
p~add("str", "West",   "obj", .bsf~new("java.awt.Label", "str", "Inner 
west text from Object Rexx"))

/* configure p a bit */
p~setBackground("obj", .bsf~getStaticValue("java.awt.Color", "green"))

/* configure the frame that p is in */
f=p~getParent
f~setTitle("str", "Hello from Object REXX (title reset from Object Rexx)")

::requires "BSF.cls"    -- get Object Rexx wrapper support for BSF
------------------------------------------- cut here 
--------------------------------------

More on Rexx can be found at: <http://www.RexxLA.org>.

---

I am in the process of enhancing and cleaning up "bsf4rexx" (cf. 
<http://wi.wu-wien.ac.at/rgf/rexx/orx12/JavaBeanScriptingWithRexx_orx12.pdf>) 
for the IBM version of BSF first (so it can be used wherever the IBM 
version is deployed) and will then port it to Apache, giving it the 
Apache license, such that that the Rexx support can be included into the 
Apache distribution together with the Regina interpreter.

Hope that helps a little,

---rony