public class GroovyScript extends AbstractScript
| Modifier and Type | Class and Description |
|---|---|
class |
GroovyScript.Function |
static class |
GroovyScript.HGB |
RM_DEFAULT, RM_RESULT, RM_SCRIPT, SL_BEANSHELL, SL_DEFAULT, SL_GROOVY, STR_VALUES_FALSE, STR_VALUES_TRUE| Constructor and Description |
|---|
GroovyScript(java.lang.String _source,
boolean _precompile)
Instantiates a new Groovy script runner instance.
|
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent) |
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl) |
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars) |
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars,
java.util.List<ScriptImport> _defaultImports) |
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars,
java.util.List<ScriptImport> _defaultImports,
java.lang.String _baseClassName) |
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars,
java.util.List<ScriptImport> _defaultImports,
java.lang.String _baseClassName,
GroovyScript.HGB _binding) |
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars,
java.util.List<ScriptImport> _defaultImports,
java.lang.String _baseClassName,
GroovyScript.HGB _binding,
java.lang.String _scriptname) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
asBool(java.lang.Object o,
boolean nullValue)
Converts an object to a boolean.
|
static boolean |
asBoolStatic(java.lang.Object o,
boolean nullValue) |
java.lang.Object |
boolConverter(java.lang.Object o,
java.lang.Object nullValue) |
void |
clear()
Clears local variable bindings and cached execution state.
|
void |
close()
Closes this script instance, freeing up resources.
|
void |
compileNT(int offset,
java.lang.String errorTip)
Compiles the script with a specified line offset and error tip.
|
static boolean |
compilesToSame(java.lang.String sourceA,
java.lang.String sourceB)
Checks if the two given pieces of source code will result in the same actual script, that is not only differ
in things like comments or whitespace.
|
ScriptFunctionI |
createFunction(java.lang.String src,
java.lang.String[] parmNames,
java.lang.Class[] parmTypes,
java.lang.Class returnType)
Creates a function from a script source string.
|
ScriptFunctionI |
createFunction(java.lang.String src,
java.lang.String[] parmNames,
java.lang.Class[] parmTypes,
java.lang.Class returnType,
java.lang.String scriptName,
java.lang.String functionName)
Creates a function from a script source string.
|
ScriptFunctionI |
createFunction(java.lang.String src,
java.lang.String[] parmNames,
java.lang.Class[] parmTypes,
java.lang.Class returnType,
java.lang.String scriptName,
java.lang.String functionName,
int offset)
Creates a function from a script source string.
|
ScriptFunctionI |
createFunction(java.lang.String src,
java.lang.String[] parmNames,
java.lang.Class[] parmTypes,
java.lang.Class returnType,
java.lang.String scriptName,
java.lang.String functionName,
int offset,
java.lang.Object delegate)
Creates a function from a script source string.
|
void |
createScript() |
boolean |
evalAsBoolNT(java.lang.String s,
boolean nullValue,
int offset,
java.lang.String errorTip)
Evaluates a string as a script with a specified null value and line offset and returns the result as boolean.
|
java.lang.Object |
evalNT(java.lang.String s,
java.lang.Object nullValue,
int offset,
java.lang.String errorTip)
Evaluates a string as a script with a specified null value and line offset and returns the result as Object.
|
java.lang.Object |
evalNT(java.lang.String s,
java.lang.Object nullValue,
int offset,
java.lang.String errorTip,
java.util.function.BiFunction typeConverter) |
GroovyScript.HGB |
getBinding() |
org.codehaus.groovy.control.CompilerConfiguration |
getCompilerConf() |
groovy.lang.Script |
getEvalScript(java.lang.String s) |
groovy.lang.Script |
getEvalScript(java.lang.String s,
java.lang.String name) |
java.lang.String |
getLanguage()
Returns the scripting language of this script instance.
|
int |
getLineOffset() |
java.lang.Object |
getNT(java.lang.String name,
java.lang.Object exValue)
Gets the value of a variable from the script context.
|
GroovyScript |
getParent() |
groovy.lang.GroovyShell |
getShell() |
java.lang.String |
getSource()
Hierarchical Groovy Binding (HGB).
|
boolean |
hasSource()
Checks if this script has source code.
|
void |
initShellInstance(java.lang.ClassLoader cl,
java.util.List<ScriptImport> imports,
java.lang.String baseClassName) |
static boolean |
isActualScript(java.lang.String _str)
Checks if the given text, supposed to be script source, actually results in
a valid (Groovy) script, that is one that does not completely consist only
of comments.
|
static boolean |
isActualScriptNT(java.lang.String _str)
Checks if the given text, supposed to be script source, actually results in
a valid (Groovy) script, that is one that does not completely consist only
of comments.
|
static boolean |
isActualScriptNT(java.lang.String _str,
boolean _errorValue) |
static boolean |
isActualScriptNT(java.lang.String _str,
boolean _errorValue,
boolean _logException) |
static boolean |
isActualScriptTR(java.lang.String _src)
Checks if the given text, supposed to be syntactically valid script source,
actually results in a valid (Groovy) script, that is one that does not
completely consist only of comments.
|
static boolean |
isActualScriptTR(java.lang.String _src,
java.lang.String _msg) |
static boolean |
isValidVarName(java.lang.Object o)
Checks if the passed Object is a valid variable name for Groovy.
|
int |
nextFunctionCounter() |
int |
nextScriptCounter() |
static java.lang.String |
replaceCustomLogicalOperators(java.lang.String scriptCode)
Replaces our custom logical operators (for hassle-free usage in XML, avoiding a CDATA block just for that)
in the given string with standard Groovy logical operators.
|
java.lang.Object |
runAsObjectNT(java.lang.Object nullValue,
int offset,
java.lang.String errorTip)
Executes the compiled script and returns the result as an arbitrary
Object. |
void |
setBinding(GroovyScript.HGB $16) |
void |
setCompilerConf(org.codehaus.groovy.control.CompilerConfiguration $15) |
void |
setLineOffset(int $12)
Sets an offset for line numbers, used for error reporting.
|
void |
setNT(java.lang.String name,
java.lang.Object value,
boolean local)
Sets a variable, optionally with local scope.
|
void |
setParent(GroovyScript $13) |
void |
setPrecompile(boolean _b)
Sets the pre-compile flag.
|
void |
setShell(groovy.lang.GroovyShell $14) |
void |
setSource(java.lang.String $11)
Sets the source code of this script.
|
asString, compileNT, compileNT, evalAsBoolNT, evalAsBoolNT, evalAsBoolNT, evalAsStringNT, evalAsStringNT, evalAsStringNT, evalAsStringNT, evalNT, evalNT, evalNT, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInterrupt, getJavaSyntaxImports, getJavaSyntaxImports, getNT, isScriptException, runAsBoolNT, runAsBoolNT, runAsBoolNT, runAsBoolNT, runAsObjectNT, runAsObjectNT, runAsObjectNT, runAsStringNT, runAsStringNT, runAsStringNT, runAsStringNT, runNT, runNT, runNT, setInterrupt, setNT, setNT, setNT, setNT, setNT, setNT, setNT, setNT, setNT, setNT, setNT, setNTpublic GroovyScript(java.lang.String _source,
boolean _precompile)
_source - raw script source code_precompile - if true, compiles the script into bytecode immediately upon instantiation_parent - optional parent script to inherit variable bindings from_cl - custom classloader for resolving domain dependencies_initialvars - initial key-value pairs populated into the execution scope_defaultImports - list of default import descriptors automatically prepended to the script_baseClassName - optional base script class extending Script_binding - custom hierarchical binding context instance (HGB)_scriptname - identifier used for debugging, stack traces, and profiler metricspublic GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent)
public GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl)
public GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars)
public GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars,
java.util.List<ScriptImport> _defaultImports)
public GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars,
java.util.List<ScriptImport> _defaultImports,
java.lang.String _baseClassName)
public GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars,
java.util.List<ScriptImport> _defaultImports,
java.lang.String _baseClassName,
GroovyScript.HGB _binding)
public GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map<java.lang.String,java.lang.Object> _initialvars,
java.util.List<ScriptImport> _defaultImports,
java.lang.String _baseClassName,
GroovyScript.HGB _binding,
java.lang.String _scriptname)
public static java.lang.String replaceCustomLogicalOperators(java.lang.String scriptCode)
This method transforms custom logical operators "@and" and "@or" into "&&" and "||" respectively. It is particularly useful for converting Groovy script strings coming from XML that contain non-standard logical syntax for avoiding a CDATA block into a format that is compatible with Groovy's standard logical operators.
Example Usage:
String groovyScript = "true @and false @or true";
String convertedScript = replaceCustomLogicalOperators(groovyScript);
System.out.println(convertedScript); // Output: true && false || true
scriptCode - the input string containing custom logical operatorspublic void setPrecompile(boolean _b)
AbstractScriptsetPrecompile in class AbstractScript_b - The boolean value for the pre-compile flag.public boolean hasSource()
AbstractScripthasSource in class AbstractScriptpublic java.lang.String getLanguage()
AbstractScriptgetLanguage in class AbstractScriptpublic int nextScriptCounter()
public int nextFunctionCounter()
public void initShellInstance(java.lang.ClassLoader cl,
java.util.List<ScriptImport> imports,
java.lang.String baseClassName)
public java.lang.Object getNT(java.lang.String name,
java.lang.Object exValue)
AbstractScriptgetNT in class AbstractScriptname - The name of the variable to retrieve the value of.exValue - This parameter is unused in all implementing classes. Maybe it was once intended to be a default value?public void setNT(java.lang.String name,
java.lang.Object value,
boolean local)
AbstractScriptsetNT in class AbstractScriptname - The name of the variable to set.value - The value of the variable to set.local - A flag indicating if the variable shall have a local scope.public java.lang.Object runAsObjectNT(java.lang.Object nullValue,
int offset,
java.lang.String errorTip)
Object.runAsObjectNT in class AbstractScriptnullValue - currently unused; retained for consistency with abstract super classoffset - line adjustment offset applied to runtime stack traces for error reportingerrorTip - diagnostic hint displayed in error reports when script evaluation failsGroovyScriptException - if script execution throws a runtime exceptionpublic groovy.lang.Script getEvalScript(java.lang.String s)
public groovy.lang.Script getEvalScript(java.lang.String s,
java.lang.String name)
public java.lang.Object evalNT(java.lang.String s,
java.lang.Object nullValue,
int offset,
java.lang.String errorTip)
AbstractScriptevalNT in class AbstractScripts - The source of the script to evaluate.nullValue - The value to return if the evaluation returns null.offset - An integer line offset to use for error reporting.errorTip - A string to use as an error message tip if evaluation fails.public java.lang.Object evalNT(java.lang.String s,
java.lang.Object nullValue,
int offset,
java.lang.String errorTip,
java.util.function.BiFunction typeConverter)
public boolean evalAsBoolNT(java.lang.String s,
boolean nullValue,
int offset,
java.lang.String errorTip)
AbstractScriptevalAsBoolNT in class AbstractScripts - The source of the script to evaluate.nullValue - The value to return if the evaluation returns null.offset - An integer line offset to use for error reporting.errorTip - A string to use as an error message tip if evaluation fails.public java.lang.Object boolConverter(java.lang.Object o,
java.lang.Object nullValue)
public void compileNT(int offset,
java.lang.String errorTip)
AbstractScriptcompileNT in class AbstractScriptoffset - An integer line offset to use for error reporting.errorTip - A string to use as an error message tip if compilation fails.public void close()
AbstractScriptclose in class AbstractScriptpublic void clear()
Delegates to the underlying GroovyScript.HGB binding hierarchy to ensure
bound variables and closure delegates do not leak into long-lived heaps.
clear in class AbstractScriptpublic void createScript()
public ScriptFunctionI createFunction(java.lang.String src, java.lang.String[] parmNames, java.lang.Class[] parmTypes, java.lang.Class returnType)
AbstractScriptcreateFunction in class AbstractScriptsrc - The script source code.parmNames - An array of names for the function's parameters.parmTypes - An array of Class objects representing the types of the function's parameters.returnType - The Class object representing the return type of the function.ScriptFunctionI instance representing the created function.public ScriptFunctionI createFunction(java.lang.String src, java.lang.String[] parmNames, java.lang.Class[] parmTypes, java.lang.Class returnType, java.lang.String scriptName, java.lang.String functionName)
AbstractScriptcreateFunction in class AbstractScriptsrc - The script source code.parmNames - An array of names for the function's parameters.parmTypes - An array of Class objects representing the types of the function's parameters.returnType - The Class object representing the return type of the function.scriptName - The name of the script, used for debugging and error reporting.functionName - The name of the function.ScriptFunctionI instance representing the created function.public ScriptFunctionI createFunction(java.lang.String src, java.lang.String[] parmNames, java.lang.Class[] parmTypes, java.lang.Class returnType, java.lang.String scriptName, java.lang.String functionName, int offset)
AbstractScriptcreateFunction in class AbstractScriptsrc - The script source code.parmNames - An array of names for the function's parameters.parmTypes - An array of Class objects representing the types of the function's parameters.returnType - The Class object representing the return type of the function.scriptName - The name of the script, used for debugging and error reporting.functionName - The name of the function.offset - An integer line offset to use for error reporting.ScriptFunctionI instance representing the created function.public ScriptFunctionI createFunction(java.lang.String src, java.lang.String[] parmNames, java.lang.Class[] parmTypes, java.lang.Class returnType, java.lang.String scriptName, java.lang.String functionName, int offset, java.lang.Object delegate)
AbstractScriptcreateFunction in class AbstractScriptsrc - The script source code.parmNames - An array of names for the function's parameters.parmTypes - An array of Class objects representing the types of the function's parameters.returnType - The Class object representing the return type of the function.scriptName - The name of the script, used for debugging and error reporting.functionName - The name of the function.offset - An integer line offset to use for error reporting.delegate - The object to which the function's method calls will be delegated.ScriptFunctionI instance representing the created function.public static boolean isActualScript(java.lang.String _str)
throws groovyjarjarantlr.RecognitionException,
groovyjarjarantlr.TokenStreamException
_str - the supposed-to-be-script-source text.groovyjarjarantlr.RecognitionExceptiongroovyjarjarantlr.TokenStreamExceptionpublic static boolean isActualScriptTR(java.lang.String _src)
throws IRuntimeException
_src - the script source, supposed to be valid Groovy script syntax
if not null or empty string.IRuntimeExceptionpublic static boolean isActualScriptTR(java.lang.String _src,
java.lang.String _msg)
throws IRuntimeException
IRuntimeExceptionpublic static boolean isActualScriptNT(java.lang.String _str)
_str - the supposed-to-be-script-source text._errorValue - boolean value that is returned when the parsing of _str
resulted in an error, that is the given text could not be parsed by the
GroovyRecognizer. If a syntactically invalid script is seen as "actual
script" will depend on where this method is called and so is configurable
via this value. Defaults to false._logException - if true, parsing (and other) exceptions during the
check will produce a message in the log; if false (the default) they will
not produce any output.public static boolean isActualScriptNT(java.lang.String _str,
boolean _errorValue)
public static boolean isActualScriptNT(java.lang.String _str,
boolean _errorValue,
boolean _logException)
public boolean asBool(java.lang.Object o,
boolean nullValue)
AbstractScriptasBool in class AbstractScripto - The Object to convert.nullValue - The value to return if the passed object is null.public static boolean asBoolStatic(java.lang.Object o,
boolean nullValue)
public static boolean isValidVarName(java.lang.Object o)
o - the object to testpublic static boolean compilesToSame(java.lang.String sourceA,
java.lang.String sourceB)
public java.lang.String getSource()
Provides scoped variable management supporting parent inheritance, thread isolation, and explicit cleanup mechanics for Groovy executions.
getSource in class AbstractScriptpublic void setSource(java.lang.String $11)
AbstractScriptsetSource in class AbstractScript$11 - The new source code as a String.public int getLineOffset()
public void setLineOffset(int $12)
AbstractScriptsetLineOffset in class AbstractScript$12 - The line offset.public GroovyScript getParent()
public void setParent(GroovyScript $13)
public groovy.lang.GroovyShell getShell()
public void setShell(groovy.lang.GroovyShell $14)
public org.codehaus.groovy.control.CompilerConfiguration getCompilerConf()
public void setCompilerConf(org.codehaus.groovy.control.CompilerConfiguration $15)
public GroovyScript.HGB getBinding()
public void setBinding(GroovyScript.HGB $16)
Copyright © 2000-2026 OAshi S.à r.l. All Rights Reserved.