| Method from groovy.lang.Script Detail: |
public Object evaluate(String expression) throws CompilationFailedException {
GroovyShell shell = new GroovyShell(getClass().getClassLoader(), binding);
return shell.evaluate(expression);
}
A helper method to allow the dynamic evaluation of groovy expressions using this
scripts binding as the variable scope |
public Object evaluate(File file) throws CompilationFailedException, IOException {
GroovyShell shell = new GroovyShell(getClass().getClassLoader(), binding);
return shell.evaluate(file);
}
A helper method to allow the dynamic evaluation of groovy expressions using this
scripts binding as the variable scope |
public Binding getBinding() {
return binding;
}
|
public Object getProperty(String property) {
try {
return binding.getVariable(property);
} catch (MissingPropertyException e) {
return super.getProperty(property);
}
}
|
public Object invokeMethod(String name,
Object args) {
try {
return super.invokeMethod(name, args);
}
// if the method was not found in the current scope (the script's methods)
// let's try to see if there's a method closure with the same name in the binding
catch (MissingMethodException mme) {
try {
if (name.equals(mme.getMethod())) {
Object boundClosure = binding.getVariable(name);
if (boundClosure != null && boundClosure instanceof Closure) {
return ((Closure) boundClosure).call((Object[])args);
} else {
throw mme;
}
} else {
throw mme;
}
} catch (MissingPropertyException mpe) {
throw mme;
}
}
}
Invoke a method (or closure in the binding) defined. |
public void print(Object value) {
Object object;
try {
object = getProperty("out");
} catch (MissingPropertyException e) {
DefaultGroovyMethods.print(System.out,value);
return;
}
InvokerHelper.invokeMethod(object, "print", new Object[]{value});
}
Prints the value to the current 'out' variable which should be a PrintWriter
or at least have a print() method defined on it.
If there is no 'out' property then print to standard out. |
public void println() {
Object object;
try {
object = getProperty("out");
} catch (MissingPropertyException e) {
System.out.println();
return;
}
InvokerHelper.invokeMethod(object, "println", ArgumentListExpression.EMPTY_ARRAY);
}
Prints a newline to the current 'out' variable which should be a PrintWriter
or at least have a println() method defined on it.
If there is no 'out' property then print to standard out. |
public void println(Object value) {
Object object;
try {
object = getProperty("out");
} catch (MissingPropertyException e) {
DefaultGroovyMethods.println(System.out,value);
return;
}
InvokerHelper.invokeMethod(object, "println", new Object[]{value});
}
Prints the value and a newline to the current 'out' variable which should be a PrintWriter
or at least have a println() method defined on it.
If there is no 'out' property then print to standard out. |
abstract public Object run()
The main instance method of a script which has variables in scope
as defined by the current Binding instance. |
public void run(File file,
String[] arguments) throws CompilationFailedException, IOException {
GroovyShell shell = new GroovyShell(getClass().getClassLoader(), binding);
shell.run(file, arguments);
}
A helper method to allow scripts to be run taking command line arguments |
public void setBinding(Binding binding) {
this.binding = binding;
}
|
public void setProperty(String property,
Object newValue) {
if ("binding".equals(property))
setBinding((Binding) newValue);
else if("metaClass".equals(property))
setMetaClass((MetaClass)newValue);
else
binding.setVariable(property, newValue);
}
|