Package org.apache.ofbiz.base.util
Class GroovyUtil
java.lang.Object
org.apache.ofbiz.base.util.GroovyUtil
Groovy Utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Evaluate a Groovy condition or expressionstatic Binding
getBinding
(Map<String, Object> context) static Binding
getBinding
(Map<String, Object> context, String expression) Returns aBinding
instance initialized with the variables contained incontext
.static Class<?>
getScriptClassFromLocation
(String location) static Class<?>
parseClass
(String text) static Object
Runs a Groovy script with a context argument.
-
Method Details
-
eval
public static Object eval(String expression, Map<String, Object> context) throws CompilationFailedExceptionEvaluate a Groovy condition or expression- Parameters:
expression
- The expression to evaluatecontext
- The context to use in evaluation (re-written)- Returns:
- Object The result of the evaluation
- Throws:
CompilationFailedException
- See Also:
-
getBinding
Returns aBinding
instance initialized with the variables contained incontext
. Ifcontext
isnull
, an emptyBinding
is returned.The expression is parsed to initiate non existing variable in
Binding
to null for GroovyShell evaluation.The
context Map
is added to theBinding
as a variable called "context" so that variables can be passed back to the caller. Any variables that are created in the script are lost when the script ends unless they are copied to the "context"Map
.- Parameters:
context
- AMap
containing initial variables- Returns:
- A
Binding
instance
-
getBinding
-
getScriptClassFromLocation
- Throws:
GeneralException
-
parseClass
- Throws:
IOException
-
runScriptAtLocation
public static Object runScriptAtLocation(String location, String methodName, Map<String, Object> context) throws GeneralExceptionRuns a Groovy script with a context argument.A Groovy script can be either a stand-alone script or a method embedded in a script.
- Parameters:
location
- the location of the script filemethodName
- the name of the method inside the script to be run, if it isnull
consider the script as stand-alonecontext
- the context of execution which is in the case of a method inside a script passed as an argument- Returns:
- the invocation result
- Throws:
GeneralException
- when the script is not properly located
-