Logo Search packages:      
Sourcecode: janino version File versions  Download package

org::codehaus::janino::ScriptEvaluator Class Reference

Inheritance diagram for org::codehaus::janino::ScriptEvaluator:

org::codehaus::janino::ClassBodyEvaluator org::codehaus::janino::SimpleCompiler org::codehaus::janino::Cookable org::codehaus::janino::ExpressionEvaluator

List of all members.


Detailed Description

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:

  1. Create the ScriptEvaluator using ScriptEvaluator()
  2. Configure the ScriptEvaluator by calling any of the following methods:
  3. Call any of the org.codehaus.janino.Cookable#cook(Scanner) methods to scan, parse, compile and load the script into the JVM.
After the 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:

Notice that these methods have array parameters in contrast to their one-script brethren.

Definition at line 124 of file ScriptEvaluator.java.


Public Member Functions

final void cook (String s) throws CompileException, Parser.ParseException, Scanner.ScanException
final void cook (String optionalFileName, InputStream is, String optionalEncoding) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (InputStream is, String optionalEncoding) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (String optionalFileName, InputStream is) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (InputStream is) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (String optionalFileName, Reader r) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (Reader r) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (String[] strings) throws CompileException, Parser.ParseException, Scanner.ScanException
final void cook (String[] optionalFileNames, Reader[] readers) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (Reader[] readers) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (Scanner[] scanners) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cook (Scanner scanner) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cookFile (String fileName, String optionalEncoding) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cookFile (String fileName) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cookFile (File file, String optionalEncoding) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
final void cookFile (File file) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
boolean equals (Object o)
Object evaluate (int idx, Object[] parameterValues) throws InvocationTargetException
Object evaluate (Object[] parameterValues) throws InvocationTargetException
ClassLoader getClassLoader ()
Class getClazz ()
Method getMethod (int idx)
Method getMethod ()
int hashCode ()
 ScriptEvaluator (Scanner scanner, String className, Class optionalExtendedType, Class[] implementedTypes, boolean staticMethod, Class returnType, String methodName, String[] parameterNames, Class[] parameterTypes, Class[] thrownExceptions, ClassLoader optionalParentClassLoader) throws Scanner.ScanException, Parser.ParseException, CompileException, IOException
 ScriptEvaluator (Scanner scanner, Class optionalExtendedType, Class[] implementedTypes, Class returnType, String[] parameterNames, Class[] parameterTypes, Class[] thrownExceptions, ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
 ScriptEvaluator (Scanner scanner, Class returnType, String[] parameterNames, Class[] parameterTypes, Class[] thrownExceptions, ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
 ScriptEvaluator (String optionalFileName, Reader reader, Class returnType, String[] parameterNames, Class[] parameterTypes, Class[] thrownExceptions, ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
 ScriptEvaluator (String optionalFileName, InputStream is, Class returnType, String[] parameterNames, Class[] parameterTypes, Class[] thrownExceptions, ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
 ScriptEvaluator (String script, Class returnType, String[] parameterNames, Class[] parameterTypes, Class[] thrownExceptions) throws CompileException, Parser.ParseException, Scanner.ScanException
 ScriptEvaluator (String script, Class returnType, String[] parameterNames, Class[] parameterTypes) throws CompileException, Parser.ParseException, Scanner.ScanException
 ScriptEvaluator (String script, Class returnType) throws CompileException, Parser.ParseException, Scanner.ScanException
 ScriptEvaluator (String script) throws CompileException, Parser.ParseException, Scanner.ScanException
void setClassName (String className)
void setDefaultImports (String[] optionalDefaultImports)
void setExtendedType (Class optionalExtendedType)
void setImplementedTypes (Class[] implementedTypes)
void setMethodName (String methodName)
void setMethodNames (String[] methodNames)
void setParameters (String[][] parameterNames, Class[][] parameterTypes)
void setParameters (String[] parameterNames, Class[] parameterTypes)
void setParentClassLoader (ClassLoader optionalParentClassLoader, Class[] auxiliaryClasses)
void setParentClassLoader (ClassLoader optionalParentClassLoader)
void setReturnType (Class returnType)
void setReturnTypes (Class[] returnTypes)
void setStaticMethod (boolean[] staticMethod)
void setStaticMethod (boolean staticMethod)
void setThrownExceptions (Class[][] thrownExceptions)
void setThrownExceptions (Class[] thrownExceptions)

Static Public Member Functions

static Object createFastClassBodyEvaluator (Scanner scanner, String className, Class optionalExtendedType, Class[] implementedTypes, ClassLoader optionalParentClassLoader) throws CompileException, ParseException, ScanException, IOException
static Object createFastClassBodyEvaluator (Scanner scanner, Class optionalBaseType, ClassLoader optionalParentClassLoader) throws CompileException, ParseException, ScanException, IOException
static Object createFastEvaluator (ScriptEvaluator se, Scanner scanner, String[] parameterNames, Class interfaceToImplement) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
static Object createFastEvaluator (ScriptEvaluator se, String s, String[] parameterNames, Class interfaceToImplement) throws CompileException, Parser.ParseException, Scanner.ScanException
static Object createFastScriptEvaluator (Scanner scanner, String[] optionalDefaultImports, String className, Class optionalExtendedType, Class interfaceToImplement, String[] parameterNames, ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
static Object createFastScriptEvaluator (Scanner scanner, String className, Class optionalExtendedType, Class interfaceToImplement, String[] parameterNames, ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
static Object createFastScriptEvaluator (Scanner scanner, Class interfaceToImplement, String[] parameterNames, ClassLoader optionalParentClassLoader) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
static Object createFastScriptEvaluator (String script, Class interfaceToImplement, String[] parameterNames) throws CompileException, Parser.ParseException, Scanner.ScanException
static void main (String[] args) throws Exception

Static Public Attributes

static final ClassLoader BOOT_CLASS_LOADER = new ClassLoader(null) {}
static final String DEFAULT_CLASS_NAME = "SC"

Protected Member Functions

Java.PackageMemberClassDeclaration addPackageMemberClassDeclaration (Location location, Java.CompilationUnit compilationUnit) throws ParseException
Java.Type[] classesToTypes (Location location, Class[] classes)
Java.Type classToType (Location location, final Class optionalClass)
final Class compileToClass (Java.CompilationUnit compilationUnit, EnumeratorSet debuggingInformation, String newClassName) throws CompileException
final ClassLoader compileToClassLoader (Java.CompilationUnit compilationUnit, EnumeratorSet debuggingInformation) throws CompileException
void compileToMethods (Java.CompilationUnit compilationUnit, String[] methodNames, Class[][] parameterTypes) throws CompileException
Class getDefaultReturnType ()
Java.Block makeBlock (int idx, Scanner scanner) throws ParseException, ScanException, IOException
final Java.CompilationUnit makeCompilationUnit (Scanner optionalScanner) throws ParseException, ScanException, IOException
Java.MethodDeclarator makeMethodDeclaration (Location location, boolean staticMethod, Class returnType, String methodName, Class[] parameterTypes, String[] parameterNames, Class[] thrownExceptions, Java.Block optionalBody)
final void setUpClassLoaders ()

Protected Attributes

String className = ClassBodyEvaluator.DEFAULT_CLASS_NAME
String[] optionalMethodNames = null
String[][] optionalParameterNames = null
Class[][] optionalParameterTypes = null
Class[] optionalReturnTypes = null
boolean[] optionalStaticMethod = null
Class[][] optionalThrownExceptions = null

Static Protected Attributes

static final Class[] ZERO_CLASSES = new Class[0]

Private Attributes

Method[] result = null

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index