|
janino.net | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.janino.Cookable
org.codehaus.janino.SimpleCompiler
org.codehaus.janino.ClassBodyEvaluator
org.codehaus.janino.ScriptEvaluator
public class ScriptEvaluator
An engine that executes a script in JavaTM bytecode.
The syntax of the script to compile is a sequence of import declarations (not allowed if you compile many scripts at a time, see below) followed by a sequence of statements, as defined in the Java Language Specification, 2nd edition, sections 7.5 and 14.
Example:
import java.text.*; System.out.println("HELLO"); System.out.println(new DecimalFormat("####,###.##").format(a));(Notice that this expression refers to a parameter "a", as explained below.)
The script may complete abnormally, e.g. through a RETURN statement:
if (a == null) { System.out.println("Oops!"); return; }Optionally, the script may be declared with a non-void return type. In this case, the last statement of the script must be a RETURN statement (or a THROW statement), and all RETURN statements in the script must return a value with the given type.
The script evaluator is implemented by creating and compiling a temporary compilation unit defining one class with one method the body of which consists of the statements of the script.
To set up a ScriptEvaluator
object, proceed as follows:
ScriptEvaluator
using ScriptEvaluator()
ScriptEvaluator
by calling any of the following methods:
Cookable.cook(Scanner)
methods to scan,
parse, compile and load the script into the JVM.
ScriptEvaluator
object is created, the script can be executed as often with
different parameter values (see evaluate(Object[])
). This execution is very fast,
compared to the compilation.
Less common methods exist that allow for the specification of the name of the generated class,
the class it extends, the interfaces it implements, the name of the method that executes the
script, the exceptions that this method (i.e. the script) is allowed to throw, and the
ClassLoader
that is used to define the generated class and to load classes referenced by
the script.
Alternatively, a number of "convenience constructors" exist that execute the steps described above instantly. Their use is discouraged.
If you want to compile many scripts at the same time, you have the option to cook an
array of scripts in one ScriptEvaluator
by using the following methods:
setMethodNames(String[])
setParameters(String[][], Class[][])
setReturnTypes(Class[])
setStaticMethod(boolean[])
setThrownExceptions(Class[][])
cook(Scanner[])
evaluate(int, Object[])
Field Summary | |
---|---|
protected java.lang.String[] |
optionalMethodNames
|
protected java.lang.String[][] |
optionalParameterNames
|
protected java.lang.Class[][] |
optionalParameterTypes
|
protected java.lang.Class[] |
optionalReturnTypes
|
protected boolean[] |
optionalStaticMethod
|
protected java.lang.Class[][] |
optionalThrownExceptions
|
Fields inherited from class org.codehaus.janino.ClassBodyEvaluator |
---|
className, DEFAULT_CLASS_NAME, ZERO_CLASSES |
Fields inherited from class org.codehaus.janino.SimpleCompiler |
---|
BOOT_CLASS_LOADER |
Constructor Summary | |
---|---|
ScriptEvaluator()
|
|
ScriptEvaluator(Scanner scanner,
java.lang.Class optionalExtendedType,
java.lang.Class[] implementedTypes,
java.lang.Class returnType,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes,
java.lang.Class[] thrownExceptions,
java.lang.ClassLoader optionalParentClassLoader)
Equivalent to |
|
ScriptEvaluator(Scanner scanner,
java.lang.Class returnType,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes,
java.lang.Class[] thrownExceptions,
java.lang.ClassLoader optionalParentClassLoader)
Equivalent to |
|
ScriptEvaluator(Scanner scanner,
java.lang.String className,
java.lang.Class optionalExtendedType,
java.lang.Class[] implementedTypes,
boolean staticMethod,
java.lang.Class returnType,
java.lang.String methodName,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes,
java.lang.Class[] thrownExceptions,
java.lang.ClassLoader optionalParentClassLoader)
Equivalent to |
|
ScriptEvaluator(java.lang.String script)
Equivalent to |
|
ScriptEvaluator(java.lang.String script,
java.lang.Class returnType)
Equivalent to |
|
ScriptEvaluator(java.lang.String script,
java.lang.Class returnType,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes)
Equivalent to |
|
ScriptEvaluator(java.lang.String script,
java.lang.Class returnType,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes,
java.lang.Class[] thrownExceptions)
Equivalent to |
|
ScriptEvaluator(java.lang.String optionalFileName,
java.io.InputStream is,
java.lang.Class returnType,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes,
java.lang.Class[] thrownExceptions,
java.lang.ClassLoader optionalParentClassLoader)
Equivalent to |
|
ScriptEvaluator(java.lang.String optionalFileName,
java.io.Reader reader,
java.lang.Class returnType,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes,
java.lang.Class[] thrownExceptions,
java.lang.ClassLoader optionalParentClassLoader)
Equivalent to |
Method Summary | |
---|---|
protected void |
compileToMethods(Java.CompilationUnit compilationUnit,
java.lang.String[] methodNames,
java.lang.Class[][] parameterTypes)
|
void |
cook(java.io.Reader[] readers)
|
void |
cook(Scanner scanner)
To be implemented by the derived classes. |
void |
cook(Scanner[] scanners)
Like cook(Scanner) , but cooks a set of scripts into one class. |
void |
cook(java.lang.String[] strings)
Cook tokens from String s. |
void |
cook(java.lang.String[] optionalFileNames,
java.io.Reader[] readers)
|
static java.lang.Object |
createFastEvaluator(ScriptEvaluator se,
Scanner scanner,
java.lang.String[] parameterNames,
java.lang.Class interfaceToImplement)
Create and return an object that implements the exactly one method of the given interfaceToImplement . |
static java.lang.Object |
createFastEvaluator(ScriptEvaluator se,
java.lang.String s,
java.lang.String[] parameterNames,
java.lang.Class interfaceToImplement)
|
static java.lang.Object |
createFastScriptEvaluator(Scanner scanner,
java.lang.Class interfaceToImplement,
java.lang.String[] parameterNames,
java.lang.ClassLoader optionalParentClassLoader)
If the parameter and return types of the expression are known at compile time, then a "fast" script evaluator can be instantiated through this method. |
static java.lang.Object |
createFastScriptEvaluator(Scanner scanner,
java.lang.String[] optionalDefaultImports,
java.lang.String className,
java.lang.Class optionalExtendedType,
java.lang.Class interfaceToImplement,
java.lang.String[] parameterNames,
java.lang.ClassLoader optionalParentClassLoader)
|
static java.lang.Object |
createFastScriptEvaluator(Scanner scanner,
java.lang.String className,
java.lang.Class optionalExtendedType,
java.lang.Class interfaceToImplement,
java.lang.String[] parameterNames,
java.lang.ClassLoader optionalParentClassLoader)
Like createFastScriptEvaluator(Scanner, Class, String[], ClassLoader) ,
but gives you more control over the generated class (rarely needed in practice). |
static java.lang.Object |
createFastScriptEvaluator(java.lang.String script,
java.lang.Class interfaceToImplement,
java.lang.String[] parameterNames)
Simplified version of createFastScriptEvaluator(Scanner, Class, String[], ClassLoader) . |
java.lang.Object |
evaluate(int idx,
java.lang.Object[] parameterValues)
Calls the generated method with concrete parameter values. |
java.lang.Object |
evaluate(java.lang.Object[] parameterValues)
Calls the generated method with concrete parameter values. |
protected java.lang.Class |
getDefaultReturnType()
|
java.lang.reflect.Method |
getMethod()
Returns the loaded Method . |
java.lang.reflect.Method |
getMethod(int idx)
Returns the loaded Method . |
static java.lang.String[] |
guessParameterNames(Scanner scanner)
Guess the names of the parameters used in the given expression. |
protected Java.Block |
makeBlock(int idx,
Scanner scanner)
Fill the given block by parsing statements until EOF and adding
them to the block. |
protected Java.MethodDeclarator |
makeMethodDeclaration(Location location,
boolean staticMethod,
java.lang.Class returnType,
java.lang.String methodName,
java.lang.Class[] parameterTypes,
java.lang.String[] parameterNames,
java.lang.Class[] thrownExceptions,
Java.Block optionalBody)
To the given Java.ClassDeclaration , add
A public method declaration with the given return type, name, parameter
names and values and thrown exceptions
A block
|
void |
setMethodName(java.lang.String methodName)
Define the name of the generated method. |
void |
setMethodNames(java.lang.String[] methodNames)
Define the names of the generated methods. |
void |
setParameters(java.lang.String[][] parameterNames,
java.lang.Class[][] parameterTypes)
Define the names and types of the parameters of the generated methods. |
void |
setParameters(java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes)
Define the names and types of the parameters of the generated method. |
void |
setReturnType(java.lang.Class returnType)
Define the return type of the generated method. |
void |
setReturnTypes(java.lang.Class[] returnTypes)
Define the return types of the scripts. |
void |
setStaticMethod(boolean staticMethod)
Define whether the generated method should be STATIC or not. |
void |
setStaticMethod(boolean[] staticMethod)
Define whether the methods implementing each script should be STATIC or not. |
void |
setThrownExceptions(java.lang.Class[] thrownExceptions)
Define the exceptions that the generated method may throw. |
void |
setThrownExceptions(java.lang.Class[][] thrownExceptions)
Define the exceptions that the generated methods may throw. |
Methods inherited from class org.codehaus.janino.ClassBodyEvaluator |
---|
addPackageMemberClassDeclaration, compileToClass, createFastClassBodyEvaluator, createFastClassBodyEvaluator, getClazz, makeCompilationUnit, setClassName, setDefaultImports, setExtendedType, setImplementedTypes |
Methods inherited from class org.codehaus.janino.SimpleCompiler |
---|
assertNotCooked, classesToTypes, classToType, compileToClassLoader, cook, equals, getClassLoader, hashCode, main, setParentClassLoader, setParentClassLoader, setUpClassLoaders |
Methods inherited from class org.codehaus.janino.Cookable |
---|
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean[] optionalStaticMethod
protected java.lang.Class[] optionalReturnTypes
protected java.lang.String[] optionalMethodNames
protected java.lang.String[][] optionalParameterNames
protected java.lang.Class[][] optionalParameterTypes
protected java.lang.Class[][] optionalThrownExceptions
Constructor Detail |
---|
public ScriptEvaluator(java.lang.String script) throws CompileException, Parser.ParseException, Scanner.ScanException
ScriptEvaluator se = new ScriptEvaluator(); se.cook(script);
CompileException
Parser.ParseException
Scanner.ScanException
ScriptEvaluator()
,
Cookable.cook(String)
public ScriptEvaluator(java.lang.String script, java.lang.Class returnType) throws CompileException, Parser.ParseException, Scanner.ScanException
ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.cook(script);
CompileException
Parser.ParseException
Scanner.ScanException
ScriptEvaluator()
,
setReturnType(Class)
,
Cookable.cook(String)
public ScriptEvaluator(java.lang.String script, java.lang.Class returnType, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes) throws CompileException, Parser.ParseException, Scanner.ScanException
ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.cook(script);
CompileException
Parser.ParseException
Scanner.ScanException
ScriptEvaluator()
,
setReturnType(Class)
,
setParameters(String[], Class[])
,
Cookable.cook(String)
public ScriptEvaluator(java.lang.String script, java.lang.Class returnType, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes, java.lang.Class[] thrownExceptions) throws CompileException, Parser.ParseException, Scanner.ScanException
ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.cook(script);
CompileException
Parser.ParseException
Scanner.ScanException
ScriptEvaluator()
,
setReturnType(Class)
,
setParameters(String[], Class[])
,
setThrownExceptions(Class[])
,
Cookable.cook(String)
public ScriptEvaluator(java.lang.String optionalFileName, java.io.InputStream is, java.lang.Class returnType, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes, java.lang.Class[] thrownExceptions, java.lang.ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(optionalFileName, is);
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
ScriptEvaluator()
,
setReturnType(Class)
,
setParameters(String[], Class[])
,
setThrownExceptions(Class[])
,
SimpleCompiler.setParentClassLoader(ClassLoader)
,
Cookable.cook(String, InputStream)
public ScriptEvaluator(java.lang.String optionalFileName, java.io.Reader reader, java.lang.Class returnType, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes, java.lang.Class[] thrownExceptions, java.lang.ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(reader);
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
ScriptEvaluator()
,
setReturnType(Class)
,
setParameters(String[], Class[])
,
setThrownExceptions(Class[])
,
SimpleCompiler.setParentClassLoader(ClassLoader)
,
Cookable.cook(String, Reader)
public ScriptEvaluator(Scanner scanner, java.lang.Class returnType, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes, java.lang.Class[] thrownExceptions, java.lang.ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(scanner);
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
ScriptEvaluator()
,
setReturnType(Class)
,
setParameters(String[], Class[])
,
setThrownExceptions(Class[])
,
SimpleCompiler.setParentClassLoader(ClassLoader)
,
Cookable.cook(Scanner)
public ScriptEvaluator(Scanner scanner, java.lang.Class optionalExtendedType, java.lang.Class[] implementedTypes, java.lang.Class returnType, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes, java.lang.Class[] thrownExceptions, java.lang.ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
ScriptEvaluator se = new ScriptEvaluator(); se.setExtendedType(optionalExtendedType); se.setImplementedTypes(implementedTypes); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(scanner);
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
ScriptEvaluator()
,
ClassBodyEvaluator.setExtendedType(Class)
,
ClassBodyEvaluator.setImplementedTypes(Class[])
,
setReturnType(Class)
,
setParameters(String[], Class[])
,
setThrownExceptions(Class[])
,
SimpleCompiler.setParentClassLoader(ClassLoader)
,
Cookable.cook(Scanner)
public ScriptEvaluator(Scanner scanner, java.lang.String className, java.lang.Class optionalExtendedType, java.lang.Class[] implementedTypes, boolean staticMethod, java.lang.Class returnType, java.lang.String methodName, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes, java.lang.Class[] thrownExceptions, java.lang.ClassLoader optionalParentClassLoader) throws Scanner.ScanException, Parser.ParseException, CompileException, java.io.IOException
ScriptEvaluator se = new ScriptEvaluator(); se.setClassName(className); se.setExtendedType(optionalExtendedType); se.setImplementedTypes(implementedTypes); se.setStaticMethod(staticMethod); se.setReturnType(returnType); se.setMethodName(methodName); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(scanner);
Scanner.ScanException
Parser.ParseException
CompileException
java.io.IOException
ScriptEvaluator()
,
ClassBodyEvaluator.setClassName(String)
,
ClassBodyEvaluator.setExtendedType(Class)
,
ClassBodyEvaluator.setImplementedTypes(Class[])
,
setStaticMethod(boolean)
,
setReturnType(Class)
,
setMethodName(String)
,
setParameters(String[], Class[])
,
setThrownExceptions(Class[])
,
SimpleCompiler.setParentClassLoader(ClassLoader)
,
Cookable.cook(Scanner)
public ScriptEvaluator()
Method Detail |
---|
public void setStaticMethod(boolean staticMethod)
true
.
public void setReturnType(java.lang.Class returnType)
void.class
.
public void setMethodName(java.lang.String methodName)
public void setParameters(java.lang.String[] parameterNames, java.lang.Class[] parameterTypes)
public void setThrownExceptions(java.lang.Class[] thrownExceptions)
public final void cook(Scanner scanner) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
Cookable
cook
in class ClassBodyEvaluator
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
public java.lang.Object evaluate(java.lang.Object[] parameterValues) throws java.lang.reflect.InvocationTargetException
Each parameter value must have the same type as specified through
the "parameterTypes" parameter of
setParameters(String[], Class[])
.
Parameters of primitive type must passed with their wrapper class objects.
The object returned has the class as specified through
setReturnType(Class)
.
This method is thread-safe.
parameterValues
- The concrete parameter values.
java.lang.reflect.InvocationTargetException
public java.lang.reflect.Method getMethod()
Method
.
This method must only be called after cook(Scanner)
.
This method must not be called for instances of derived classes.
public void setStaticMethod(boolean[] staticMethod)
public void setReturnTypes(java.lang.Class[] returnTypes)
public void setMethodNames(java.lang.String[] methodNames)
If two scripts have the same name, then they must have different parameter types
(see setParameters(String[][], Class[][])
).
public void setParameters(java.lang.String[][] parameterNames, java.lang.Class[][] parameterTypes)
public void setThrownExceptions(java.lang.Class[][] thrownExceptions)
public final void cook(Scanner[] scanners) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
cook(Scanner)
, but cooks a set of scripts into one class. Notice that
if any of the scripts causes trouble, the entire compilation will fail. If you
need to report which of the scripts causes the exception, you may want to use the
optionalFileName
argument of Scanner.Scanner(String, Reader)
to
distinguish between the individual token sources.
On a 2 GHz Intel Pentium Core Duo under Windows XP with an IBM 1.4.2 JDK, compiling 10000 expressions "a + b" (integer) takes about 4 seconds and 56 MB of main memory. The generated class file is 639203 bytes large.
The number and the complexity of the scripts is restricted by the Limitations of the Java Virtual Machine, where the most limiting factor is the 64K entries limit of the constant pool. Since every method with a distinct name requires one entry there, you can define at best 32K (very simple) scripts. If and only if the number of scanners is one, then that single script may contain leading IMPORT directives.
java.lang.IllegalStateException
- if any of the preceeding set...()
had an array size different from that of scanners
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
public final void cook(java.io.Reader[] readers) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
public final void cook(java.lang.String[] optionalFileNames, java.io.Reader[] readers) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
optionalFileNames
- Used when reporting errors and warnings.
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
public final void cook(java.lang.String[] strings) throws CompileException, Parser.ParseException, Scanner.ScanException
String
s.
CompileException
Parser.ParseException
Scanner.ScanException
protected java.lang.Class getDefaultReturnType()
protected Java.Block makeBlock(int idx, Scanner scanner) throws Parser.ParseException, Scanner.ScanException, java.io.IOException
block
by parsing statements until EOF and adding
them to the block.
Parser.ParseException
Scanner.ScanException
java.io.IOException
protected void compileToMethods(Java.CompilationUnit compilationUnit, java.lang.String[] methodNames, java.lang.Class[][] parameterTypes) throws CompileException
CompileException
protected Java.MethodDeclarator makeMethodDeclaration(Location location, boolean staticMethod, java.lang.Class returnType, java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.String[] parameterNames, java.lang.Class[] thrownExceptions, Java.Block optionalBody)
Java.ClassDeclaration
, add
returnType
- Return type of the declared methodpublic static java.lang.Object createFastScriptEvaluator(java.lang.String script, java.lang.Class interfaceToImplement, java.lang.String[] parameterNames) throws CompileException, Parser.ParseException, Scanner.ScanException
createFastScriptEvaluator(Scanner, Class, String[], ClassLoader)
.
script
- Contains the sequence of script tokensinterfaceToImplement
- Must declare exactly the one method that defines the expression's signatureparameterNames
- The expression references the parameters through these names
optionalExtendedType
CompileException
Parser.ParseException
Scanner.ScanException
public static java.lang.Object createFastScriptEvaluator(Scanner scanner, java.lang.Class interfaceToImplement, java.lang.String[] parameterNames, java.lang.ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
Script evaluation is faster than through evaluate(Object[])
, because
it is not done through reflection but through direct method invocation.
Example:
public interface Foo { int bar(int a, int b); } ... Foo f = (Foo) ScriptEvaluator.createFastScriptEvaluator( new Scanner(null, new StringReader("return a + b;")), Foo.class, new String[] { "a", "b" }, (ClassLoader) null // Use current thread's context class loader ); System.out.println("1 + 2 = " + f.bar(1, 2));Notice: The
interfaceToImplement
must either be declared public
,
or with package scope in the root package (i.e. "no" package).
scanner
- Source of script tokensinterfaceToImplement
- Must declare exactly one methodparameterNames
- optionalParentClassLoader
-
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
public static java.lang.Object createFastScriptEvaluator(Scanner scanner, java.lang.String className, java.lang.Class optionalExtendedType, java.lang.Class interfaceToImplement, java.lang.String[] parameterNames, java.lang.ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
createFastScriptEvaluator(Scanner, Class, String[], ClassLoader)
,
but gives you more control over the generated class (rarely needed in practice).
Notice: The interfaceToImplement
must either be declared public
,
or with package scope in the same package as className
.
scanner
- Source of script tokensclassName
- Name of generated classoptionalExtendedType
- Class to extendinterfaceToImplement
- Must declare exactly the one method that defines the expression's signatureparameterNames
- The expression references the parameters through these namesoptionalParentClassLoader
- Used to load referenced classes, defaults to the current thread's "context class loader"
optionalExtendedType
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
public static java.lang.Object createFastScriptEvaluator(Scanner scanner, java.lang.String[] optionalDefaultImports, java.lang.String className, java.lang.Class optionalExtendedType, java.lang.Class interfaceToImplement, java.lang.String[] parameterNames, java.lang.ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
public static java.lang.Object createFastEvaluator(ScriptEvaluator se, java.lang.String s, java.lang.String[] parameterNames, java.lang.Class interfaceToImplement) throws CompileException, Parser.ParseException, Scanner.ScanException
CompileException
Parser.ParseException
Scanner.ScanException
public static java.lang.Object createFastEvaluator(ScriptEvaluator se, Scanner scanner, java.lang.String[] parameterNames, java.lang.Class interfaceToImplement) throws CompileException, Parser.ParseException, Scanner.ScanException, java.io.IOException
interfaceToImplement
.
se
- A pre-configured ScriptEvaluator
objectscanner
- Source of tokens to readparameterNames
- The names of the parameters of the one abstract method of interfaceToImplement
interfaceToImplement
- A type with exactly one abstract method
Object
CompileException
Parser.ParseException
Scanner.ScanException
java.io.IOException
public static java.lang.String[] guessParameterNames(Scanner scanner) throws Parser.ParseException, Scanner.ScanException, java.io.IOException
Parser.ParseException
Scanner.ScanException
java.io.IOException
Scanner.Scanner(String, Reader)
public java.lang.Object evaluate(int idx, java.lang.Object[] parameterValues) throws java.lang.reflect.InvocationTargetException
Each parameter value must have the same type as specified through
the "parameterTypes" parameter of
setParameters(String[], Class[])
.
Parameters of primitive type must passed with their wrapper class objects.
The object returned has the class as specified through
setReturnType(Class)
.
This method is thread-safe.
idx
- The index of the script (0 ... scripts.length - 1
)parameterValues
- The concrete parameter values.
java.lang.reflect.InvocationTargetException
public java.lang.reflect.Method getMethod(int idx)
Method
.
This method must only be called after cook(Scanner)
.
This method must not be called for instances of derived classes.
idx
- The index of the script (0 ... scripts.length - 1
)
|
janino.net | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |