org.apache.bsf.util
Class EngineUtils
java.lang.Object
org.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.
- Sanjiva Weerawarana
- Sam Ruby
static void | addEventListener(Object bean, String eventSetName, String filter, BSFEngine engine, BSFManager manager, String source, int lineNo, int columnNo, Object script) - Add a script as a listener to some event coming out of an object.
|
static Object | callBeanMethod(Object bean, String methodName, Object[] args) - Finds and invokes a method with the given signature on the given
bean.
|
static Object | createBean(String className, args[] ) - Creates a new bean.
|
static String | getTypeSignatureString(Class cl) - Given a class return the type signature string fragment for it.
|
static Class | loadClass(BSFManager mgr, String name) - Load a class using the class loader of given manager.
|
addEventListener
public static void addEventListener(Object bean,
String eventSetName,
String filter,
BSFEngine engine,
BSFManager manager,
String source,
int lineNo,
int columnNo,
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.
bean
- event sourceeventSetName
- name of event set from event src to bind tofilter
- filter for eventsengine
- BSFEngine which can run this scriptmanager
- BSFManager of the above enginesource
- (context info) the source of this expression
(e.g., filename)lineNo
- (context info) the line number in source for exprcolumnNo
- (context info) the column number in source for exprscript
- the script to execute when the event occurs
BSFException
- if anything goes wrong while running the script
callBeanMethod
public static Object callBeanMethod(Object bean,
String methodName,
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.
bean
- the object on which to invoke the methodmethodName
- name of the methodargs
- arguments to be given to the method
- the result of invoking the method, if any
BSFException
- if something goes wrong
createBean
public static Object createBean(String className,
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.
className
- fully qualified name of class to instantiate
- the created bean
BSFException
- if something goes wrong (@see
org.apache.cs.util.MethodUtils for the real
exceptions that can occur).
getTypeSignatureString
public static String getTypeSignatureString(Class cl)
Given a class return the type signature string fragment for it.
That is, return "I" for int, "J" for long, ... etc..
cl
- class object for whom the signature fragment is needed.
- the string representing the type signature
loadClass
public static Class loadClass(BSFManager mgr,
String name)
throws BSFException
Load a class using the class loader of given manager. If that fails
try using a class loader that loads from the tempdir of the manager.
mgr
- BSFManager who's classLoader and tempDir props are
consultedname
- name of the class to load
- the loaded class
BSFException
- if something goes wrong.