You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Felix Meschberger <Fe...@day.com> on 2007/06/29 16:01:35 UTC

Re: svn commit: r551894 - in /felix/trunk/ipojo: core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/ core/src/main/java/org/apache/felix/ipojo/util/ plugin/src/main/java/org/apache/felix/ipojo/plugin/

Hi Clement,

Don't want to step on your toes, but just to be sure: Are you aware, that
Class.getMethods() only returns public methods but no protected methods ?

To get the protected methods of parent classes you have to use
getDeclaredMethods() and walk up the super class chain to find the method
you are looking for.

It just sprang into my eyes, because I also had the same issue once :-)

Regards
Felix

On 6/29/07, clement@apache.org <cl...@apache.org> wrote:
>
> Author: clement
> Date: Fri Jun 29 06:56:49 2007
> New Revision: 551894
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=551894
> Log:
> Improve method invocation for Lifecycle Callbacks. Allow the invocation of
> method from parent classes.(Felix-315).
> <snip>
> ---
> felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
> (original)
> +++
> felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
> Fri Jun 29 06:56:49 2007
> @@ -209,8 +209,31 @@
>
>              }
>          }
> +
> +        if (m_methodObj == null) { //look at parent classes
> +            methods = m_manager.getClazz().getMethods();
> +            for (int i = 0; m_methodObj == null && i < methods.length;
> i++) {
> +                // First check the method name
> +                if (methods[i].getName().equals(m_method)) {
> +                    // Check arguments
> +                    Class[] clazzes = methods[i].getParameterTypes();
> +                    if (clazzes.length == m_args.length) { // Test size
> to avoid useless loop
> +                        boolean ok = true;
> +                        for (int j = 0; ok && j < m_args.length; j++) {
> +                            if (!m_args[j].equals(clazzes[j].getName()))
> {
> +                                ok = false;
> +                            }
> +                        }
> +                        if (ok) {
> +                            m_methodObj = methods[i]; // It is the looked
> method.
> +                        }
> +                    }
> +                }
> +            }
> +        }
> +
> </snip>
>

Re: svn commit: r551894 - in /felix/trunk/ipojo: core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/ core/src/main/java/org/apache/felix/ipojo/util/ plugin/src/main/java/org/apache/felix/ipojo/plugin/

Posted by Felix Meschberger <Fe...@day.com>.
Hi Clement,

Thanks for the clarification (I only read your final Jira posting after
having written this...).

I just was not sure, whether this was intended, as for example SCR defines
any (un)bind and (de)activate methods as public or protected (stipulating to
use protected) and those methods may of course well live in the base class.

Never mind.

Regards
Felix

On 6/29/07, Clement Escoffier <cl...@gmail.com> wrote:
>
> Felix Meschberger a écrit :
> > Hi Clement,
> >
> > Don't want to step on your toes, but just to be sure: Are you aware,
> that
> > Class.getMethods() only returns public methods but no protected methods
> ?
> >
> > To get the protected methods of parent classes you have to use
> > getDeclaredMethods() and walk up the super class chain to find the
> method
> > you are looking for.
> Yes, to avoid this, I look inside the two arrays. I begin to look for
> the Method object inside the array returned by the getDeclaredMethods,
> if not found I look inside the array returned by the getMethods. The
> applied patch allow to invoke private, protected and public method from
> the POJO and public methods from the parent classes.
>
> Regards,
>
> Clement
>
> >
> >
> > On 6/29/07, clement@apache.org <cl...@apache.org> wrote:
> >>
> >> Author: clement
> >> Date: Fri Jun 29 06:56:49 2007
> >> New Revision: 551894
> >>
> >> URL: http://svn.apache.org/viewvc?view=rev&rev=551894
> >> Log:
> >> Improve method invocation for Lifecycle Callbacks. Allow the
> >> invocation of
> >> method from parent classes.(Felix-315).
> >> <snip>
> >> ---
> >>
> felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
> >>
> >> (original)
> >> +++
> >>
> felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
> >>
> >> Fri Jun 29 06:56:49 2007
> >> @@ -209,8 +209,31 @@
> >>
> >>              }
> >>          }
> >> +
> >> +        if (m_methodObj == null) { //look at parent classes
> >> +            methods = m_manager.getClazz().getMethods();
> >> +            for (int i = 0; m_methodObj == null && i < methods.length;
> >> i++) {
> >> +                // First check the method name
> >> +                if (methods[i].getName().equals(m_method)) {
> >> +                    // Check arguments
> >> +                    Class[] clazzes = methods[i].getParameterTypes();
> >> +                    if (clazzes.length == m_args.length) { // Test
> size
> >> to avoid useless loop
> >> +                        boolean ok = true;
> >> +                        for (int j = 0; ok && j < m_args.length; j++)
> {
> >> +                            if
> >> (!m_args[j].equals(clazzes[j].getName()))
> >> {
> >> +                                ok = false;
> >> +                            }
> >> +                        }
> >> +                        if (ok) {
> >> +                            m_methodObj = methods[i]; // It is the
> >> looked
> >> method.
> >> +                        }
> >> +                    }
> >> +                }
> >> +            }
> >> +        }
> >> +
> >> </snip>
> >>
> >
>
>
> --
> Clement Escoffier
> Grenoble University
> LSR - Bat. C
> 220, Rue de la Chimie
> BP 53
> 38041 GRENOBLE CEDEX 9
> 04.76.51.40.24
> http://clement.plop-plop.net
>
>

