org.jbind.util.reflect
Class ReflectUtil

java.lang.Object
  extended byorg.jbind.util.reflect.ReflectUtil

public class ReflectUtil
extends java.lang.Object

Static utility methods for the generator.


Method Summary
static java.lang.String getTypeName(java.lang.Class aClass)
          Returns the type name of the specified class.
static java.lang.Class getWrapperClass(java.lang.Class aClass)
           
static java.util.List removeSubClasses(java.util.Collection aClasses)
          Removes all classes from the specified collection that have a (real) super class in the collection.
static void setMembers(java.lang.Object anObject, java.util.Map aMap)
          Tries to set the members of an object by their setter-methods if there is a corresponding value in the map.
static java.util.List sortClasses(java.util.Collection aClasses)
          Sorts the classes according to their subclass relationship.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTypeName

public static java.lang.String getTypeName(java.lang.Class aClass)
Returns the type name of the specified class. Arrays and inner classes are supported.

Returns:
The type name of the specified class. (required)

removeSubClasses

public static java.util.List removeSubClasses(java.util.Collection aClasses)
Removes all classes from the specified collection that have a (real) super class in the collection.

Parameters:
aClasses - The classes that are considered. (required)
Returns:
A list of the classes that have no (real) super classes in the specified collection. (required)

sortClasses

public static java.util.List sortClasses(java.util.Collection aClasses)
Sorts the classes according to their subclass relationship. Super classes are guaranteed to be in the list before their sub classes.

Parameters:
aClasses - The classes to sort. (required)
Returns:
The sorted classes. (required)

getWrapperClass

public static final java.lang.Class getWrapperClass(java.lang.Class aClass)

setMembers

public static void setMembers(java.lang.Object anObject,
                              java.util.Map aMap)
                       throws java.lang.Exception
Tries to set the members of an object by their setter-methods if there is a corresponding value in the map.

The method proceeds by iterating over all methods of the object selecting those whose method names have the prefix "set". The member name is derived as the remaining part of the method name (possibly an upper and lower case first letter). For each such method it is tested the map contains a value for the corresponding member name and if the method needs a single parameter to set the member. If both conditions are true, it is tested if the value in the map is assignment compatible with the parameter class of the setter method. If this is not the case than it is tried to construct a suitable parameter object from the value. Finally the setter method is called.

Parameters:
anObject - (required).
aMap - (required). The values that are set are removed from the map. Therefore the success of the method may be checked by testing the map for emptiness.
Throws:
java.lang.Exception