com.flat502.rox.marshal
Class ClassDescriptor

java.lang.Object
  extended by com.flat502.rox.marshal.ClassDescriptor

public class ClassDescriptor
extends java.lang.Object

Defines an interface for accessing members of a Java Class consistently.

An instance of this class provides uniform access to members of a Java Class. Whether or not the member is a public field or only through methods is opaque to the caller.

This class guarantees a singleton instance per Class. As such instances of this class are only available via the static factory method.

The set of members on a given class is defined as all non-transient public fields and all properties (in the Introspector sense) accessible via either a public getter or setter method. If there is an overlap (i.e. a setter or getter exists for a public field) methods are given precedence.


Method Summary
 java.lang.Class getGetterType(java.lang.String name)
           
static ClassDescriptor getInstance(java.lang.Class clazz)
          Static factory method for creating instances of this class.
 java.lang.Class getSetterType(java.lang.String name)
           
 java.util.Iterator getters()
          Provides an Iterator over the getters on the represented Class.
 java.lang.Object getValue(java.lang.Object target, java.lang.String name)
          Gets the value of the named property.
 java.util.Iterator setters()
          Provides an Iterator over the setters on the represented Class.
 void setValue(java.lang.Object target, java.lang.String name, java.lang.Object value)
          Sets the value of the named property.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

setValue

public void setValue(java.lang.Object target,
                     java.lang.String name,
                     java.lang.Object value)
              throws java.lang.IllegalArgumentException,
                     java.lang.IllegalAccessException,
                     java.lang.reflect.InvocationTargetException
Sets the value of the named property.

No type coercion beyond that provided by Field.set(java.lang.Object, java.lang.Object) or Method.invoke(java.lang.Object, java.lang.Object[]) is performed.

Parameters:
target - The object on which the named property should be set.
name - The name of the property to set.
value - The value to set the named property to.
Throws:
java.lang.IllegalArgumentException - if target or name are null, or if the Class represented by this instance differs to target's.
java.lang.IllegalAccessException - if the field or method associated with the named property is inaccessible.
java.lang.reflect.InvocationTargetException - if an exception is raised while invoking a setter.

getValue

public java.lang.Object getValue(java.lang.Object target,
                                 java.lang.String name)
                          throws java.lang.IllegalArgumentException,
                                 java.lang.IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException
Gets the value of the named property.

Parameters:
target - The object on which the named property should be set.
name - The name of the property to set.
Returns:
the current value of the named property on the target object.
Throws:
java.lang.IllegalArgumentException - if target or name are null, or if the Class represented by this instance differs to target's.
java.lang.IllegalAccessException - if the field or method associated with the named property is inaccessible.
java.lang.reflect.InvocationTargetException - if an exception is raised while invoking a setter.

getters

public java.util.Iterator getters()
Provides an Iterator over the getters on the represented Class.

The iterator returns String instances on each iteration. These instances name the readable properties on the represented Class.

Returns:
an Iterator over the getters available on the represented Class.

setters

public java.util.Iterator setters()
Provides an Iterator over the setters on the represented Class.

The iterator returns String instances on each iteration. These instances name the writeable properties on the represented Class.

Returns:
an Iterator over the setters available on the represented Class.

getGetterType

public java.lang.Class getGetterType(java.lang.String name)

getSetterType

public java.lang.Class getSetterType(java.lang.String name)

getInstance

public static ClassDescriptor getInstance(java.lang.Class clazz)
                                   throws java.beans.IntrospectionException
Static factory method for creating instances of this class.

Multiple invocations of this method with the same Class instance are guaranteed to return the same instance.

Parameters:
clazz - The class for which a ClassDescriptor is required.
Returns:
The ClassDescriptor instance associated with the given class.
Throws:
java.beans.IntrospectionException - if an error ocurrs while introspecting the given class.
java.lang.IllegalArgumentException - if the parameter is null.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object