public class ScriptEvaluator extends ClassBodyEvaluator 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).
| Modifier and Type | Field and Description |
|---|---|
protected boolean[] |
optionalOverrideMethod
Whether methods override a method declared by a supertype;
null means "none". |
protected boolean[] |
optionalStaticMethod
Whether methods are static;
null means "all". |
DEFAULT_CLASS_NAMEBOOT_CLASS_LOADER| 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 optionalFileName,
InputStream is,
Class<?> returnType,
String[] parameterNames,
Class<?>[] parameterTypes,
Class<?>[] thrownExceptions,
ClassLoader optionalParentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(optionalParentClassLoader);
se.cook(optionalFileName, is);
|
ScriptEvaluator(String optionalFileName,
Reader reader,
Class<?> returnType,
String[] parameterNames,
Class<?>[] parameterTypes,
Class<?>[] thrownExceptions,
ClassLoader optionalParentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(optionalParentClassLoader);
se.cook(reader);
|
| Modifier and Type | Method and Description |
|---|---|
void |
cook(Reader[] readers) |
void |
cook(String[] strings) |
void |
cook(String[] optionalFileNames,
Reader[] readers) |
protected void |
cook(String[] optionalFileNames,
Reader[] readers,
String[] imports) |
void |
cook(String[] optionalFileNames,
String[] strings) |
void |
cook(String optionalFileName,
Reader r) |
<T> Object |
createFastEvaluator(Reader r,
Class<T> interfaceToImplement,
String[] parameterNames) |
<T> Object |
createFastEvaluator(String script,
Class<T> interfaceToImplement,
String[] parameterNames) |
Object |
createInstance(Reader reader)
Don't use.
|
Object |
evaluate(int idx,
Object[] arguments) |
Object |
evaluate(Object[] arguments) |
protected Class<?> |
getDefaultReturnType()
The default return type of a script is
void. |
Method |
getMethod() |
Method |
getMethod(int idx) |
protected Method[] |
getMethods() |
protected Class<?> |
getReturnType(int i) |
void |
setMethodName(String methodName) |
void |
setMethodNames(String[] methodNames) |
void |
setOverrideMethod(boolean overrideMethod) |
void |
setOverrideMethod(boolean[] overrideMethod) |
void |
setParameters(String[][] names,
Class<?>[][] types) |
void |
setParameters(String[] names,
Class<?>[] types) |
void |
setReturnType(Class<?> returnType) |
void |
setReturnTypes(Class<?>[] returnTypes) |
void |
setStaticMethod(boolean staticMethod) |
void |
setStaticMethod(boolean[] staticMethod) |
void |
setThrownExceptions(Class<?>[] thrownExceptions) |
void |
setThrownExceptions(Class<?>[][] thrownExceptions) |
cook, getClazz, newFileName, parseImportDeclarations, setClassName, setDefaultImports, setExtendedClass, setExtendedType, setImplementedInterfaces, setImplementedTypesaddOffset, getClassLoader, setCompileErrorHandler, setDebuggingInformation, setNoPermissions, setParentClassLoader, setParentClassLoader, setPermissions, setWarningHandlercook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, readStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetClazz, setClassName, setDefaultImports, setExtendedClass, setExtendedType, setImplementedInterfaces, setImplementedTypesgetClassLoader, setNoPermissions, setPermissionscook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, setCompileErrorHandler, setDebuggingInformation, setParentClassLoader, setWarningHandler@Nullable protected boolean[] optionalOverrideMethod
null means "none".@Nullable protected boolean[] optionalStaticMethod
null means "all".public 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 optionalFileName, InputStream is, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, @Nullable ClassLoader optionalParentClassLoader) throws CompileException, IOException
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(optionalParentClassLoader);
se.cook(optionalFileName, is);
optionalParentClassLoader - 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 optionalFileName, Reader reader, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, @Nullable ClassLoader optionalParentClassLoader) throws CompileException, IOException
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(optionalParentClassLoader);
se.cook(reader);
optionalParentClassLoader - null means use current thread's context class loaderCompileExceptionIOExceptionScriptEvaluator(),
setReturnType(Class),
setParameters(String[], Class[]),
setThrownExceptions(Class[]),
SimpleCompiler.setParentClassLoader(ClassLoader),
ICookable.cook(String, Reader)public ScriptEvaluator()
public 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(String methodName)
setMethodName in interface IScriptEvaluatorpublic void setParameters(String[] names, Class<?>[] types)
setParameters in interface IScriptEvaluatorpublic void setThrownExceptions(Class<?>[] thrownExceptions)
setThrownExceptions in interface IScriptEvaluatorpublic void cook(@Nullable String optionalFileName, Reader r) throws CompileException, IOException
cook in interface ICookablecook in class ClassBodyEvaluatorCompileExceptionIOException@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[][] names, Class<?>[][] types)
setParameters in interface IScriptEvaluatorpublic void setThrownExceptions(Class<?>[][] thrownExceptions)
setThrownExceptions in interface IScriptEvaluatorpublic final void cook(Reader[] readers) throws CompileException, IOException
cook in interface IScriptEvaluatorCompileExceptionIOExceptionpublic void cook(@Nullable String[] optionalFileNames, Reader[] readers) throws CompileException, IOException
cook in interface IScriptEvaluatorCompileExceptionIOExceptionpublic final void cook(String[] strings) throws CompileException
cook in interface IScriptEvaluatorCompileExceptionpublic void cook(@Nullable String[] optionalFileNames, String[] strings) throws CompileException
cook in interface IScriptEvaluatorCompileExceptionprotected final void cook(@Nullable String[] optionalFileNames, Reader[] readers, String[] imports) throws CompileException, IOException
readers - The scripts to cookCompileExceptionIOExceptionprotected Class<?> getDefaultReturnType()
void.protected final Class<?> getReturnType(int i)
public <T> Object createFastEvaluator(String script, Class<T> interfaceToImplement, String[] parameterNames) throws CompileException
createFastEvaluator in interface IScriptEvaluatorscript - Contains the sequence of script tokensCompileExceptioncreateFastEvaluator(String, Class, String[])public final Object createInstance(Reader reader)
createInstance in interface IClassBodyEvaluatorcreateInstance in class ClassBodyEvaluatorpublic <T> Object 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 getMethod(int idx)
getMethod in interface IScriptEvaluatorprotected Method[] getMethods()
IllegalStateException - This ScriptEvaluator has not yet been cook()edCopyright © 2019. All rights reserved.