org.apache.bsf
public class BSFManager extends Object
BSFManager serves as the registry of available scripting engines as well. Loading and unloading of scripting engines is supported as well. Each BSFManager loads one engine per language. Several BSFManagers can be created per JVM.
Field Summary | |
---|---|
protected ClassLoader | classLoader |
protected String | classPath |
protected Vector | declaredBeans |
protected static Hashtable | extn2Lang |
protected Hashtable | loadedEngines |
protected ObjectRegistry | objectRegistry |
protected PropertyChangeSupport | pcs |
protected static Hashtable | registeredEngines |
protected String | tempDir |
protected static String | version |
Constructor Summary | |
---|---|
BSFManager() |
Method Summary | |
---|---|
Object | apply(String lang, String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments)
Apply the given anonymous function of the given language to the given
parameters and return the resulting value.
|
void | compileApply(String lang, String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments, CodeBuffer cb)
Compile the application of the given anonymous function of the given
language to the given parameters into the given CodeBuffer.
|
void | compileExpr(String lang, String source, int lineNo, int columnNo, Object expr, CodeBuffer cb)
Compile the given expression of the given language into the given
CodeBuffer.
|
void | compileScript(String lang, String source, int lineNo, int columnNo, Object script, CodeBuffer cb)
Compile the given script of the given language into the given
CodeBuffer.
|
void | declareBean(String beanName, Object bean, Class type)
Declare a bean. |
Object | eval(String lang, String source, int lineNo, int columnNo, Object expr)
Evaluate the given expression of the given language and return the
resulting value.
|
void | exec(String lang, String source, int lineNo, int columnNo, Object script)
Execute the given script of the given language.
|
ClassLoader | getClassLoader()
Get classLoader |
String | getClassPath()
Get classPath |
static String | getLangFromFilename(String fileName)
Determine the language of a script file by looking at the file
extension.
|
ObjectRegistry | getObjectRegistry()
Return the current object registry of the manager.
|
String | getTempDir()
Get tempDir |
static String | getVersion() Returns the version string of BSF.
|
void | iexec(String lang, String source, int lineNo, int columnNo, Object script)
Execute the given script of the given language, attempting to
emulate an interactive session w/ the language.
|
static boolean | isLanguageRegistered(String lang)
Determine whether a language is registered.
|
BSFEngine | loadScriptingEngine(String lang)
Load a scripting engine based on the lang string identifying it.
|
Object | lookupBean(String beanName)
return a handle to a bean registered in the bean registry by the
application or a scripting engine. |
void | registerBean(String beanName, Object bean)
Registering a bean allows a scripting engine or the application to
access that bean by name and to manipulate it.
|
static void | registerScriptingEngine(String lang, String engineClassName, String[] extensions)
Register a scripting engine in the static registry of the
BSFManager.
|
void | setClassLoader(ClassLoader classLoader)
Set the class loader for those that need to use it. |
void | setClassPath(String classPath)
Set the classpath for those that need to use it. |
void | setObjectRegistry(ObjectRegistry objectRegistry)
Set the object registry used by this manager. |
void | setTempDir(String tempDir)
Temporary directory to put stuff into (for those who need to). |
void | terminate()
Gracefully terminate all engines |
void | undeclareBean(String beanName)
Undeclare a previously declared bean. |
void | unregisterBean(String beanName)
Unregister a previously registered bean. |
Parameters: lang language identifier 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 funcBody the multi-line, value returning script to evaluate paramNames the names of the parameters above assumes arguments values of the above parameters
Throws: BSFException if anything goes wrong while running the script
Parameters: lang language identifier 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 funcBody the multi-line, value returning script to evaluate paramNames the names of the parameters above assumes arguments values of the above parameters cb code buffer to compile into
Throws: BSFException if anything goes wrong while running the script
Parameters: lang language identifier 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 expr the expression to compile cb code buffer to compile into
Throws: BSFException if any error while compiling the expression
Parameters: lang language identifier source (context info) the source of this script (e.g., filename) lineNo (context info) the line number in source for script columnNo (context info) the column number in source for script script the script to compile cb code buffer to compile into
Throws: BSFException if any error while compiling the script
When a bean is declared it is automatically registered as well so that any declared bean can be gotton to by looking it up as well.
If any of the languages that are already running in this manager says they don't like this (by throwing an exception) then this method will simply quit with that exception. That is, any engines that come after than in the engine enumeration will not even be told about this new bean.
So, in general its best to declare beans before the manager has been asked to load any engines because then the user can be informed when an engine rejects it. Also, its much more likely that an engine can declare a bean at start time than it can at any time.
Parameters: beanName name to declare bean as bean the bean that's being declared type the type to represent the bean as
Throws: BSFException if any of the languages that are already running decides to throw an exception when asked to declare this bean.
Parameters: lang language identifier 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 expr the expression to evaluate
Throws: BSFException if anything goes wrong while running the script
Parameters: lang language identifier 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
Throws: BSFException if anything goes wrong while running the script
Parameters: fileName the name of the file
Returns: the scripting language the file is in if the file extension is known to me (must have been registered via registerScriptingEngine).
Throws: BSFException if file's extension is unknown.
Returns: the current registry.
Returns: version string in the form "abc.yyyymmdd" where
"abc" represents a dewey decimal number (three levels, each between 0 and 9), and
"yyyy" a four digit year, "mm" a two digit month,
"dd" a two digit day.
Example: "240.20061006
"
stands for: BSF version 2.4.0
as of 2006-10-06
.
Since: 2006-01-17
Parameters: lang language identifier 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
Throws: BSFException if anything goes wrong while running the script
Parameters: lang string identifying a language
Returns: true iff it is
Parameters: lang string identifying language
Throws: BSFException if the language is unknown (i.e., if it has not been registered) with a reason of REASON_UNKNOWN_LANGUAGE. If the language is known but if the interface can't be created for some reason, then the reason is set to REASON_OTHER_ERROR and the actual exception is passed on as well.
Parameters: beanName name of bean to look up
Returns: the bean if its found or null
Parameters: beanName name to register under bean the bean to register
Parameters: lang string identifying language engineClassName fully qualified name of the class interfacing the language to BSF. extensions array of file extensions that should be mapped to this language type. may be null.
Parameters: classLoader the class loader to use.
Parameters: classPath the classpath to use
Parameters: objectRegistry the registry to use
Parameters: tempDir the temporary directory
Parameters: beanName name of bean to undeclare
Throws: BSFException if any of the languages that are already running decides to throw an exception when asked to undeclare this bean.
Parameters: beanName name of bean to unregister