groovy.util.ResourceConnector

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

groovy.util.ResourceConnector

Dirk.Dinger

Just reading Direk Königs latest Article in the "Java Magazin". He says
there that it is possible to easily make groovy work together with other
implementations of the
ResourceConnector interface to for example read the script code from a
database.

Could anyone of you give me an example of how that would look like. How
would the GroovyClassLoader have to be used with such a custom
ResourceConnector ?

Regards,
Dirk Dinger
Software Architect
InterComponentWare AG   Ph : +49 (6227) 385 - 144
Otto-Hahn-Straße 3             Fax: +49 (6227) 385 - 199
69190 Walldorf
Germany


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: groovy.util.ResourceConnector

Guillaume Laforge
Administrator
Hmm, ResourceConnector? or GroovyResourceLoader?
Ah right, there's also ResourceConnector.
I guess we should use the same interface there rather than having two
different interfaces for two different Groovy integration mechanism.

If you're using the GroovyScriptEngine, you can pass your own
implementation of ResourceConnector in the constructor:

new GroovyScriptEngine(new MyResourceConnectorImpl());

But if you're using the GroovyClassLoader for integrating your Groovy
code in your application, you'll have to use the GroovyResourceLoader:

GroovyClassLoader gcl = new GroovyClassLoader();
gcl.setResourceLoader(new MyResourceLoaderImpl());

You can have a look at the JavaDocs for these classes online.

ResourceConnector in combination with GroovyScriptEngine:
http://groovy.codehaus.org/apidocs/groovy/util/ResourceConnector.html
http://groovy.codehaus.org/apidocs/groovy/util/GroovyScriptEngine.html#GroovyScriptEngine(groovy.util.ResourceConnector)

GroovyResourceLoader in combination with GroovyClassLoader:
http://groovy.codehaus.org/apidocs/groovy/lang/GroovyResourceLoader.html
http://groovy.codehaus.org/apidocs/groovy/lang/GroovyClassLoader.html#setResourceLoader(groovy.lang.GroovyResourceLoader)

Hope this helps.


On 7/13/06, [hidden email] <[hidden email]> wrote:

>
> Just reading Direk Königs latest Article in the "Java Magazin". He says
> there that it is possible to easily make groovy work together with other
> implementations of the
> ResourceConnector interface to for example read the script code from a
> database.
>
> Could anyone of you give me an example of how that would look like. How
> would the GroovyClassLoader have to be used with such a custom
> ResourceConnector ?
>
> Regards,
> Dirk Dinger
> Software Architect
> InterComponentWare AG Ph : +49 (6227) 385 - 144
> Otto-Hahn-Straße 3 Fax: +49 (6227) 385 - 199
> 69190 Walldorf
> Germany
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: groovy.util.ResourceConnector

Dirk.Dinger

I'm a little confused about the GroovyResourceLoader interface.

Currently I am storing the script code in Database BLOBs, converting them
to strings and doing a

        GroovyClassLoader gcl = new GroovyClassLoader();
        Class clazz = gcl.parseClass(codeFromDB);

Around that, I use a similar caching strategy as the GroovyScriptEngine
does to store the compiled classes.
Reading Dierks article I was wondering if I could simplyfy that by
implementing some Groovy interface.
Actually I need some abstraction to the mechanism obtaining the script
source code, so I would expect
an interface returning some sort of inputstream for example.

Regards,
Dirk


"Guillaume Laforge" <[hidden email]> wrote on 13.07.2006 15:52:55:

> Hmm, ResourceConnector? or GroovyResourceLoader?
> Ah right, there's also ResourceConnector.
> I guess we should use the same interface there rather than having two
> different interfaces for two different Groovy integration mechanism.

> If you're using the GroovyScriptEngine, you can pass your own
> implementation of ResourceConnector in the constructor:

> new GroovyScriptEngine(new MyResourceConnectorImpl());

> But if you're using the GroovyClassLoader for integrating your Groovy
> code in your application, you'll have to use the GroovyResourceLoader:

> GroovyClassLoader gcl = new GroovyClassLoader();
> gcl.setResourceLoader(new MyResourceLoaderImpl());

> You can have a look at the JavaDocs for these classes online.

> ResourceConnector in combination with GroovyScriptEngine:
> http://groovy.codehaus.org/apidocs/groovy/util/ResourceConnector.html
> http://groovy.codehaus.org/apidocs/groovy/util/GroovyScriptEngine.
> html#GroovyScriptEngine(groovy.util.ResourceConnector)

> GroovyResourceLoader in combination with GroovyClassLoader:
> http://groovy.codehaus.org/apidocs/groovy/lang/GroovyResourceLoader.html
> http://groovy.codehaus.org/apidocs/groovy/lang/GroovyClassLoader.
> html#setResourceLoader(groovy.lang.GroovyResourceLoader)

