users@jersey.java.net

Re: [Jersey] WADL generator resource loading uses the wrong class loader

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 20 Feb 2009 13:04:23 +0100

On Feb 20, 2009, at 11:47 AM, Jakub Podlesak wrote:

> On Fri, Feb 20, 2009 at 11:30:49AM +0100, Martin Grotzke wrote:
>> Hi Jakub,
>>
>> I just modified the GenerateWadlMojo so that it creates a more
>> informative error message (which property fails).
>>
>> Can you svn update and build/install the maven-wadl-plugin and try
>> again?
>
> Sure, please see the new output log attached,
>

The problem is that i think Class.getConstructors() returns an array
whose elements are not sorted and not in any particular order
(although that is not stated in the JavaDoc, which is stated for
returning of methods).

The following code should check that the number of parameters is equal
to one:

     private Constructor<?> getMatchingConstructor( final Class<?>
paramClazz,
             final Object propertyValue ) {
         final Constructor<?>[] constructors =
paramClazz.getConstructors();
         for ( Constructor<?> constructor : constructors ) {
             final Class<?>[] parameterTypes =
constructor.getParameterTypes();
             if ( parameterTypes.length > 0
                     && constructor.getParameterTypes()[0] ==
propertyValue.getClass() ) {
                 return constructor;
             }
         }
         return null;
     }

Paul.