You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by LOX <di...@blue-edge.bg> on 2003/02/03 15:46:34 UTC

[beanutils][patch] ConstructorUtils javadoc

Hi all,

When I start using new class, I have a habit to first take a quick view
of the javadoc. 
If there isn't any I often write some while I browse through the source.

In case you're interested here is a patch containing JavaDoc for the
ConstructorUtils class.
It's not perfect and I have borrowed some parts from the MethodUtils,
but I hope it's better than nothing :).

Also I often find classes in jacarta commons which have illegal
javadocs, are you interested in corrections for these?


Best regards,
Dimiter


RE: [beanutils][patch] ConstructorUtils javadoc

Posted by Martin van den Bemt <ml...@mvdb.net>.
Applied thanx !

Mvgr,
Martin

On Mon, 2003-02-03 at 20:58, LOX wrote:
> here we go again...
> ----
> 

> Index: ConstructorUtils.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConstructorUtils.java,v
> retrieving revision 1.2
> diff -u -r1.2 ConstructorUtils.java
> --- ConstructorUtils.java	15 Jan 2003 21:59:38 -0000	1.2
> +++ ConstructorUtils.java	3 Feb 2003 14:38:06 -0000
> @@ -63,6 +63,21 @@
>  
>  /**
>   * @version $Revision: 1.2 $ $Date: 2003/01/15 21:59:38 $
> + *
> + * <p> Utility reflection methods focussed on constructors, modelled after {@link MethodUtils}. </p>
> + *
> + * <h3>Known Limitations</h3>
> + * <h4>Accessing Public Constructors In A Default Access Superclass</h4>
> + * <p>There is an issue when invoking public constructors contained in a default access superclass.
> + * Reflection locates these constructors fine and correctly assigns them as public.
> + * However, an <code>IllegalAccessException</code> is thrown if the constructors is invoked.</p>
> + *
> + * <p><code>ConstructorUtils</code> contains a workaround for this situation.
> + * It will attempt to call <code>setAccessible</code> on this constructor.
> + * If this call succeeds, then the method can be invoked as normal.
> + * This call will only succeed when the application has sufficient security privilages.
> + * If this call fails then a warning will be logged and the method may fail.</p>
> + *
>   * @author Craig R. McClanahan
>   * @author Ralph Schaer
>   * @author Chris Audley
> @@ -82,6 +97,19 @@
>  
>      // --------------------------------------------------------- Public Methods
>  
> +    /**
> +     * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor.
> +     * The formal parameter type is inferred from the actual values of <code>arg</code>.
> +     * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p>
> +     *
> +     * <p>The signatures should be assignment compatible.</p>
> +     *
> +     * @param klass the class to be constructed.
> +     * @param arg the actual argument
> +     * @return new instance of <code>klazz</code>
> +     *
> +     * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
> +     */
>      public static Object invokeConstructor(Class klass, Object arg)
>          throws
>              NoSuchMethodException,
> @@ -94,6 +122,19 @@
>  
>      }
>  
> +    /**
> +     * <p>Returns new instance of <code>klazz</code> created using the actual arguments <code>args</code>.
> +     * The formal parameter types are inferred from the actual values of <code>args</code>.
> +     * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p>
> +     *
> +     * <p>The signatures should be assignment compatible.</p>
> +     *
> +     * @param klass the class to be constructed.
> +     * @param args actual argument array
> +     * @return new instance of <code>klazz</code>
> +     *
> +     * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
> +     */
>      public static Object invokeConstructor(Class klass, Object[] args)
>          throws
>              NoSuchMethodException,
> @@ -113,6 +154,23 @@
>  
>      }
>  
> +    /**
> +     * <p>Returns new instance of <code>klazz</code> created using constructor
> +     * with signature <code>parameterTypes</code> and actual arguments <code>args</code>.</p>
> +     *
> +     * <p>The signatures should be assignment compatible.</p>
> +     *
> +     * @param klass the class to be constructed.
> +     * @param args actual argument array
> +     * @param parameterTypes parameter types array
> +     * @return new instance of <code>klazz</code>
> +     *
> +     * @throws NoSuchMethodException if matching constructor cannot be found
> +     * @throws IllegalAccessException thrown on the constructor's invocation
> +     * @throws InvocationTargetException thrown on the constructor's invocation
> +     * @throws InstantiationException thrown on the constructor's invocation
> +     * @see Constructor#newInstance
> +     */
>      public static Object invokeConstructor(
>          Class klass,
>          Object[] args,
> @@ -139,6 +197,20 @@
>          return ctor.newInstance(args);
>      }
>  
> +
> +    /**
> +     * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor.
> +     * The formal parameter type is inferred from the actual values of <code>arg</code>.
> +     * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p>
> +     *
> +     * <p>The signatures should match exactly.</p>
> +     *
> +     * @param klass the class to be constructed.
> +     * @param arg the actual argument
> +     * @return new instance of <code>klazz</code>
> +     *
> +     * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
> +     */
>      public static Object invokeExactConstructor(Class klass, Object arg)
>          throws
>              NoSuchMethodException,
> @@ -150,6 +222,20 @@
>          return invokeExactConstructor(klass, args);
>  
>      }
> +
> +    /**
> +     * <p>Returns new instance of <code>klazz</code> created using the actual arguments <code>args</code>.
> +     * The formal parameter types are inferred from the actual values of <code>args</code>.
> +     * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p>
> +     *
> +     * <p>The signatures should match exactly.</p>
> +     *
> +     * @param klass the class to be constructed.
> +     * @param args actual argument array
> +     * @return new instance of <code>klazz</code>
> +     *
> +     * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
> +     */
>      public static Object invokeExactConstructor(Class klass, Object[] args)
>          throws
>              NoSuchMethodException,
> @@ -168,6 +254,24 @@
>  
>      }
>  
> +    /**
> +     * <p>Returns new instance of <code>klazz</code> created using constructor
> +     * with signature <code>parameterTypes</code> and actual arguments
> +     * <code>args</code>.</p>
> +     *
> +     * <p>The signatures should match exactly.</p>
> +     *
> +     * @param klass the class to be constructed.
> +     * @param args actual argument array
> +     * @param parameterTypes parameter types array
> +     * @return new instance of <code>klazz</code>
> +     *
> +     * @throws NoSuchMethodException if matching constructor cannot be found
> +     * @throws IllegalAccessException thrown on the constructor's invocation
> +     * @throws InvocationTargetException thrown on the constructor's invocation
> +     * @throws InstantiationException thrown on the constructor's invocation
> +     * @see Constructor#newInstance
> +     */
>      public static Object invokeExactConstructor(
>          Class klass,
>          Object[] args,
> @@ -195,6 +299,13 @@
>  
>      }
>  
> +    /**
> +     * Returns a constructor with single argument.
> +     * @param klass the class to be constructed
> +     * @return null if matching accessible constructor can not be found.
> +     * @see Class#getConstructor
> +     * @see #getAccessibleConstructor(java.lang.reflect.Constructor)
> +     */
>      public static Constructor getAccessibleConstructor(
>          Class klass,
>          Class parameterType) {
> @@ -204,6 +315,14 @@
>  
>      }
>  
> +    /**
> +     * Returns a constructor given a class and signature.
> +     * @param klass the class to be constructed
> +     * @param parameterTypes the parameter array
> +     * @return null if matching accessible constructor can not be found
> +     * @see Class#getConstructor
> +     * @see #getAccessibleConstructor(java.lang.reflect.Constructor)
> +     */
>      public static Constructor getAccessibleConstructor(
>          Class klass,
>          Class[] parameterTypes) {
> @@ -217,6 +336,12 @@
>  
>      }
>  
> +    /**
> +     * Returns accessible version of the given constructor.
> +     * @param ctor prototype constructor object.
> +     * @return <code>null</code> if accessible constructor can not be found.
> +     * @see java.lang.SecurityManager
> +     */
>      public static Constructor getAccessibleConstructor(Constructor ctor) {
>  
>          // Make sure we have a method to check
> @@ -241,7 +366,21 @@
>      }
>  
>      // -------------------------------------------------------- Private Methods
> -
> +    /**
> +     * <p>Find an accessible constructor with compatible parameters.
> +     * Compatible parameters mean that every method parameter is assignable from
> +     * the given parameters. In other words, it finds constructor that will take
> +     * the parameters given.</p>
> +     *
> +     * <p>First it checks if there is constructor matching the exact signature.
> +     * If no such, all the constructors of the class are tested if their signatures
> +     * are assignment compatible with the parameter types.
> +     * The first matching constructor is returned.</p>
> +     *
> +     * @param clazz find constructor for this class
> +     * @param parameterTypes find method with compatible parameters
> +     * @return a valid Constructor object. If there's no matching constructor, returns <code>null</code>.
> +     */
>      private static Constructor getMatchingAccessibleConstructor(
>          Class clazz,
>          Class[] parameterTypes) {
> 
> ----
> 

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [beanutils][patch] ConstructorUtils javadoc

Posted by LOX <di...@blue-edge.bg>.
here we go again...

RE: [beanutils][patch] ConstructorUtils javadoc

Posted by Martin van den Bemt <ml...@mvdb.net>.
Have a go with the txt extension (the headers still showed the
mixed/multipart, so that's why I think it was stripped out of the mail).
Don't know if it makes any difference though :)

Mvgr,
Martin

On Mon, 2003-02-03 at 19:48, LOX wrote:
> > Seems like your attachment got stripped from the mail. Amybe 
> > wrong extension or too big, don't know..
> 
> The extension was .patch, the size was 12k..
> Plain text patch file...
> 
> Dimiter
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [beanutils][patch] ConstructorUtils javadoc

Posted by LOX <di...@blue-edge.bg>.
> Seems like your attachment got stripped from the mail. Amybe 
> wrong extension or too big, don't know..

The extension was .patch, the size was 12k..
Plain text patch file...

Dimiter


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [beanutils][patch] ConstructorUtils javadoc

Posted by Martin van den Bemt <ml...@mvdb.net>.
Seems like your attachment got stripped from the mail. Amybe wrong
extension or too big, don't know..

Mvgr,
Martin

On Mon, 2003-02-03 at 19:22, LOX wrote:
> I'm sorry, I'm relly new to the Apache lists..
> 
> Could somebody explain me what happened?
> 
> First I sent a mail containing the patch, a minute later I received the
> mail from the list.
> So far it's fine, but now I receive the same mail with some kind of
> default file attached to it. (also my attachment was missing).
> 
> My adress was in the "from" fields of the both mails..
> 
> What happened actually?
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [beanutils][patch] ConstructorUtils javadoc

Posted by LOX <di...@blue-edge.bg>.
I'm sorry, I'm relly new to the Apache lists..

Could somebody explain me what happened?

First I sent a mail containing the patch, a minute later I received the
mail from the list.
So far it's fine, but now I receive the same mail with some kind of
default file attached to it. (also my attachment was missing).

My adress was in the "from" fields of the both mails..

What happened actually?



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org