Class GroovyUtil

java.lang.Object
org.apache.ofbiz.base.util.GroovyUtil

public final class GroovyUtil extends Object
Groovy Utilities.
  • Method Details

    • eval

      public static Object eval(String expression, Map<String,Object> context) throws CompilationFailedException
      Evaluate a Groovy condition or expression
      Parameters:
      expression - The expression to evaluate
      context - The context to use in evaluation (re-written)
      Returns:
      Object The result of the evaluation
      Throws:
      CompilationFailedException
      See Also:
    • getBinding

      public static Binding getBinding(Map<String,Object> context)
    • getScriptClassFromLocation

      public static Class<?> getScriptClassFromLocation(String location) throws GeneralException
      Throws:
      GeneralException
    • parseClass

      public static Class<?> parseClass(String text) throws IOException
      Parses a Groovy class from a text.
      Parameters:
      text - as flexible string to parse
      Returns:
      the corresponding class object
      Throws:
      IOException - when parsing fails
    • runScriptAtLocation

      public static Object runScriptAtLocation(String location, String methodName, Map<String,Object> context) throws GeneralException
      Runs 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 file
      methodName - the name of the method inside the script to be run, if it is null consider the script as stand-alone
      context - 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