> Hope this helps.

>
> On 7/13/06, [hidden email] <[hidden email]>
wrote:
> >
> > Just reading Direk Königs latest Article in the "Java Magazin". He says
> > there that it is possible to easily make groovy work together with
other

> > implementations of the
> > ResourceConnector interface to for example read the script code from a
> > database.
> >
> > Could anyone of you give me an example of how that would look like. How
> > would the GroovyClassLoader have to be used with such a custom
> > ResourceConnector ?
> >
> > Regards,
> > Dirk Dinger
> > Software Architect
> > InterComponentWare AG Ph : +49 (6227) 385 - 144
> > Otto-Hahn-Straße 3 Fax: +49 (6227) 385 - 199
> > 69190 Walldorf
> > Germany
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >

>
> --
> Guillaume Laforge
> Groovy Project Manager
> http://glaforge.free.fr/blog/groovy

> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:

> http://xircles.codehaus.org/manage_email


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: groovy.util.ResourceConnector

Guillaume Laforge
Administrator
Those two aforementioned interfaces return URLs or URLConnections from
which you can retrieve inputstreams. You can provide your own
overriden URL or URLConnection by just implementing the
getInputStream() & getLastModified() methods.
If you're happy with your database string loading, I guess that's fine too.

On 7/13/06, [hidden email] <[hidden email]> wrote:

>
> I'm a little confused about the GroovyResourceLoader interface.
>
> Currently I am storing the script code in Database BLOBs, converting them
> to strings and doing a
>
>   GroovyClassLoader gcl = new GroovyClassLoader();
>   Class clazz = gcl.parseClass(codeFromDB);
>
> Around that, I use a similar caching strategy as the GroovyScriptEngine
> does to store the compiled classes.
> Reading Dierks article I was wondering if I could simplyfy that by
> implementing some Groovy interface.
> Actually I need some abstraction to the mechanism obtaining the script
> source code, so I would expect
> an interface returning some sort of inputstream for example.
>
> Regards,
> Dirk
>
>
> "Guillaume Laforge" <[hidden email]> wrote on 13.07.2006 15:52:55:
>
> > Hmm, ResourceConnector? or GroovyResourceLoader?
> > Ah right, there's also ResourceConnector.
> > I guess we should use the same interface there rather than having two
> > different interfaces for two different Groovy integration mechanism.
>
> > If you're using the GroovyScriptEngine, you can pass your own
> > implementation of ResourceConnector in the constructor:
>
> > new GroovyScriptEngine(new MyResourceConnectorImpl());
>
> > But if you're using the GroovyClassLoader for integrating your Groovy
> > code in your application, you'll have to use the GroovyResourceLoader:
>
> > GroovyClassLoader gcl = new GroovyClassLoader();
> > gcl.setResourceLoader(new MyResourceLoaderImpl());
>
> > You can have a look at the JavaDocs for these classes online.
>
> > ResourceConnector in combination with GroovyScriptEngine:
> > http://groovy.codehaus.org/apidocs/groovy/util/ResourceConnector.html
> > http://groovy.codehaus.org/apidocs/groovy/util/GroovyScriptEngine.
> > html#GroovyScriptEngine(groovy.util.ResourceConnector)
>
> > GroovyResourceLoader in combination with GroovyClassLoader:
> > http://groovy.codehaus.org/apidocs/groovy/lang/GroovyResourceLoader.html
> > http://groovy.codehaus.org/apidocs/groovy/lang/GroovyClassLoader.
> > html#setResourceLoader(groovy.lang.GroovyResourceLoader)
>
> > Hope this helps.
>
> >
> > On 7/13/06, [hidden email] <[hidden email]>
> wrote:
> > >
> > > Just reading Direk Königs latest Article in the "Java Magazin". He says
> > > there that it is possible to easily make groovy work together with
> other
> > > implementations of the
> > > ResourceConnector interface to for example read the script code from a
> > > database.
> > >
> > > Could anyone of you give me an example of how that would look like. How
> > > would the GroovyClassLoader have to be used with such a custom
> > > ResourceConnector ?
> > >
> > > Regards,
> > > Dirk Dinger
> > > Software Architect
> > > InterComponentWare AG Ph : +49 (6227) 385 - 144
> > > Otto-Hahn-Straße 3 Fax: +49 (6227) 385 - 199
> > > 69190 Walldorf
> > > Germany
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe from this list please visit:
> > >
> > > http://xircles.codehaus.org/manage_email
> > >
> > >
>
> >
> > --
> > Guillaume Laforge
> > Groovy Project Manager
> > http://glaforge.free.fr/blog/groovy
>
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
>
> > http://xircles.codehaus.org/manage_email
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email