com.sptci
Class ReflectionUtility

java.lang.Object
  extended by com.sptci.ReflectionUtility

public final class ReflectionUtility
extends java.lang.Object

A utility class to handle common reflection tasks.

Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: ReflectionUtility.java,v 1.3 2006/02/09 16:09:58 rakesh Exp $
Author:
Rakesh Vidyadharan 2006-02-07

Constructor Summary
private ReflectionUtility()
          Default constructor.
 
Method Summary
static java.lang.reflect.Method fetchAccessor(java.lang.String property, java.lang.Class cls)
          Fetches the accessor method for the specified property in the specified class.
static java.lang.reflect.Method fetchAccessor(java.lang.String property, java.lang.Object object)
          Fetches the accessor method for the specified property in the specified object.
static java.lang.reflect.Field fetchField(java.lang.String name, java.lang.Object object)
          Return the Field instance with the specified name from the object.
static java.util.Map<java.lang.String,java.lang.reflect.Field> fetchFields(java.lang.Class cls)
          Return the declared fields for the specified Class.
static java.util.Map<java.lang.String,java.lang.reflect.Field> fetchFields(java.lang.Object object)
          Return the declared fields for the specified object.
static java.lang.reflect.Method fetchMethod(java.lang.Class cls, java.lang.String name, java.lang.Class[] parameters)
          Fetch the Method defined in the specified class with the specified name that accepts the specified parameters.
static java.lang.reflect.Method fetchMethod(java.lang.reflect.Field field, java.lang.String name, java.lang.Class[] parameters)
          Fetch the Method defined in the specified field with the specified name that accepts the specified parameters.
static java.lang.reflect.Method fetchMethod(java.lang.Object object, java.lang.String name, java.lang.Class[] parameters)
          Fetch the Method defined in the specified object with the specified name that accepts the specified parameters.
static java.lang.reflect.Method fetchMutator(java.lang.String property, java.lang.Class cls)
          Fetches the mutator method for the specified property in the specified class.
static java.lang.reflect.Method fetchMutator(java.lang.String property, java.lang.Object object)
          Fetches the mutator method for the specified property in the specified object.
static java.lang.Object fetchObject(java.lang.String name, java.lang.Object object)
          Return the Object instance represented by the specified name from object.
static java.util.Map<java.lang.String,java.lang.Object> fetchObjects(java.lang.Object object)
          Return the Object instances representing the declared fields for the specified object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtility

private ReflectionUtility()
Default constructor. Cannot be instantiated.

Method Detail

fetchField

public static final java.lang.reflect.Field fetchField(java.lang.String name,
                                                       java.lang.Object object)
                                                throws java.lang.NoSuchFieldException
Return the Field instance with the specified name from the object. Sets the field accessible if it is not accessible.

Parameters:
name - The name of the field to look up.
object - The object from which the field is to be retrieved.
Throws:
java.lang.NoSuchFieldException - If no field with the specified name exists in object.

fetchObject

public static final java.lang.Object fetchObject(java.lang.String name,
                                                 java.lang.Object object)
                                          throws java.lang.NoSuchFieldException,
                                                 java.lang.IllegalAccessException
Return the Object instance represented by the specified name from object.

Parameters:
name - The name of the object to fetch.
object - The object from which the field is to be retrieved.
Returns:
Object The object instance for the specified field.
Throws:
java.lang.NoSuchFieldException - If no field with the specified name exists in object.
java.lang.IllegalAccessException - If the field cannot be accessed due to custom security policies.
See Also:
fetchField(java.lang.String, java.lang.Object)

fetchFields

public static final java.util.Map<java.lang.String,java.lang.reflect.Field> fetchFields(java.lang.Object object)
Return the declared fields for the specified object.

Parameters:
object - The object whose declared fields are to be retrieved.
Returns:
Map A map with the field names as key and the field as value
See Also:
fetchFields( Class )

fetchFields

public static final java.util.Map<java.lang.String,java.lang.reflect.Field> fetchFields(java.lang.Class cls)
Return the declared fields for the specified Class.

