Quantcast

Can a plugin use an application level class?

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can a plugin use an application level class?

Roshan Dawrani
Hi,

Can a Grails plugin access an application level class? I don't want to use the class using its string name.

Thanks.

--
Roshan
Blog: http://roshandawrani.wordpress.com/
Twitter: @roshandawrani
Skype: roshandawrani

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

Re: Can a plugin use an application level class?

Graeme Rocher-4
Administrator
No. The only way is via dynamic class loading

Cheers

On Tue, Mar 1, 2011 at 4:34 PM, Roshan Dawrani <[hidden email]> wrote:

> Hi,
> Can a Grails plugin access an application level class? I don't want to use
> the class using its string name.
> Thanks.
> --
> Roshan
> Blog: http://roshandawrani.wordpress.com/
> Twitter: @roshandawrani
> Skype: roshandawrani
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

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

    http://xircles.codehaus.org/manage_email


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

Re: Can a plugin use an application level class?

johnrellis
Or refactor that class into another plugin :)  

On Tue, Mar 1, 2011 at 4:10 PM, Graeme Rocher <[hidden email]> wrote:
No. The only way is via dynamic class loading

Cheers

On Tue, Mar 1, 2011 at 4:34 PM, Roshan Dawrani <[hidden email]> wrote:
> Hi,
> Can a Grails plugin access an application level class? I don't want to use
> the class using its string name.
> Thanks.
> --
> Roshan
> Blog: http://roshandawrani.wordpress.com/
> Twitter: @roshandawrani
> Skype: roshandawrani
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

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

   http://xircles.codehaus.org/manage_email





--
John Rellis
@johnrellis

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

Re: Can a plugin use an application level class?

Roshan Dawrani
On Wed, Mar 2, 2011 at 2:59 PM, John Rellis <[hidden email]> wrote:
Or refactor that class into another plugin :)  

I can't. 

I wanted to access an app level class from my plugin that in-turn touches a lot of other app classes. If I refactored all that into another plugin, all I will be left with will be 2 plug-ins and no app ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can a plugin use an application level class?

johnrellis
Yeap, you would have a thin 'core app' but that approach could work if you were open to trying it.  If you put that class into a plugin, all the other 'app classes' that touch it should be able to see it when you plug it in.

On the other hand, the main reason for plugins is re-usability, you should probably reconsider your design if a plugin depends on an app, there doesn't seem to be any reason to have a plugin if you cannot reuse it in another project. 

Food for thought :)

If you can't alter the structures

On Wed, Mar 2, 2011 at 9:33 AM, Roshan Dawrani <[hidden email]> wrote:
On Wed, Mar 2, 2011 at 2:59 PM, John Rellis <[hidden email]> wrote:
Or refactor that class into another plugin :)  

I can't. 

I wanted to access an app level class from my plugin that in-turn touches a lot of other app classes. If I refactored all that into another plugin, all I will be left with will be 2 plug-ins and no app ;-)



--
John Rellis
@johnrellis

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

Re: Can a plugin use an application level class?

Roshan Dawrani
:-) Thank you.

Let me have a re-think with that then ;-)

On Wed, Mar 2, 2011 at 3:11 PM, John Rellis <[hidden email]> wrote:
Yeap, you would have a thin 'core app' but that approach could work if you were open to trying it.  If you put that class into a plugin, all the other 'app classes' that touch it should be able to see it when you plug it in.

On the other hand, the main reason for plugins is re-usability, you should probably reconsider your design if a plugin depends on an app, there doesn't seem to be any reason to have a plugin if you cannot reuse it in another project. 

Food for thought :)

If you can't alter the structures


On Wed, Mar 2, 2011 at 9:33 AM, Roshan Dawrani <[hidden email]> wrote:
On Wed, Mar 2, 2011 at 2:59 PM, John Rellis <[hidden email]> wrote:
Or refactor that class into another plugin :)  

I can't. 

I wanted to access an app level class from my plugin that in-turn touches a lot of other app classes. If I refactored all that into another plugin, all I will be left with will be 2 plug-ins and no app ;-)



