Package adams.core.scripting
Class Groovy
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.scripting.Groovy
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Serializable
public class Groovy extends LoggingObject
A helper class for Groovy.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
CLASS_GROOVYCLASSLOADER
the classname of the Groovy classloader.protected Object
m_ClassLoader
the classloader.protected boolean
m_Present
whether the Groovy classes are in the Classpath.protected static Groovy
m_Singleton
the singleton.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Groovy()
default constructor, tries to instantiate a Groovy classloader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
getClassLoader()
returns the currently used Groovy classloader.static Groovy
getSingleton()
Returns the singleton instance.Object
invoke(Object o, String methodName, Class[] paramClasses, Object[] paramValues)
executes the specified method and returns the result, if any.Object
invoke(String methodName, Class[] paramClasses, Object[] paramValues)
executes the specified method on the current interpreter and returns the result, if any.boolean
isPresent()
returns whether the Groovy classes are present or not, i.e.Object[]
loadScriptObject(Class cls, PlaceholderFile scriptFile, GroovyScript inlineScript, String scriptOptions, Variables vars)
Loads the scripts object and sets its options.static void
main(String[] args)
If no arguments are given, it just prints the presence of the Groovy classes, otherwise it expects a Groovy filename to execute.Object
newClassLoader()
initializes and returns a Groovy Interpreter.Object
newInstance(File file, Class template)
loads the module and returns a new instance of it as instance of the provided Java class template.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
CLASS_GROOVYCLASSLOADER
public static final String CLASS_GROOVYCLASSLOADER
the classname of the Groovy classloader.- See Also:
- Constant Field Values
-
m_Present
protected boolean m_Present
whether the Groovy classes are in the Classpath.
-
m_ClassLoader
protected Object m_ClassLoader
the classloader.
-
m_Singleton
protected static Groovy m_Singleton
the singleton.
-
-
Method Detail
-
getClassLoader
public Object getClassLoader()
returns the currently used Groovy classloader.- Returns:
- the classloader, can be null
-
invoke
public Object invoke(String methodName, Class[] paramClasses, Object[] paramValues)
executes the specified method on the current interpreter and returns the result, if any.- Parameters:
methodName
- the name of the methodparamClasses
- the classes of the parametersparamValues
- the values of the parameters- Returns:
- the return value of the method, if any (in that case null)
-
isPresent
public boolean isPresent()
returns whether the Groovy classes are present or not, i.e. whether the classes are in the classpath or not- Returns:
- whether the Groovy classes are available
-
newClassLoader
public Object newClassLoader()
initializes and returns a Groovy Interpreter.- Returns:
- the interpreter or null if Groovy classes not present
-
newInstance
public Object newInstance(File file, Class template)
loads the module and returns a new instance of it as instance of the provided Java class template.- Parameters:
file
- the Groovy module filetemplate
- the template for the returned Java object- Returns:
- the Groovy object
-
invoke
public Object invoke(Object o, String methodName, Class[] paramClasses, Object[] paramValues)
executes the specified method and returns the result, if any.- Parameters:
o
- the object the method should be called from, e.g., a Groovy InterpretermethodName
- the name of the methodparamClasses
- the classes of the parametersparamValues
- the values of the parameters- Returns:
- the return value of the method, if any (in that case null)
-
loadScriptObject
public Object[] loadScriptObject(Class cls, PlaceholderFile scriptFile, GroovyScript inlineScript, String scriptOptions, Variables vars)
Loads the scripts object and sets its options.- Parameters:
cls
- the class to instantiatescriptFile
- the external file to loadinlineScript
- the inline script to load if external file points to a directoryscriptOptions
- the options to setvars
- the variables to use for expanding- Returns:
- element 0: error messsage (null if ok), element 1: script object
-
getSingleton
public static Groovy getSingleton()
Returns the singleton instance.- Returns:
- the singleton
-
main
public static void main(String[] args)
If no arguments are given, it just prints the presence of the Groovy classes, otherwise it expects a Groovy filename to execute.- Parameters:
args
- commandline arguments
-
-