public class ScriptEvaluator extends MultiCookable implements IScriptEvaluator
ScriptEvaluator object, proceed as described for IScriptEvaluator. Alternatively, a
number of "convenience constructors" exist that execute the described steps instantly.
Alternatively, a number of "convenience constructors" exist that execute the steps described above instantly. Their use is discouraged.
Notice that this implementation of IClassBodyEvaluator is prone to "Java injection", i.e. an
application could get more than one class body compiled by passing a bogus input document.
Also notice that the parsing of leading IMPORT declarations is heuristic and has certain limitations; see
ClassBodyEvaluator.parseImportDeclarations(Reader).
DEFAULT_METHOD_NAME, DEFAULT_RETURN_TYPE| Constructor and Description |
|---|
ScriptEvaluator() |
ScriptEvaluator(String script)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.cook(script);
|
ScriptEvaluator(String script,
Class<?> returnType)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.cook(script);
|
ScriptEvaluator(String script,
Class<?> returnType,
String[] parameterNames,
Class<?>[] parameterTypes)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.cook(script);
|
ScriptEvaluator(String script,
Class<?> returnType,
String[] parameterNames,
Class<?>[] parameterTypes,
Class<?>[] thrownExceptions)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.cook(script);
|
ScriptEvaluator(String fileName,
InputStream is,
Class<?> returnType,
String[] parameterNames,
Class<?>[] parameterTypes,
Class<?>[] thrownExceptions,
ClassLoader parentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(fileName, is);
|
ScriptEvaluator(String fileName,
Reader reader,
Class<?> returnType,
String[] parameterNames,
Class<?>[] parameterTypes,
Class<?>[] thrownExceptions,
ClassLoader parentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(reader);
|
| Modifier and Type | Method and Description |
|---|---|
void |
cook(String[] fileNames,
Reader[] readers) |
protected void |
cook(String[] fileNames,
Reader[] readers,
String[] imports) |
void |
cook(String fileName,
Reader reader) |
<T> T |
createFastEvaluator(Reader r,
Class<T> interfaceToImplement,
String[] parameterNames) |
<T> T |
createFastEvaluator(String script,
Class<T> interfaceToImplement,
String[] parameterNames) |
Object |
evaluate(int idx,
Object[] arguments) |
Object |
evaluate(Object[] arguments) |
Map<String,byte[]> |
getBytecodes() |
Class<?> |
getClazz() |
String[] |
getDefaultImports() |
Class<?> |
getDefaultReturnType() |
Method |
getMethod() |
Method |
getMethod(int idx) |
protected Method[] |
getMethods() |
Method[] |
getResult() |
protected Class<?> |
getReturnType(int i) |
void |
setClassName(String className) |
void |
setCompileErrorHandler(ErrorHandler compileErrorHandler) |
void |
setDebuggingInformation(boolean debugSource,
boolean debugLines,
boolean debugVars) |
void |
setDefaultImports(String... defaultImports) |
void |
setDefaultReturnType(Class<?> defaultReturnType) |
void |
setExtendedClass(Class<?> extendedClass) |
void |
setImplementedInterfaces(Class<?>[] implementedInterfaces) |
void |
setMethodName(String methodName) |
void |
setMethodNames(String[] methodNames) |
void |
setOverrideMethod(boolean overrideMethod) |
void |
setOverrideMethod(boolean[] overrideMethod) |
void |
setParameters(String[][] parameterNames,
Class<?>[][] parameterTypes) |
void |
setParameters(String[] names,
Class<?>[] types) |
void |
setParentClassLoader(ClassLoader parentClassLoader) |
void |
setReturnType(Class<?> returnType) |
void |
setReturnTypes(Class<?>[] returnTypes) |
void |
setScriptCount(int count) |
void |
setSourceVersion(int version) |
void |
setStaticMethod(boolean staticMethod) |
void |
setStaticMethod(boolean[] staticMethod) |
void |
setTargetVersion(int version) |
void |
setThrownExceptions(Class<?>[] thrownExceptions) |
void |
setThrownExceptions(Class<?>[][] thrownExceptions) |
void |
setWarningHandler(WarningHandler warningHandler) |
cook, cook, cook, cook, cook, cook, cook, cookFiles, cookFiles, cookFiles, cookFilescook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFileclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcook, cook, cookpublic ScriptEvaluator(String script) throws CompileException
ScriptEvaluator se = new ScriptEvaluator();
se.cook(script);
CompileExceptionScriptEvaluator(),
Cookable.cook(String)public ScriptEvaluator(String script, Class<?> returnType) throws CompileException
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.cook(script);
CompileExceptionScriptEvaluator(),
setReturnType(Class),
Cookable.cook(String)public ScriptEvaluator(String script, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes) throws CompileException
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.cook(script);
public ScriptEvaluator(String script, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions) throws CompileException
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.cook(script);
public ScriptEvaluator(@Nullable String fileName, InputStream is, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, @Nullable ClassLoader parentClassLoader) throws CompileException, IOException
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(fileName, is);
parentClassLoader - null means use current thread's context class loaderCompileExceptionIOExceptionScriptEvaluator(),
setReturnType(Class),
setParameters(String[], Class[]),
setThrownExceptions(Class[]),
SimpleCompiler.setParentClassLoader(ClassLoader),
Cookable.cook(String, InputStream)public ScriptEvaluator(@Nullable String fileName, Reader reader, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, @Nullable ClassLoader parentClassLoader) throws CompileException, IOException
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(reader);
parentClassLoader - null means use current thread's context class loaderCompileExceptionIOExceptionScriptEvaluator(),
setReturnType(Class),
setParameters(String[], Class[]),
setThrownExceptions(Class[]),
SimpleCompiler.setParentClassLoader(ClassLoader),
Cookable.cook(String, Reader)public ScriptEvaluator()
public void setParentClassLoader(@Nullable ClassLoader parentClassLoader)
setParentClassLoader in interface IScriptEvaluatorpublic void setDebuggingInformation(boolean debugSource,
boolean debugLines,
boolean debugVars)
setDebuggingInformation in interface IScriptEvaluatorpublic void setSourceVersion(int version)
setSourceVersion in interface ICookablepublic void setTargetVersion(int version)
setTargetVersion in interface ICookablepublic void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)
setCompileErrorHandler in interface IScriptEvaluatorpublic void setWarningHandler(@Nullable WarningHandler warningHandler)
setWarningHandler in interface IScriptEvaluatorpublic void setScriptCount(int count)
IllegalArgumentException - count is different from previous invocations of
this methodpublic void setClassName(String className)
setClassName in interface IScriptEvaluatorpublic void setImplementedInterfaces(Class<?>[] implementedInterfaces)
setImplementedInterfaces in interface IScriptEvaluatorpublic void setExtendedClass(@Nullable Class<?> extendedClass)
setExtendedClass in interface IScriptEvaluatorpublic void setDefaultReturnType(Class<?> defaultReturnType)
setDefaultReturnType in interface IScriptEvaluatorpublic Class<?> getDefaultReturnType()
getDefaultReturnType in interface IScriptEvaluatorpublic void setDefaultImports(String... defaultImports)
setDefaultImports in interface IScriptEvaluatorpublic String[] getDefaultImports()
getDefaultImports in interface IScriptEvaluatorpublic void setOverrideMethod(boolean overrideMethod)
setOverrideMethod in interface IScriptEvaluatorpublic void setStaticMethod(boolean staticMethod)
setStaticMethod in interface IScriptEvaluatorpublic void setReturnType(Class<?> returnType)
setReturnType in interface IScriptEvaluatorpublic void setMethodName(@Nullable String methodName)
setMethodName in interface IScriptEvaluatorpublic void setParameters(String[] names, Class<?>[] types)
setParameters in interface IScriptEvaluatorpublic void setThrownExceptions(Class<?>[] thrownExceptions)
setThrownExceptions in interface IScriptEvaluator@Nullable public Object evaluate(@Nullable Object[] arguments) throws InvocationTargetException
evaluate in interface IScriptEvaluatorInvocationTargetExceptionpublic Method getMethod()
getMethod in interface IScriptEvaluatorpublic void setOverrideMethod(boolean[] overrideMethod)
setOverrideMethod in interface IScriptEvaluatorpublic void setStaticMethod(boolean[] staticMethod)
setStaticMethod in interface IScriptEvaluatorpublic void setReturnTypes(Class<?>[] returnTypes)
setReturnTypes in interface IScriptEvaluatorpublic void setMethodNames(String[] methodNames)
setMethodNames in interface IScriptEvaluatorpublic void setParameters(String[][] parameterNames, Class<?>[][] parameterTypes)
setParameters in interface IScriptEvaluatorpublic void setThrownExceptions(Class<?>[][] thrownExceptions)
setThrownExceptions in interface IScriptEvaluatorpublic void cook(@Nullable String fileName, Reader reader) throws CompileException, IOException
cook in interface ICookablecook in class CookableCompileExceptionIOExceptionpublic void cook(String[] fileNames, Reader[] readers) throws CompileException, IOException
cook in interface IMultiCookablecook in interface IScriptEvaluatorcook in class MultiCookableCompileExceptionIOExceptionprotected final void cook(String[] fileNames, Reader[] readers, String[] imports) throws CompileException, IOException
readers - The scripts to cookCompileExceptionIOExceptionprotected final Class<?> getReturnType(int i)
public <T> T createFastEvaluator(String script, Class<T> interfaceToImplement, String[] parameterNames) throws CompileException
createFastEvaluator in interface IScriptEvaluatorscript - Contains the sequence of script tokensCompileExceptioncreateFastEvaluator(String, Class, String[])public <T> T createFastEvaluator(Reader r, Class<T> interfaceToImplement, String[] parameterNames) throws CompileException, IOException
createFastEvaluator in interface IScriptEvaluatorCompileExceptionIOException@Nullable public Object evaluate(int idx, @Nullable Object[] arguments) throws InvocationTargetException
evaluate in interface IScriptEvaluatorInvocationTargetExceptionpublic Method[] getResult()
getResult in interface IScriptEvaluatorpublic Method getMethod(int idx)
getMethod in interface IScriptEvaluatorprotected Method[] getMethods()
IllegalStateException - This ScriptEvaluator has not yet been cook()edpublic Class<?> getClazz()
getClazz in interface IScriptEvaluatorpublic Map<String,byte[]> getBytecodes()
getBytecodes in interface ICookableCopyright © 2022. All rights reserved.