--
John Rellis
@johnrellis


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

Re: Can a plugin use an application level class?

Ian Roberts
In reply to this post by Roshan Dawrani
On 02/03/2011 09:33, Roshan Dawrani wrote:
> I wanted to access an app level class from my plugin that in-turn
> touches a lot of other app classes. If I refactored all that into
> another plugin, all I will be left with will be 2 plug-ins and no app ;-)

That isn't necessarily a bad thing...

Anyway, to answer the original question, you can't make static
references to application classes from a plugin but if the app class you
want to refer to is a Spring bean (a controller, service, etc.) or if
you can at least gather all the accesses that the plugin requires into a
service in your app, then you can should in theory be able to autowire
the app bean into your plugin services and controllers and call methods
on it in the usual way.  You will certainly be able to get the bean out
of the grailsApplication.mainContext dynamically even if autowiring
doesn't work.

i.e. if your app defines a PluginHelperService then in your plugin you
can "def pluginHelperService" and call methods on that.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

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

    http://xircles.codehaus.org/manage_email


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

Re: Can a plugin use an application level class?

Roshan Dawrani
On Wed, Mar 2, 2011 at 3:18 PM, Ian Roberts <[hidden email]> wrote:
On 02/03/2011 09:33, Roshan Dawrani wrote:
> I wanted to access an app level class from my plugin that in-turn
> touches a lot of other app classes. If I refactored all that into
> another plugin, all I will be left with will be 2 plug-ins and no app ;-)

That isn't necessarily a bad thing...

Anyway, to answer the original question, you can't make static
references to application classes from a plugin but if the app class you
want to refer to is a Spring bean (a controller, service, etc.) or if
you can at least gather all the accesses that the plugin requires into a
service in your app, then you can should in theory be able to autowire
the app bean into your plugin services and controllers and call methods
on it in the usual way.

Thanks Ian. That's exactly the way I am going ahead. I am already using some app beans in my plug-in and I will introduce one more for this purpose.

I was just wondering if there was some way I could make static references.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can a plugin use an application level class?

johnrellis
Ian,

Nice idea, I'll check that out :)

John

On Wed, Mar 2, 2011 at 9:53 AM, Roshan Dawrani <[hidden email]> wrote:
On Wed, Mar 2, 2011 at 3:18 PM, Ian Roberts <[hidden email]> wrote:
On 02/03/2011 09:33, Roshan Dawrani wrote:
> I wanted to access an app level class from my plugin that in-turn
> touches a lot of other app classes. If I refactored all that into
> another plugin, all I will be left with will be 2 plug-ins and no app ;-)

That isn't necessarily a bad thing...

Anyway, to answer the original question, you can't make static
references to application classes from a plugin but if the app class you
want to refer to is a Spring bean (a controller, service, etc.) or if
you can at least gather all the accesses that the plugin requires into a
service in your app, then you can should in theory be able to autowire
the app bean into your plugin services and controllers and call methods
on it in the usual way.

Thanks Ian. That's exactly the way I am going ahead. I am already using some app beans in my plug-in and I will introduce one more for this purpose.

I was just wondering if there was some way I could make static references.



--
John Rellis
@johnrellis

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

Re: Can a plugin use an application level class?

johnrellis
Roshan,

Is it safe to say then you are only using the plugin to achieve modularity??

Also, are you accessing services in the plugin that are created in the main app??

John

On Wed, Mar 2, 2011 at 10:28 AM, John Rellis <[hidden email]> wrote:
Ian,

Nice idea, I'll check that out :)

John


On Wed, Mar 2, 2011 at 9:53 AM, Roshan Dawrani <[hidden email]> wrote:
On Wed, Mar 2, 2011 at 3:18 PM, Ian Roberts <[hidden email]> wrote:
On 02/03/2011 09:33, Roshan Dawrani wrote:
> I wanted to access an app level class from my plugin that in-turn
> touches a lot of other app classes. If I refactored all that into
> another plugin, all I will be left with will be 2 plug-ins and no app ;-)