Re: svn commit: r551894 - in /felix/trunk/ipojo: core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/ core/src/main/java/org/apache/felix/ipojo/util/ plugin/src/main/java/org/apache/felix/ipojo/plugin/

Posted by Clement Escoffier <cl...@gmail.com>.
Felix Meschberger a écrit :
> Hi Clement,
>
> Don't want to step on your toes, but just to be sure: Are you aware, that
> Class.getMethods() only returns public methods but no protected methods ?
>
> To get the protected methods of parent classes you have to use
> getDeclaredMethods() and walk up the super class chain to find the method
> you are looking for.
Yes, to avoid this, I look inside the two arrays. I begin to look for 
the Method object inside the array returned by the getDeclaredMethods, 
if not found I look inside the array returned by the getMethods. The 
applied patch allow to invoke private, protected and public method from 
the POJO and public methods from the parent classes.

Regards,

Clement

>
>
> On 6/29/07, clement@apache.org <cl...@apache.org> wrote:
>>
>> Author: clement
>> Date: Fri Jun 29 06:56:49 2007
>> New Revision: 551894
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=551894
>> Log:
>> Improve method invocation for Lifecycle Callbacks. Allow the 
>> invocation of
>> method from parent classes.(Felix-315).
>> <snip>
>> ---
>> felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java 
>>
>> (original)
>> +++
>> felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java 
>>
>> Fri Jun 29 06:56:49 2007
>> @@ -209,8 +209,31 @@
>>
>>              }
>>          }
>> +
>> +        if (m_methodObj == null) { //look at parent classes
>> +            methods = m_manager.getClazz().getMethods();
>> +            for (int i = 0; m_methodObj == null && i < methods.length;
>> i++) {
>> +                // First check the method name
>> +                if (methods[i].getName().equals(m_method)) {
>> +                    // Check arguments
>> +                    Class[] clazzes = methods[i].getParameterTypes();
>> +                    if (clazzes.length == m_args.length) { // Test size
>> to avoid useless loop
>> +                        boolean ok = true;
>> +                        for (int j = 0; ok && j < m_args.length; j++) {
>> +                            if 
>> (!m_args[j].equals(clazzes[j].getName()))
>> {
>> +                                ok = false;
>> +                            }
>> +                        }
>> +                        if (ok) {
>> +                            m_methodObj = methods[i]; // It is the 
>> looked
>> method.
>> +                        }
>> +                    }
>> +                }
>> +            }
>> +        }
>> +
>> </snip>
>>
>


-- 
Clement Escoffier
Grenoble University
LSR - Bat. C
220, Rue de la Chimie
BP 53
38041 GRENOBLE CEDEX 9
04.76.51.40.24
http://clement.plop-plop.net