Alexei,
I don't know how much you know about Groovy, and I am no expert, but I
thought I would put together a quick example.
Here is an example where I have a very simple class with one method in a
'plugin' in which I modify the behavior of the meth() method.
I don't guarantee that any of this is done the best way, as I said, I am
no Groovy expert, but it is a quick example of how flexible Groovy is
and how the behavior of a class can be modified.
// Plugin code
class A {
def meth() {
println "original meth method"
}
}
// code using plugin before modification
new A().meth() // prints 'original meth method'
// My plugin modification code
A.metaClass.oldMeth = A.getMethod('meth')
A.metaClass.meth = {
println "new meth method"
oldMeth.invoke(delegate, null)
}
// code using plugin after modification
new A().meth() // prints 'new meth method' and 'original meth method'
On Sun, 2009-07-05 at 10:07 -0700, altosz wrote:
> So I should create my own plugin which is loaded after the original plugin
> and there override the functionality I need?
>
> But still is it possible to override the functionality of the plugins not
> messing with other plugins? Just in the application structure. And if it is
> ok I should better create a patch to the plugin then issue another one.
>
>
>
> nycsailor wrote:
> >
> > Is it possible with what you want to do, that you can create a plugin
> > that modifies the other plugin through MetaProgramming. Groovy is very
> > flexible when it comes to modifying objects and classes and grails
> > allows you to specify plugins that need to be loaded before yours.
> >
> > I'm not sure what you want to do, but this might be the easiest.
> >
> > On Sun, 2009-07-05 at 09:36 -0700, altosz wrote:
> >> Good day, Grails and plugin developers,
> >>
> >> I've encountered the following question when developing an app. I have a
> >> plugin and would like to override (expand) it functionality. How should
> >> it
> >> be done?
> >>
> >> 1. Is it possible to create the same class in app plugin folder? Whould
> >> it
> >> override the same class of the plugin?
> >> 2. Or the only way is to modify plugin code?
> >>
> >> --
> >> Regards,
> >> Alexei
> >
> >
> > ---------------------------------------------------------------------
> > 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