20080913, rgf

org.apache.bsf.util
Class EngineUtils

java.lang.Object
  extended byorg.apache.bsf.util.EngineUtils

public class EngineUtils
extends java.lang.Object

This class contains utilities that language integrators can use when implementing the BSFEngine interface.

Author:
Sanjiva Weerawarana, Sam Ruby, Rony G. Flatscher (added addEventListenerReturningEventInfos)

Field Summary
(package private) static boolean bMethodHasSetAccessible
           
(package private) static BSFClassLoader bsfCL
           
(package private) static java.lang.ClassLoader bsfManagerDefinedCL
           
 
Constructor Summary
EngineUtils()
           
 
Method Summary
static void addEventListener(java.lang.Object bean, java.lang.String eventSetName, java.lang.String filter, BSFEngine engine, BSFManager manager, java.lang.String source, int lineNo, int columnNo, java.lang.Object script)
          Add a script as a listener to some event coming out of an object.
static void addEventListenerReturningEventInfos(java.lang.Object bean, java.lang.String eventSetName, java.lang.String filter, BSFEngine engine, BSFManager manager, java.lang.String source, int lineNo, int columnNo, java.lang.Object script, java.lang.Object dataFromScriptingEngine)
          Add a script as a listener to some event coming out of an object.
static java.lang.Object callBeanMethod(java.lang.Object bean, java.lang.String methodName, java.lang.Object[] args)
          Finds and invokes a method with the given signature on the given bean.
static java.lang.Object createBean(java.lang.String className, java.lang.Object[] args)
          Creates a new bean.
static java.lang.String getTypeSignatureString(java.lang.Class cl)
          Given a class return the type signature string fragment for it.
static java.lang.Class loadClass(BSFManager mgr, java.lang.String name)
          Loads a class using the following sequence of class loaders: Thread's context class loader, settable class loader stored with BSFManager, BSFManager's defining class loader, BSF customized class loader (from the BSFManager's temporary directory).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bsfCL

static BSFClassLoader bsfCL

bsfManagerDefinedCL

static java.lang.ClassLoader bsfManagerDefinedCL

bMethodHasSetAccessible

static boolean bMethodHasSetAccessible
Constructor Detail

EngineUtils

public EngineUtils()
Method Detail

addEventListener

public static void addEventListener(java.lang.Object bean,
                                    java.lang.String eventSetName,
                                    java.lang.String filter,
                                    BSFEngine engine,
                                    BSFManager manager,
                                    java.lang.String source,
                                    int lineNo,
                                    int columnNo,
                                    java.lang.Object script)
                             throws BSFException
Add a script as a listener to some event coming out of an object. The first two args identify the src of the event and the event set and the rest identify the script which should be run when the event fires.

Parameters:
bean - event source
eventSetName - name of event set from event src to bind to
filter - filter for events
engine - BSFEngine which can run this script
manager - BSFManager of the above engine
source - (context info) the source of this expression (e.g., filename)
lineNo - (context info) the line number in source for expr
columnNo - (context info) the column number in source for expr
script - the script to execute when the event occurs
Throws:
BSFException - if anything goes wrong while running the script

addEventListenerReturningEventInfos

public static void addEventListenerReturningEventInfos(java.lang.Object bean,
                                                       java.lang.String eventSetName,
                                                       java.lang.String filter,
                                                       BSFEngine engine,
                                                       BSFManager manager,
                                                       java.lang.String source,
                                                       int lineNo,
                                                       int columnNo,
                                                       java.lang.Object script,
                                                       java.lang.Object dataFromScriptingEngine)
                                                throws BSFException
Add a script as a listener to some event coming out of an object. The first two args identify the src of the event and the event set and the rest identify the script which should be run when the event fires. The processing will use the engine's apply() method.

Parameters:
bean - event source
eventSetName - name of event set from event src to bind to
filter - filter for events
engine - BSFEngine which can run this script
manager - BSFManager of the above engine
source - (context info) the source of this expression (e.g., filename)
lineNo - (context info) the line number in source for expr
columnNo - (context info) the column number in source for expr
script - the script to execute when the event occurs
dataFromScriptingEngine - this contains any object supplied by the scripting engine and gets sent back with the supplied script, if the event occurs. This could be used e.g. for indicating to the scripting engine which scripting engine object/routine/function/procedure should be ultimately informed of the event occurrence.
Throws:
BSFException - if anything goes wrong while running the script

callBeanMethod

public static java.lang.Object callBeanMethod(java.lang.Object bean,
                                              java.lang.String methodName,
                                              java.lang.Object[] args)
                                       throws BSFException
Finds and invokes a method with the given signature on the given bean. The signature of the method that's invoked is first taken as the types of the args, but if that fails, this tries to convert any primitive wrapper type args to their primitive counterparts to see whether a method exists that way. If it does, done.

Parameters:
bean - the object on which to invoke the method
methodName - name of the method
args - arguments to be given to the method
Returns:
the result of invoking the method, if any
Throws:
BSFException - if something goes wrong

createBean

public static java.lang.Object createBean(java.lang.String className,
                                          java.lang.Object[] args)
                                   throws BSFException
Creates a new bean. The signature of the constructor that's invoked is first taken as the types of the args, but if that fails, this tries to convert any primitive wrapper type args to their primitive counterparts to see whether a method exists that way. If it does, done.

Parameters:
className - fully qualified name of class to instantiate
args - array of constructor args (or null if none)
Returns:
the created bean
Throws:
BSFException - if something goes wrong (@see org.apache.cs.util.MethodUtils for the real exceptions that can occur).

getTypeSignatureString

public static java.lang.String getTypeSignatureString(java.lang.Class cl)
Given a class return the type signature string fragment for it. That is, return "I" for int, "J" for long, ... etc..

Parameters:
cl - class object for whom the signature fragment is needed.
Returns:
the string representing the type signature

loadClass

public static java.lang.Class loadClass(BSFManager mgr,
                                        java.lang.String name)
                                 throws BSFException
Loads a class using the following sequence of class loaders: Thread's context class loader, settable class loader stored with BSFManager, BSFManager's defining class loader, BSF customized class loader (from the BSFManager's temporary directory).

Parameters:
mgr - BSFManager who's classLoader and tempDir props are consulted
name - name of the class to load
Returns:
the loaded class
Throws:
BSFException - if something goes wrong.

20080913, rgf