| java.lang.Object org.apache.bsf.util.BSFEngineImpl org.apache.bsf.engines.java.JavaEngine
JavaEngine | public class JavaEngine extends BSFEngineImpl (Code) | | This is the interface to Java from the
Bean Scripting Framework.
The Java code must be written script-style -- that is, just the body of
the function, without class or method headers or footers.
The JavaEngine will generate those via a "boilerplate" wrapper:
import java.lang.*;
import java.util.*;
public class $$CLASSNAME$$ {
static public Object BSFJavaEngineEntry(org.apache.bsf.BSFManager bsf) {
// Your code will be placed here
}
}
$$CLASSNAME$$ will be replaced by a generated classname of the form
BSFJava*, and the bsf parameter can be used to retrieve application
objects registered with the Bean Scripting Framework.
If you use the placeholder string $$CLASSNAME$$ elsewhere
in your script -- including within text strings -- BSFJavaEngine will
replace it with the generated name of the class before the Java code
is compiled.
Hazards:
NOTE that it is your responsibility to convert the code into an acceptable
Java string. If you're invoking the JavaEngine directly (as in the
JSPLikeInJava example) that means \"quoting\" characters that would
otherwise cause trouble.
ALSO NOTE that it is your responsibility to return an object, or null in
lieu thereof!
Since the code has to be compiled to a Java classfile, invoking it involves
a fair amount of computation to load and execute the compiler. We are
currently making an attempt to manage that by caching the class
after it has been loaded, but the indexing is fairly primitive. It has
been suggested that the Bean Scripting Framework may want to support
preload-and-name-script and execute-preloaded-script-by-name options to
provide better control over when and how much overhead occurs.
author: Joe Kesselman |
Constructor Summary | |
public | JavaEngine() Constructor. |
Method Summary | |
public Object | call(Object object, String method, Object[] args) | public void | compileScript(String source, int lineNo, int columnNo, Object script, CodeBuffer cb) | public Object | eval(String source, int lineNo, int columnNo, Object oscript) This is used by an application to evaluate a string containing
some expression. | public void | initialize(BSFManager mgr, String lang, Vector declaredBeans) | Object | internalCall(Object object, String method, Object[] args) Return an object from an extension. |
serializeCompilation | static String serializeCompilation(Code) | | |
JavaEngine | public JavaEngine()(Code) | | Constructor.
|
eval | public Object eval(String source, int lineNo, int columnNo, Object oscript) throws BSFException(Code) | | This is used by an application to evaluate a string containing
some expression. It should store the "bsf" handle where the
script can get to it, for callback purposes.
Note that Java compilation imposes serious overhead,
but in exchange you get full Java performance
once the classes have been created (minus the cache lookup cost).
Nobody knows whether javac is threadsafe.
I'm going to serialize access to protect it.
There is no published API for invoking javac as a class. There's a trick
that seems to work for Java 1.1.x, but it stopped working in Java 1.2.
We will attempt to use it, then if necessary fall back on invoking
javac via the command line.
|
internalCall | Object internalCall(Object object, String method, Object[] args) throws BSFException(Code) | | Return an object from an extension.
Parameters: object - Object on which to make the internal_call (ignored). Parameters: method - The name of the method to internal_call. Parameters: args - an array of arguments to bepassed to the extension, which may be eitherVectors of Nodes, or Strings. |
Methods inherited from org.apache.bsf.util.BSFEngineImpl | public Object apply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments) throws BSFException(Code)(Java Doc) public void compileApply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames, Vector arguments, CodeBuffer cb) throws BSFException(Code)(Java Doc) public void compileExpr(String source, int lineNo, int columnNo, Object expr, CodeBuffer cb) throws BSFException(Code)(Java Doc) public void compileScript(String source, int lineNo, int columnNo, Object script, CodeBuffer cb) throws BSFException(Code)(Java Doc) public void declareBean(BSFDeclaredBean bean) throws BSFException(Code)(Java Doc) public void exec(String source, int lineNo, int columnNo, Object script) throws BSFException(Code)(Java Doc) public void iexec(String source, int lineNo, int columnNo, Object script) throws BSFException(Code)(Java Doc) public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException(Code)(Java Doc) public void propertyChange(PropertyChangeEvent e)(Code)(Java Doc) public void terminate()(Code)(Java Doc) public void undeclareBean(BSFDeclaredBean bean) throws BSFException(Code)(Java Doc)
|
|
|