Rony,

This is not quite what I want to do though.  From your example below, I 
need to identify all the places in the script that do a 
bsf.lookupBean(...) and get the value of the string being passed in. Given 
that this could be a variable, it may be very difficult, but I may be 
willing to restrict our usage such that the value would always be an 
inlined constant.  Also, I'd really like to know the type of the object 
being set on the lhs.   Any hopes for any of that?  Thanks.

David Wood 
Policy Technologies Group
IBM TJ Watson Research Center
daw...@us.ibm.com
914-784-5123 (office), 914-396-6515 (mobile)




From:
"Rony G. Flatscher (Apache)" <r...@apache.org>
To:
Bean Scripting Framework users <bsf-user@jakarta.apache.org>
Date:
02/10/2009 03:05 AM
Subject:
Re: Identifying required properities



Hi David,

David Wood wrote:
> I'm new to BSF, so be gentle...I'm wondering if, given an arbitrary 
> script, there is a way to determine the beans that need to be declared 
for 
> the script to execute without throwing 'undefined' exceptions.  For 
> example, 
>
>
> String s;
> System.out.printl(s);
>
>
> I'm assuming that 's' must be declared before the script will execute 
> properly, but how can I figure out whether it is 's' or some other 
symbol. 
> I'd also like to understand the type of the required symbol.  Thanks for 

> any help.
> 
In BSF 2.4 you would first register those Java objects with the
BSFRegistry using the BSFManager's declareBean() or registerBean() that
the script should have access to. Then in the script you would use
BSFLookup() to gain access to the Java object stored in the BSFRegistry.

Here's a starting point to study BSFManager's members online:
<
http://wi.wu-wien.ac.at/rgf/rexx/bsf4rexx/current/docs/docs.apache.bsf/org/apache/bsf/BSFManager.html
>.

Here's an example from the BSF samples in which "ScriptedUI.java"
creates an awt based user-interface, registers some (GUI) Java objects,
invokes a JavaScript script depending on the filetype (e.g. "ui.js" will
invoke JavaScript) which then runs and retrieves the registered object
and interacts with it. To use this you need to issue "java ScriptedUI
ui.js".

------------------- cut here (ScriptedUI.java) --------------------

/* This example shows how a Java app can allow a script to customize
   a UI */

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import org.apache.bsf.*;
import org.apache.bsf.util.*;

public class ScriptedUI {
  BSFManager mgr = new BSFManager ();

  public ScriptedUI (String fileName) {
    Frame f = new Frame ("Application's Main Frame");
    f.addWindowListener (new WindowAdapter () {
      public void windowClosing (WindowEvent e) {
                 System.exit (0);
      }
    });

    Panel p = new Panel ();
    f.add ("Center", p);
    f.add ("North", new Button ("North Button"));
    f.add ("South", new Button ("South Button"));

    mgr.registerBean ("centerPanel", p);
    mgr.registerBean ("parentFrame", f); // --rgf, 2006-08-08: to allow 
Jacl to get to frame ...

    // exec script engine code to do its thing for this
    try {
      String language = BSFManager.getLangFromFilename (fileName);
      FileReader in = new FileReader (fileName);
      String script = IOUtils.getStringFromReader (in);

      mgr.exec (language, fileName, -1, -1, script);
    } catch (BSFException e) {
      System.err.println ("Ouch: " + e.getMessage ());
      e.printStackTrace ();
    } catch (IOException e) {
      System.err.println ("Ouch: " + e.getMessage ());
      e.printStackTrace ();
    }

    // now pack and show the frame
    f.pack ();
    f.show ();
  }

  public static void main (String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println ("Usage: java ScriptedUI filename");
      System.err.println ("       where filename is the name of the 
script");
      System.exit (1);
    }
    new ScriptedUI (args[0]);
  }
}


------------------- cut here (ScriptedUI.java) --------------------


------------------- cut here (ui.js) --------------------

/* pick up the center panel bean */
p = bsf.lookupBean ("centerPanel");

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

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

/* configure p a bit */
p.setBackground (java.awt.Color.red);

/* configure the frame that p is in */
f = p.getParent ();
f.setTitle ("Hello from JavaScript (title reset from JavaScript)");


------------------- cut here (ui.js) --------------------

HTH,

---rony








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



Reply via email to