Solely Javadoc fixes.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137420 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2003-07-14 22:29:04 +00:00
parent 00dc5a8684
commit faf34a0bb7
4 changed files with 295 additions and 217 deletions

View File

@ -58,27 +58,30 @@
import org.apache.commons.lang.ArrayUtils;
/**
* <code>ConstructorUtils</code> contains utility methods for working for
* constructors by reflection.
* <p>
* The ability is provided to break the scoping restrictions coded by the
* <p><code>ConstructorUtils</code> contains utility methods for working for
* constructors by reflection.</p>
*
* <p>The ability is provided to break the scoping restrictions coded by the
* programmer. This can allow classes to be created that shouldn't be, for
* example new instances of an enumerated type. Thus, this facility should
* be used with care.
* be used with care.</p>
*
* @author <a href="mailto:scolebourne@apache.org">Stephen Colebourne</a>
* @version $Id: ConstructorUtils.java,v 1.1 2002/10/24 23:12:54 scolebourne Exp $
* @version $Id: ConstructorUtils.java,v 1.2 2003/07/14 22:29:03 bayard Exp $
*/
public class ConstructorUtils {
/** An empty constructor array */
/**
* An empty constructor array.
*/
public static final Constructor[] EMPTY_CONSTRUCTOR_ARRAY = new Constructor[0];
/**
* ConstructorUtils instances should NOT be constructed in standard programming.
* Instead, the class should be used as <code>ConstructorUtils.newInstance(...)</code>.
* <p>ConstructorUtils instances should NOT be constructed in standard programming.</p>
*
* <p>Instead, the class should be used as <code>ConstructorUtils.newInstance(...)</code>.
* This constructor is public to permit tools that require a JavaBean instance
* to operate.
* to operate.</p>
*/
public ConstructorUtils() {
}
@ -86,30 +89,35 @@ public ConstructorUtils() {
// -------------------------------------------------------------------------
/**
* Gets a public <code>Constructor</code> object by matching the
* parameter types as per the Java Language Specification.
* <p>Gets a public <code>Constructor</code> object by matching the
* parameter types as per the Java Language Specification.</p>
*
* @param cls Class object to find constructor for, must not be null
* @param types array of Class objects representing parameter types, may be null
* @param cls Class object to find constructor for, must not
* be <code>null</code>
* @param types array of Class objects representing parameter
* types, may be <code>null</code>
* @return Constructor object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Constructor getConstructor(Class cls, Class[] types) {
return getConstructor(cls, types, false);
}
/**
* Gets a public <code>Constructor</code> object by matching the
* parameter types as per the Java Language Specification.
* <p>Gets a public <code>Constructor</code> object by matching the
* parameter types as per the Java Language Specification.</p>
*
* @param cls Class object to find constructor for, must not be null
* @param types array of Class objects representing parameter types, may be null
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public methods.
* @param cls Class object to find constructor for, must not
* be <code>null</code>
* @param types array of Class objects representing parameter
* types, may be <code>null</code>
* @param breakScope whether to break scope restrictions using
* the <code>setAccessible</code> method. <code>False</code> will
* only match public methods.
* @return Constructor object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Constructor getConstructor(Class cls, Class[] types, boolean breakScope) {
if (cls == null) {
@ -151,30 +159,34 @@ public static Constructor getConstructor(Class cls, Class[] types, boolean break
// -------------------------------------------------------------------------
/**
* Gets a public <code>Constructor</code> object by exactly matching the
* parameter types.
* <p>Gets a public <code>Constructor</code> object by exactly matching the
* parameter types.</p>
*
* @param cls Class object to find constructor for, must not be null
* @param types array of Class objects representing parameter types, may be null
* @param cls Class object to find constructor for, must not
* be <code>null</code>
* @param types array of Class objects representing parameter
* types, may be <code>null</code>
* @return Constructor object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Constructor getConstructorExact(Class cls, Class[] types) {
return getConstructorExact(cls, types, false);
}
/**
* Gets a <code>Constructor</code> object by exactly matching the
* parameter types.
* <p>Gets a <code>Constructor</code> object by exactly matching the
* parameter types.</p>
*
* @param cls Class object to find constructor for, must not be null
* @param types array of Class objects representing parameter types, may be null
* @param cls Class object to find constructor for, must not
* be <code>null</code>
* @param types array of Class objects representing parameter types, may
* be <code>null</code>
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public methods.
* @return Constructor object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Constructor getConstructorExact(Class cls, Class[] types, boolean breakScope) {
if (cls == null) {
@ -206,41 +218,48 @@ public static Constructor getConstructorExact(Class cls, Class[] types, boolean
// -------------------------------------------------------------------------
/**
* Creates a new instance using a <code>Constructor</code> and parameters.
* <p>Creates a new instance using a <code>Constructor</code> and parameters.</p>
*
* @param con Class object to find constructor for, must not be null
* @param param the single parameter to pass to the constructor, may be null
* @param con Class object to find constructor for, must not
* be <code>null</code>
* @param param the single parameter to pass to the constructor, may
* be <code>null</code>
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the constructor is null
* @throws IllegalArgumentException if the constructor is <code>null</code>
*/
public static Object newInstance(Constructor con, Object param) {
return newInstance(con, new Object[] {param}, false);
}
/**
* Creates a new instance using a <code>Constructor</code> and parameters.
* <p>Creates a new instance using a <code>Constructor</code> and parameters.</p>
*
* @param con Class object to find constructor for, must not be null
* @param params array of objects to pass as parameters, may be null
* @param con Class object to find constructor for, must not
* be <code>null</code>
* @param params array of objects to pass as parameters, may
* be <code>null</code>
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the constructor is null
* @throws IllegalArgumentException if the constructor is <code>null</code>
*/
public static Object newInstance(Constructor con, Object[] params) {
return newInstance(con, params, false);
}
/**
* Creates a new instance using a <code>Constructor</code> and parameters.
* <p>Creates a new instance using a <code>Constructor</code> and parameters.</p>
*
* @param con Class object to find constructor for, must not be null
* @param params array of objects to pass as parameters, may be null
* @param con Class object to find constructor for, must not
* be <code>null</code>
* @param params array of objects to pass as parameters, may
* be <code>null</code>
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public methods.
* <code>setAccessible</code> method. <code>False</code> will only
* match public methods.
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the constructor is null
* @throws IllegalArgumentException if the constructor is <code>null</code>
*/
public static Object newInstance(Constructor con, Object[] params, boolean breakScope) {
if (con == null) {
@ -266,7 +285,7 @@ public static Object newInstance(Constructor con, Object[] params, boolean break
// -------------------------------------------------------------------------
/**
* Creates a new instance of the specified <code>Class</code> by name.
* <p>Creates a new instance of the specified <code>Class</code> by name.</p>
*
* @param className String class name to instantiate, must not be empty
* @return the newly created object
@ -278,9 +297,10 @@ public static Object newInstance(String className) {
}
/**
* Creates a new instance of the specified <code>Class</code> by name.
* If the constructor is not public, <code>setAccessible(true)</code>
* is used to make it accessible.
* <p>Creates a new instance of the specified <code>Class</code> by name.</p>
*
* <p>If the constructor is not public, <code>setAccessible(true)</code>
* is used to make it accessible.</p>
*
* @param className String class name to instantiate, must not be empty
* @param breakScope whether to break scope restrictions using the
@ -297,28 +317,30 @@ public static Object newInstance(String className, boolean breakScope) {
// -------------------------------------------------------------------------
/**
* Creates a new instance of the specified <code>Class</code>.
* <p>Creates a new instance of the specified <code>Class</code>.</p>
*
* @param cls Class object to instantiate, must not be null
* @param cls Class object to instantiate, must not be <code>null</code>
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Object newInstance(Class cls) {
return newInstance(cls, false);
}
/**
* Creates a new instance of the specified <code>Class</code>.
* If the constructor is not public, <code>setAccessible(true)</code>
* is used to make it accessible.
* <p>Creates a new instance of the specified <code>Class</code>.</p>
*
* @param cls Class object to instantiate, must not be null
* <p>If the constructor is not public, <code>setAccessible(true)</code>
* is used to make it accessible.</p>
*
* @param cls Class object to instantiate, must not be <code>null</code>
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public methods.
* <code>setAccessible</code> method. <code>False</code> will only
* match public methods.
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Object newInstance(Class cls, boolean breakScope) {
if (breakScope) {
@ -346,35 +368,44 @@ public static Object newInstance(Class cls, boolean breakScope) {
// -------------------------------------------------------------------------
/**
* Creates a new instance of the specified <code>Class</code>.
* The constructor is found by matching the
* parameter types as per the Java Language Specification.
* <p>Creates a new instance of the specified <code>Class</code>.</p>
*
* @param cls Class object to instantiate, must not be null
* @param types array of Class objects representing parameter types, may be null
* @param params array of objects to pass as parameters, may be null
* <p>The constructor is found by matching the
* parameter types as per the Java Language Specification.</p>
*
* @param cls Class object to instantiate, must not
* be <code>null</code>
* @param types array of Class objects representing parameter types,
* may be <code>null</code>
* @param params array of objects to pass as parameters, may
* be <code>null</code>
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Object newInstance(Class cls, Class[] types, Object[] params) {
return newInstance(cls, types, params, false);
}
/**
* Creates a new instance of the specified <code>Class</code>.
* The constructor is found by matching the
* parameter types as per the Java Language Specification.
* <p>Creates a new instance of the specified <code>Class</code>.</p>
*
* @param cls Class object to instantiate, must not be null
* @param types array of Class objects representing parameter types, may be null
* @param params array of objects to pass as parameters, may be null
* <p>The constructor is found by matching the
* parameter types as per the Java Language Specification.</p>
*
* @param cls Class object to instantiate, must not
* be <code>null</code>
* @param types array of Class objects representing parameter types,
* may be <code>null</code>
* @param params array of objects to pass as parameters, may
* be <code>null</code>
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public methods.
* <code>setAccessible</code> method. <code>False</code> will only
* match public methods.
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the types and params lengths differ
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Object newInstance(Class cls, Class[] types, Object[] params, boolean breakScope) {
if (ArrayUtils.isSameLength(types, params) == false) {
@ -387,33 +418,42 @@ public static Object newInstance(Class cls, Class[] types, Object[] params, bool
// -------------------------------------------------------------------------
/**
* Creates a new instance of the specified <code>Class</code>.
* The constructor is found by matching the parameter types exactly.
* <p>Creates a new instance of the specified <code>Class</code>.</p>
*
* @param cls Class object to instantiate, must not be null
* @param types array of Class objects representing parameter types, may be null
* @param params array of objects to pass as parameters, may be null
* <p>The constructor is found by matching the parameter types exactly.</p>
*
* @param cls Class object to instantiate, must not
* be <code>null</code>
* @param types array of Class objects representing parameter types,
* may be <code>null</code>
* @param params array of objects to pass as parameters, may
* be <code>null</code>
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Object newInstanceExact(Class cls, Class[] types, Object[] params) {
return newInstanceExact(cls, types, params, false);
}
/**
* Creates a new instance of the specified <code>Class</code>.
* The constructor is found by matching the parameter types exactly.
* <p>Creates a new instance of the specified <code>Class</code>.</p>
*
* @param cls Class object to instantiate, must not be null
* @param types array of Class objects representing parameter types, may be null
* @param params array of objects to pass as parameters, may be null
* <p>The constructor is found by matching the parameter types exactly.</p>
*
* @param cls Class object to instantiate, must not
* be <code>null</code>
* @param types array of Class objects representing parameter types,
* may be <code>null</code>
* @param params array of objects to pass as parameters, may
* be <code>null</code>
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public methods.
* <code>setAccessible</code> method. <code>False</code> will only match
* public methods.
* @return the newly created object
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the types and params lengths differ
* @throws IllegalArgumentException if the class is null
* @throws IllegalArgumentException if the class is <code>null</code>
*/
public static Object newInstanceExact(Class cls, Class[] types, Object[] params, boolean breakScope) {
if (ArrayUtils.isSameLength(types, params) == false) {

View File

@ -56,26 +56,29 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/**
* <code>FieldUtils</code> contains utility methods for working with
* fields by reflection.
* <p>
* The ability is provided to break the scoping restrictions coded by the
* <p><code>FieldUtils</code> contains utility methods for working with
* fields by reflection.</p>
*
* <p>The ability is provided to break the scoping restrictions coded by the
* programmer. This can allow fields to be changed that shouldn't be. This
* facility should be used with care.
* facility should be used with care.</p>
*
* @author <a href="mailto:scolebourne@apache.org">Stephen Colebourne</a>
* @version $Id: FieldUtils.java,v 1.1 2002/10/24 23:12:54 scolebourne Exp $
* @version $Id: FieldUtils.java,v 1.2 2003/07/14 22:29:04 bayard Exp $
*/
public class FieldUtils {
/** An empty field array */
/**
* An empty field array.
*/
public static final Field[] EMPTY_FIELD_ARRAY = new Field[0];
/**
* FieldUtils instances should NOT be constructed in standard programming.
* Instead, the class should be used as <code>FieldUtils.getField(cls, name)</code>.
* <p>FieldUtils instances should NOT be constructed in standard programming.</p>
*
* <p>Instead, the class should be used as <code>FieldUtils.getField(cls, name)</code>.
* This constructor is public to permit tools that require a JavaBean instance
* to operate.
* to operate.</p>
*/
public FieldUtils() {
}
@ -83,13 +86,14 @@ public FieldUtils() {
// -------------------------------------------------------------------------
/**
* Gets an accessible Field by name repecting scope.
* Superclasses/interfaces will be considered.
* <p>Gets an accessible <code>Field</code> by name repecting scope.
* Superclasses/interfaces will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @return the Field object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Field getField(Class cls, String fieldName) {
@ -97,15 +101,17 @@ public static Field getField(Class cls, String fieldName) {
}
/**
* Gets an accessible Field by name breaking scope if requested.
* Superclasses/interfaces will be considered.
* <p>Gets an accessible <code>Field</code> by name breaking scope
* if requested. Superclasses/interfaces will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public fields.
* <code>setAccessible</code> method. <code>False</code> will only
* match public fields.
* @return the Field object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Field getField(Class cls, String fieldName, boolean breakScope) {
@ -189,13 +195,14 @@ public static Field getField(Class cls, String fieldName, boolean breakScope) {
// -------------------------------------------------------------------------
/**
* Gets an accessible Field by name respecting scope.
* Only the specified class will be considered.
* <p>Gets an accessible <code>Field</code> by name respecting scope.
* Only the specified class will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @return the Field object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Field getFieldExact(Class cls, String fieldName) {
@ -203,15 +210,16 @@ public static Field getFieldExact(Class cls, String fieldName) {
}
/**
* Gets an accessible Field by name breaking scope if requested.
* Only the specified class will be considered.
* <p>Gets an accessible <code>Field</code> by name breaking scope
* if requested. Only the specified class will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public fields.
* @return the Field object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Field getFieldExact(Class cls, String fieldName, boolean breakScope) {
@ -247,11 +255,12 @@ public static Field getFieldExact(Class cls, String fieldName, boolean breakScop
// -------------------------------------------------------------------------
/**
* Gets a static Field value from a Field object.
* <p>Gets a static Field value from a <code>Field</code> object.</p>
*
* @param field the field to use
* @return the field value
* @throws IllegalArgumentException if the field is null or not static
* @throws IllegalArgumentException if the field is
* <code>null</code> or not static
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getStaticFieldValue(Field field) {
@ -265,13 +274,15 @@ public static Object getStaticFieldValue(Field field) {
}
/**
* Gets a static Field value from a Field object.
* <p>Gets a static Field value from a <code>Field</code> object.</p>
*
* @param field the field to use
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public methods.
* <code>setAccessible</code> method. <code>False</code> will only
* match public methods.
* @return the field value
* @throws IllegalArgumentException if the field is null or not static
* @throws IllegalArgumentException if the field is <code>null</code>
* or not static
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getStaticFieldValue(Field field, boolean breakScope) {
@ -285,12 +296,13 @@ public static Object getStaticFieldValue(Field field, boolean breakScope) {
}
/**
* Gets a Field value from a Field object.
* <p>Gets a Field value from a <code>Field</code> object.</p>
*
* @param field the field to use
* @param object the object to call on, may be null for static fields
* @param object the object to call on, may be <code>null</code>
* for static fields
* @return the field value
* @throws IllegalArgumentException if the field is null
* @throws IllegalArgumentException if the field is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getFieldValue(Field field, Object object) {
@ -298,14 +310,16 @@ public static Object getFieldValue(Field field, Object object) {
}
/**
* Gets a Field value from a Field object.
* <p>Gets a Field value from a Field object.</p>
*
* @param field the field to use
* @param object the object to call on, may be null for static fields
* @param object the object to call on, may be <code>null</code>
* for static fields
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public methods.
* <code>setAccessible</code> method. <code>False</code> will only
* match public methods.
* @return the field value
* @throws IllegalArgumentException if the field is null
* @throws IllegalArgumentException if the field is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getFieldValue(Field field, Object object, boolean breakScope) {
@ -332,13 +346,14 @@ public static Object getFieldValue(Field field, Object object, boolean breakScop
// -------------------------------------------------------------------------
/**
* Gets a static Field value by name. The field must be public.
* Superclasses will be considered.
* <p>Gets a static Field value by name. The field must be public.
* Superclasses will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @return the value of the field
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getStaticFieldValue(Class cls, String fieldName) {
@ -346,15 +361,17 @@ public static Object getStaticFieldValue(Class cls, String fieldName) {
}
/**
* Gets a static Field value by name.
* Only the specified class will be considered.
* <p>Gets a static Field value by name. Only the specified class
* will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public fields.
* <code>setAccessible</code> method. <code>False</code> will only
* match public fields.
* @return the Field object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getStaticFieldValue(Class cls, String fieldName, boolean breakScope) {
@ -379,13 +396,14 @@ public static Object getStaticFieldValue(Class cls, String fieldName, boolean br
// -------------------------------------------------------------------------
/**
* Gets a static Field value by name. The field must be public.
* Only the specified class will be considered.
* <p>Gets a static Field value by name. The field must be public.
* Only the specified class will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @return the value of the field
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getStaticFieldValueExact(Class cls, String fieldName) {
@ -393,15 +411,17 @@ public static Object getStaticFieldValueExact(Class cls, String fieldName) {
}
/**
* Gets a static Field value by name.
* Only the specified class will be considered.
* <p>Gets a static Field value by name. Only the specified class will
* be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public fields.
* <code>setAccessible</code> method. <code>False</code> will only
* match public fields.
* @return the Field object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getStaticFieldValueExact(Class cls, String fieldName, boolean breakScope) {
@ -426,13 +446,14 @@ public static Object getStaticFieldValueExact(Class cls, String fieldName, boole
// -------------------------------------------------------------------------
/**
* Gets a Field value by name. The field must be public.
* Superclasses will be considered.
* <p>Gets a Field value by name. The field must be public. Superclasses
* will be considered.</p>
*
* @param object the object to reflect, must not be null
* @param object the object to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @return the value of the field
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getFieldValue(Object object, String fieldName) {
@ -440,15 +461,17 @@ public static Object getFieldValue(Object object, String fieldName) {
}
/**
* Gets a Field value by name.
* Only the specified class will be considered.
* <p>Gets a Field value by name. Only the specified class will be
* considered.</p>
*
* @param object the object to reflect, must not be null
* @param object the object to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public fields.
* <code>setAccessible</code> method. <code>False</code> will only
* match public fields.
* @return the Field object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getFieldValue(Object object, String fieldName, boolean breakScope) {
@ -459,13 +482,14 @@ public static Object getFieldValue(Object object, String fieldName, boolean brea
// -------------------------------------------------------------------------
/**
* Gets a Field value by name. The field must be public.
* Only the class of the specified object will be considered.
* <p>Gets a Field value by name. The field must be public.
* Only the class of the specified object will be considered.</p>
*
* @param object the object to reflect, must not be null
* @param object the object to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @return the value of the field
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getFieldValueExact(Object object, String fieldName) {
@ -473,15 +497,17 @@ public static Object getFieldValueExact(Object object, String fieldName) {
}
/**
* Gets a Field value by name.
* Only the class of the specified object will be considered.
* <p<>Gets a Field value by name. Only the class of the specified
* object will be considered.</p>
*
* @param object the object to reflect, must not be null
* @param object the object to reflect, must not be <code>null</code>
* @param fieldName the field name to obtain
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public fields.
* <code>setAccessible</code> method. <code>False</code> will only
* match public fields.
* @return the Field object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Object getFieldValueExact(Object object, String fieldName, boolean breakScope) {

View File

@ -60,12 +60,12 @@
import org.apache.commons.lang.ArrayUtils;
/**
* <code>MethodUtils</code> contains utility methods for working for
* methods by reflection.
* <p>
* The ability is provided to break the scoping restrictions coded by the
* <p><code>MethodUtils</code> contains utility methods for working for
* methods by reflection.</p>
*
* <p>The ability is provided to break the scoping restrictions coded by the
* programmer. This can break an implementation if used incorrectly. This
* facility should be used with care.
* facility should be used with care.</p>
*
* @author <a href="mailto:scolebourne@apache.org">Stephen Colebourne</a>
* @author Based on code from <code>BeanUtils</code> by: Craig R. McClanahan
@ -76,20 +76,23 @@
* @author Jan Sorensen
* @author Robert Burrell Donkin
* @author Gary Gregory
* @version $Id: MethodUtils.java,v 1.11 2003/01/25 13:01:38 scolebourne Exp $
* @version $Id: MethodUtils.java,v 1.12 2003/07/14 22:29:04 bayard Exp $
*/
public class MethodUtils {
public static final boolean debug = false;
/** An empty method array */
/**
* An empty method array.
*/
public static final Method[] EMPTY_METHOD_ARRAY = new Method[0];
/**
* MethodUtils instances should NOT be constructed in standard programming.
* Instead, the class should be used as <code>MethodUtils.getMethod(cls, name)</code>.
* <p>MethodUtils instances should NOT be constructed in standard programming.</p>
*
* <p>Instead, the class should be used as <code>MethodUtils.getMethod(cls, name)</code>.
* This constructor is public to permit tools that require a JavaBean instance
* to operate.
* to operate.</p>
*/
public MethodUtils() {
}
@ -97,13 +100,14 @@ public MethodUtils() {
// -------------------------------------------------------------------------
/**
* Gets a Method by name. The method must be public and take no parameters.
* Superclasses will be considered.
* <p>Gets a <code>Method</code> by name. The method must be public and take
* no parameters. Superclasses will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param methodName the field name to obtain
* @return the Method object
* @throws IllegalArgumentException if the class or method name is null
* @throws IllegalArgumentException if the class or method name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Method getMethod(Class cls, String methodName) {
@ -111,13 +115,14 @@ public static Method getMethod(Class cls, String methodName) {
}
/**
* Gets a Method by name. The method must be public.
* Superclasses will be considered.
* <p>Gets a <code>Method</code> by name. The method must be public.
* Superclasses will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param methodName the field name to obtain
* @return the Method object
* @throws IllegalArgumentException if the class or method name is null
* @throws IllegalArgumentException if the class or method name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Method getMethod(Class cls, String methodName, Class paramType) {
@ -126,13 +131,14 @@ public static Method getMethod(Class cls, String methodName, Class paramType) {
}
/**
* Gets a Method by name. The method must be public.
* Superclasses will be considered.
* <p>Gets a <code>Method</code> by name.</p> The method must be public.
* Superclasses will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param methodName the field name to obtain
* @return the Method object
* @throws IllegalArgumentException if the class or method name is null
* @throws IllegalArgumentException if the class or method name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Method getMethod(Class cls, String methodName, Class[] paramTypes) {
@ -140,15 +146,16 @@ public static Method getMethod(Class cls, String methodName, Class[] paramTypes)
}
/**
* Gets a Method by name.
* Superclasses will be considered.
* <p>Gets a <code>Method</code> by name. Superclasses will be considered.</p>
*
* @param cls the class to reflect, must not be null
* @param cls the class to reflect, must not be <code>null</code>
* @param methodName the method name to obtain
* @param breakScope whether to break scope restrictions using the
* <code>setAccessible</code> method. False will only match public fields.
* <code>setAccessible</code> method. <code>False</code> will only
* match public fields.
* @return the Method object
* @throws IllegalArgumentException if the class or field name is null
* @throws IllegalArgumentException if the class or field name
* is <code>null</code>
* @throws ReflectionException if an error occurs during reflection
*/
public static Method getMethod(Class cls, String methodName, Class[] paramTypes, boolean breakScope) {
@ -215,8 +222,8 @@ public static Method getMethod(Class cls, String methodName, Class[] paramTypes,
/**
* <p>Return an accessible method (that is, one that can be invoked via
* reflection) that implements the specified Method. If no such method
* can be found, return <code>null</code>.</p>
* reflection) that implements the specified <code>Method</code>. If
* no such method can be found, return <code>null</code>.</p>
*
* @param method The method that we wish to call
*/
@ -270,12 +277,14 @@ public static Method getMethod(Method method) {
* {@link #invokeMethod(Object object,String methodName,Object [] args)}.
* </p>
*
* @param objectToInvoke invoke method on this object, must not be null
* @param methodName get method with this name, must not be null
* @param arg use this argument, must not be null
*
* @param objectToInvoke invoke method on this object, must
* not be <code>null</code>
* @param methodName get method with this name, must not
* be <code>null</code>
* @param arg use this argument, must not be <code>null</code>
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if any parameter is null
* @throws IllegalArgumentException if any parameter is
* <code>null</code>
*/
public static Object invokeMethod(
Object objectToInvoke,
@ -308,12 +317,15 @@ public static Object invokeMethod(
* {@link #invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}.
* </p>
*
* @param objectToInvoke invoke method on this object, must not be null
* @param methodName get method with this name, must not be null
* @param args use these arguments - treat null as empty array
*
* @param objectToInvoke invoke method on this object, must not
* be <code>null</code>
* @param methodName get method with this name, must not
* be <code>null</code>
* @param args use these arguments - treat <code>null</code>
* as empty array
* @throws ReflectionException if an error occurs during reflection
* @throws IllegalArgumentException if the objectToInvoke, methodName or any argument is null
* @throws IllegalArgumentException if the objectToInvoke, methodName
* or any argument is <code>null</code>
*/
public static Object invokeMethod(
Object objectToInvoke,
@ -354,8 +366,8 @@ public static Object invokeMethod(
* @param object invoke method on this object
* @param methodName get method with this name
* @param args use these arguments - treat null as empty array
* @param parameterTypes match these parameters - treat null as empty array
*
* @param parameterTypes match these parameters - treat
* <code>null</code> as empty array
* @throws ReflectionException if an error occurs during reflection
*/
public static Object invokeMethod(

View File

@ -55,25 +55,25 @@
import org.apache.commons.lang.exception.NestableRuntimeException;
/**
* Exception thrown when the Reflection process fails. The original
* error is wrapped within this one.
* <p>Exception thrown when the Reflection process fails. The original
* error is wrapped within this one.</p>
*
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @version $Id: ReflectionException.java,v 1.1 2002/10/24 23:12:54 scolebourne Exp $
* @version $Id: ReflectionException.java,v 1.2 2003/07/14 22:29:04 bayard Exp $
*/
public class ReflectionException extends NestableRuntimeException {
/**
* Constructs a new <code>ReflectionException</code> without specified
* detail message.
* <p>Constructs a new <code>ReflectionException</code> without specified
* detail message.</p>
*/
public ReflectionException() {
super();
}
/**
* Constructs a new <code>ReflectionException</code> with specified
* detail message.
* <p>Constructs a new <code>ReflectionException</code> with specified
* detail message.</p>
*
* @param msg The error message.
*/
@ -82,8 +82,8 @@ public ReflectionException(String msg) {
}
/**
* Constructs a new <code>ReflectionException</code> with specified
* nested <code>Throwable</code>.
* <p>Constructs a new <code>ReflectionException</code> with specified
* nested <code>Throwable</code>.</p>
*
* @param cause The exception or error that caused this exception
* to be thrown.
@ -93,8 +93,8 @@ public ReflectionException(Throwable cause) {
}
/**
* Constructs a new <code>ReflectionException</code> with specified
* detail message and nested <code>Throwable</code>.
* <p>Constructs a new <code>ReflectionException</code> with specified
* detail message and nested <code>Throwable</code>.</p>
*
* @param msg The error message.
* @param cause The exception or error that caused this exception