That isn't necessarily a bad thing...

Anyway, to answer the original question, you can't make static
references to application classes from a plugin but if the app class you
want to refer to is a Spring bean (a controller, service, etc.) or if
you can at least gather all the accesses that the plugin requires into a
service in your app, then you can should in theory be able to autowire
the app bean into your plugin services and controllers and call methods
on it in the usual way.

Thanks Ian. That's exactly the way I am going ahead. I am already using some app beans in my plug-in and I will introduce one more for this purpose.

I was just wondering if there was some way I could make static references.



--
John Rellis
@johnrellis




--
John Rellis
@johnrellis

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

Re: Can a plugin use an application level class?

Roshan Dawrani
On Wed, Mar 2, 2011 at 4:03 PM, John Rellis <[hidden email]> wrote:
Roshan,

Is it safe to say then you are only using the plugin to achieve modularity??

Yes, John. To achieve modularity and help me cut down heavily on the boilerplate code that I was otherwise having to write within the app. The idea at this point is not to make it perfectly re-usable.
 

Also, are you accessing services in the plugin that are created in the main app??

Not services really, I am accessing some other beans right now. So that's how I will do it for this other class also that I wanted to access and cut down on some more boilerplate code that I currently have.

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

Re: Can a plugin use an application level class?

Graeme Rocher-4
Administrator
Actually having thought about this there is one way

If you define the class that your plugin depends on in your plugin and
also in your application then the version in your application will
override the version in your plugin

The version if your plugin could just be a stub so to speak

Cheers

On Wed, Mar 2, 2011 at 11:41 AM, Roshan Dawrani <[hidden email]> wrote:

> On Wed, Mar 2, 2011 at 4:03 PM, John Rellis <[hidden email]> wrote:
>>
>> Roshan,
>> Is it safe to say then you are only using the plugin to achieve
>> modularity??
>
> Yes, John. To achieve modularity and help me cut down heavily on the
> boilerplate code that I was otherwise having to write within the app. The
> idea at this point is not to make it perfectly re-usable.
>
>>
>> Also, are you accessing services in the plugin that are created in the
>> main app??
>
> Not services really, I am accessing some other beans right now. So that's
> how I will do it for this other class also that I wanted to access and cut
> down on some more boilerplate code that I currently have.
> Thanks.



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

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

    http://xircles.codehaus.org/manage_email


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

Re: Can a plugin use an application level class?

Roshan Dawrani
Thank you, Graeme. I will try the trick just to be aware of it,  but I think I am more comfortable going down the spring bean way.

I already did that to avoid some boilerplate code from a number of domain classes, so the purpose I had is solved.

I don't want to depend on a "trick", unless there is absolutely no way out.

---------------------------------------------------
Sent from BlackBerry

-----Original Message-----
From: Graeme Rocher <[hidden email]>
Sender: [hidden email]
Date: Thu, 3 Mar 2011 15:38:15
To: <[hidden email]>
Reply-to: [hidden email]
Subject: Re: [grails-user] Can a plugin use an application level class?
Actually having thought about this there is one way

If you define the class that your plugin depends on in your plugin and
also in your application then the version in your application will
override the version in your plugin

The version if your plugin could just be a stub so to speak

Cheers

On Wed, Mar 2, 2011 at 11:41 AM, Roshan Dawrani <[hidden email]> wrote:

> On Wed, Mar 2, 2011 at 4:03 PM, John Rellis <[hidden email]> wrote:
>>
>> Roshan,
>> Is it safe to say then you are only using the plugin to achieve
>> modularity??
>
> Yes, John. To achieve modularity and help me cut down heavily on the
> boilerplate code that I was otherwise having to write within the app. The
> idea at this point is not to make it perfectly re-usable.
>
>>
>> Also, are you accessing services in the plugin that are created in the
>> main app??
>
> Not services really, I am accessing some other beans right now. So that's
> how I will do it for this other class also that I wanted to access and cut
> down on some more boilerplate code that I currently have.
> Thanks.



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

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

    http://xircles.codehaus.org/manage_email


Loading...