Class GroovyUtil

  • public final class GroovyUtil
    extends java.lang.Object
    Groovy Utilities.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object eval​(java.lang.String expression, java.util.Map<java.lang.String,​java.lang.Object> context)
      Evaluate a Groovy condition or expression
      static Binding getBinding​(java.util.Map<java.lang.String,​java.lang.Object> context)  
      static Binding getBinding​(java.util.Map<java.lang.String,​java.lang.Object> context, java.lang.String expression)
      Returns a Binding instance initialized with the variables contained in context.
      static java.lang.Class<?> getScriptClassFromLocation​(java.lang.String location)  
      static java.lang.Class<?> parseClass​(java.lang.String text)  
      static java.lang.Object runScriptAtLocation​(java.lang.String location, java.lang.String methodName, java.util.Map<java.lang.String,​java.lang.Object> context)
      Runs a Groovy script with a context argument.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getBinding

        public static Binding getBinding​(java.util.Map<java.lang.String,​java.lang.Object> context,
                                         java.lang.String expression)
        Returns a Binding instance initialized with the variables contained in context. If context is null, an empty Binding is returned.

        The expression is parsed to initiate non existing variable in Binding to null for GroovyShell evaluation.

        The context Map is added to the Binding 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.

        context - A Map containing initial variables
        A Binding instance
      • getBinding

        public static Binding getBinding​(java.util.Map<java.lang.String,​java.lang.Object> context)
      • getScriptClassFromLocation

        public static java.lang.Class<?> getScriptClassFromLocation​(java.lang.String location)
                                                             throws GeneralException
      • parseClass

        public static java.lang.Class<?> parseClass​(java.lang.String text)
      • runScriptAtLocation

        public static java.lang.Object runScriptAtLocation​(java.lang.String location,
                                                           java.lang.String methodName,
                                                           java.util.Map<java.lang.String,​java.lang.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.

        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
        the invocation result
        GeneralException - when the script is not properly located