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) |
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 _initialvars) |
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map _initialvars,
java.util.List<ScriptImport> _defaultImports) |
GroovyScript(java.lang.String _source,
boolean _precompile,
GroovyScript _parent,
java.lang.ClassLoader _cl,
java.util.Map _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 _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 _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()
Frees all variables of this script after execution to prevent them
from being held "forever" and causing memory leaks.
|
void |
close()
Closes this script instance, freeing up resources.
|
void |
compileNT(int _lineOffset,
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) |
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 _lineOffset)
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 _lineOffset,
java.lang.Object _delegate)
Creates a function from a script source string.
|
void |
createScript() |
boolean |
evalAsBoolNT(java.lang.String s,
boolean nullValue,
int _lineOffset,
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 _lineOffset,
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 _lineOffset,
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.Script |
getScript() |
groovy.lang.GroovyShell |
getShell() |
java.lang.String |
getSource()
Returns the source code of this script.
|
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 _lineOffset,
java.lang.String errorTip)
This method is called *NT ("no throw") but actually does throw a
GroovyScriptException should the
script throw an exception while running. |
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 |
setScript(groovy.lang.Script $17) |
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, setNT
public GroovyScript(java.lang.String _source, boolean _precompile)
public 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 _initialvars)
public GroovyScript(java.lang.String _source, boolean _precompile, GroovyScript _parent, java.lang.ClassLoader _cl, java.util.Map _initialvars, java.util.List<ScriptImport> _defaultImports)
public GroovyScript(java.lang.String _source, boolean _precompile, GroovyScript _parent, java.lang.ClassLoader _cl, java.util.Map _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 _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 _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)
AbstractScript
setPrecompile
in class AbstractScript
_b
- The boolean value for the pre-compile flag.public boolean hasSource()
AbstractScript
hasSource
in class AbstractScript
public java.lang.String getLanguage()
AbstractScript
getLanguage
in class AbstractScript
public 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)
AbstractScript
getNT
in class AbstractScript
name
- 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)
AbstractScript
setNT
in class AbstractScript
name
- 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 _lineOffset, java.lang.String errorTip)
GroovyScriptException
should the
script throw an exception while running.runAsObjectNT
in class AbstractScript
nullValue
- The value to return if the script returns null._lineOffset
- An integer line offset to use for error reporting.errorTip
- A string to use as an error message tip if compilation fails.GroovyScriptException
- if the script throws an exception while runningpublic 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 _lineOffset, java.lang.String errorTip)
AbstractScript
evalNT
in class AbstractScript
s
- The source of the script to evaluate.nullValue
- The value to return if the evaluation returns null._lineOffset
- 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 _lineOffset, java.lang.String errorTip, java.util.function.BiFunction typeConverter)
public boolean evalAsBoolNT(java.lang.String s, boolean nullValue, int _lineOffset, java.lang.String errorTip)
AbstractScript
evalAsBoolNT
in class AbstractScript
s
- The source of the script to evaluate.nullValue
- The value to return if the evaluation returns null._lineOffset
- 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 _lineOffset, java.lang.String errorTip)
AbstractScript
compileNT
in class AbstractScript
_lineOffset
- 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()
AbstractScript
close
in class AbstractScript
public void clear()
AbstractScript
clear
in class AbstractScript
public void createScript()
public ScriptFunctionI createFunction(java.lang.String src, java.lang.String[] parmNames, java.lang.Class[] parmTypes, java.lang.Class returnType)
AbstractScript
createFunction
in class AbstractScript
src
- 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)
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)
AbstractScript
createFunction
in class AbstractScript
src
- 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 _lineOffset)
AbstractScript
createFunction
in class AbstractScript
src
- 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._lineOffset
- 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 _lineOffset, java.lang.Object _delegate)
AbstractScript
createFunction
in class AbstractScript
src
- 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._lineOffset
- 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.RecognitionException
groovyjarjarantlr.TokenStreamException
public 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.IRuntimeException
public static boolean isActualScriptTR(java.lang.String _src, java.lang.String _msg) throws IRuntimeException
IRuntimeException
public 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)
AbstractScript
asBool
in class AbstractScript
o
- 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()
AbstractScript
getSource
in class AbstractScript
public void setSource(java.lang.String $11)
AbstractScript
setSource
in class AbstractScript
$11
- The new source code as a String.public int getLineOffset()
public void setLineOffset(int $12)
AbstractScript
setLineOffset
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)
public groovy.lang.Script getScript()
public void setScript(groovy.lang.Script $17)
Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.