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) |
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 script has been executed to prevent
them from being held "forever" even if they are no longer used.
|
void |
close() |
void |
compileNT(int _lineOffset,
java.lang.String errorTip) |
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) |
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) |
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) |
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) |
void |
createScript() |
boolean |
evalAsBoolNT(java.lang.String s,
boolean nullValue,
int _lineOffset,
java.lang.String errorTip) |
java.lang.Object |
evalNT(java.lang.String s,
java.lang.Object nullValue,
int _lineOffset,
java.lang.String errorTip) |
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() |
int |
getLineOffset() |
java.lang.Object |
getNT(java.lang.String name,
java.lang.Object exValue) |
GroovyScript |
getParent() |
groovy.lang.Script |
getScript() |
groovy.lang.GroovyShell |
getShell() |
java.lang.String |
getSource() |
boolean |
hasSource() |
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) |
void |
setNT(java.lang.String name,
java.lang.Object value,
boolean local) |
void |
setParent(GroovyScript $13) |
void |
setPrecompile(boolean _b) |
void |
setScript(groovy.lang.Script $17) |
void |
setShell(groovy.lang.GroovyShell $14) |
void |
setSource(java.lang.String $11) |
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)
setPrecompile
in class AbstractScript
public boolean hasSource()
hasSource
in class AbstractScript
public java.lang.String getLanguage()
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)
getNT
in class AbstractScript
public void setNT(java.lang.String name, java.lang.Object value, boolean local)
setNT
in class AbstractScript
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
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)
evalNT
in class AbstractScript
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)
evalAsBoolNT
in class AbstractScript
public java.lang.Object boolConverter(java.lang.Object o, java.lang.Object nullValue)
public void compileNT(int _lineOffset, java.lang.String errorTip)
compileNT
in class AbstractScript
public void close()
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)
createFunction
in class AbstractScript
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)
createFunction
in class AbstractScript
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)
createFunction
in class AbstractScript
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)
createFunction
in class AbstractScript
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)
asBool
in class AbstractScript
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()
getSource
in class AbstractScript
public void setSource(java.lang.String $11)
setSource
in class AbstractScript
public int getLineOffset()
public void setLineOffset(int $12)
setLineOffset
in class AbstractScript
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.