Parameters:
cls - The class whose declared fields are to be retrieved.
Returns:
Map A map with the field names as key and the field as value

fetchObjects

public static final java.util.Map<java.lang.String,java.lang.Object> fetchObjects(java.lang.Object object)
                                                                           throws java.lang.IllegalAccessException
Return the Object instances representing the declared fields for the specified object.

Parameters:
object - The object for which objects for the declared fields are to be retrieved.
Returns:
Map A map with the field names as key and the object as value
Throws:
java.lang.IllegalAccessException - If a custom security policy prevents access to the fields.
See Also:
fetchFields(java.lang.Object)

fetchMethod

public static final java.lang.reflect.Method fetchMethod(java.lang.reflect.Field field,
                                                         java.lang.String name,
                                                         java.lang.Class[] parameters)
Fetch the Method defined in the specified field with the specified name that accepts the specified parameters.

Parameters:
field - The field whose method is to be retrieved.
name - The name of the method to retrieve.
parameters - The parameters accepted by the method.
See Also:
fetchMethod( Class, String, Class[] )

fetchMethod

public static final java.lang.reflect.Method fetchMethod(java.lang.Object object,
                                                         java.lang.String name,
                                                         java.lang.Class[] parameters)
Fetch the Method defined in the specified object with the specified name that accepts the specified parameters.

Parameters:
object - The object whose method is to be retrieved.
name - The name of the method to retrieve.
parameters - The parameters accepted by the method.
See Also:
fetchMethod( Class, String, Class[] )

fetchMethod

public static final java.lang.reflect.Method fetchMethod(java.lang.Class cls,
                                                         java.lang.String name,
                                                         java.lang.Class[] parameters)
Fetch the Method defined in the specified class with the specified name that accepts the specified parameters.

Parameters:
cls - The cls whose method is to be retrieved.
name - The name of the method to retrieve.
parameters - The parameters accepted by the method.

fetchAccessor

public static final java.lang.reflect.Method fetchAccessor(java.lang.String property,
                                                           java.lang.Object object)
                                                    throws java.beans.IntrospectionException
Fetches the accessor method for the specified property in the specified object.

Parameters:
property - The property whose accessor is to be fetched.
object - The object to which the property belongs.
Returns:
Method The accessor method for the property.
Throws:
java.beans.IntrospectionException - If errors are encountered while introspecting the specified class.
See Also:
fetchAccessor( String, Class )

fetchAccessor

public static final java.lang.reflect.Method fetchAccessor(java.lang.String property,
                                                           java.lang.Class cls)
                                                    throws java.beans.IntrospectionException
Fetches the accessor method for the specified property in the specified class.

Parameters:
property - The property whose accessor is to be fetched.
cls - The class to which the property belongs.
Returns:
Method The accessor method for the property.
Throws:
java.beans.IntrospectionException - If errors are encountered while introspecting the specified class.

fetchMutator

public static final java.lang.reflect.Method fetchMutator(java.lang.String property,
                                                          java.lang.Object object)
                                                   throws java.beans.IntrospectionException
Fetches the mutator method for the specified property in the specified object.

Parameters:
property - The property whose mutator is to be fetched.
object - The object to which the property belongs.
Returns:
Method The mutator method for the property.
Throws:
java.beans.IntrospectionException - If errors are encountered while introspecting the specified class.
See Also:
fetchMutator( String, Class )

fetchMutator

public static final java.lang.reflect.Method fetchMutator(java.lang.String property,
                                                          java.lang.Class cls)
                                                   throws java.beans.IntrospectionException
Fetches the mutator method for the specified property in the specified class.

Parameters:
property - The property whose mutator is to be fetched.
cls - The class to which the property belongs.
Returns:
Method The mutator method for the property.
Throws:
java.beans.IntrospectionException - If errors are encountered while introspecting the specified class.


Copyright © 2006 Sans Pareil Technologies, Inc. All Rights Reserved.