is binding available when running groovy using the class loader method?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

is binding available when running groovy using the class loader method?

Resolve Test
Are the groovy.lang.Binding still available if you use the class loader method to run groovy scripts instead of the GroovyShell?
i.e.
Binding binding = new Binding();

binding.setVariable("foo", new Integer(2));

ClassLoader
parent = getClass().getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
Class groovyClass = loader.parseClass(new File( "src/test/groovy/script/HelloWorld.groovy"));

// lets call some method on an instance
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
Object[] args = {};
groovyObject.invokeMethod("run", args);


Thanks

Duke
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: is binding available when running groovy using the class loader method?

tugwilson

On 8 May 2006, at 20:27, Duke Tantiprasut wrote:

> Are the groovy.lang.Binding still available if you use the class  
> loader method to run groovy scripts instead of the GroovyShell?
> i.e.
> Binding binding = new Binding();
> binding.setVariable("foo", new Integer(2));
>
> ClassLoader parent = getClass().getClassLoader();
> GroovyClassLoader loader = new GroovyClassLoader(parent);
> Class groovyClass = loader.parseClass(new File( "src/test/groovy/
> script/HelloWorld.groovy"));
>
> // lets call some method on an instance
> GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
> Object[] args = {};
> groovyObject.invokeMethod("run", args);
>

Yes but you have to tell the script to use the binding by calling  
setBinding before calling run.


John Wilson
The Wilson Partnership
web http://www.wilson.co.uk
blog http://eek.ook.org


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: is binding available when running groovy using the class loader method?

Resolve Test
Thanks John.

On 5/8/06, John Wilson <[hidden email]> wrote:

On 8 May 2006, at 20:27, Duke Tantiprasut wrote:

> Are the groovy.lang.Binding still available if you use the class
> loader method to run groovy scripts instead of the GroovyShell?
> i.e.
> Binding binding = new Binding();
> binding.setVariable("foo", new Integer(2));
>
> ClassLoader parent = getClass().getClassLoader();
> GroovyClassLoader loader = new GroovyClassLoader(parent);
> Class groovyClass = loader.parseClass(new File( "src/test/groovy/
> script/HelloWorld.groovy"));
>
> // lets call some method on an instance
> GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance ();
> Object[] args = {};
> groovyObject.invokeMethod("run", args);
>

Yes but you have to tell the script to use the binding by calling
setBinding before calling run.


John Wilson
The Wilson Partnership
web http://www.wilson.co.uk
blog http://eek.ook.org



Loading...