org.springframework.richclient.util
Class ClassUtils

java.lang.Object
  extended by org.springframework.richclient.util.ClassUtils

public class ClassUtils
extends Object

Misc static utility functions for java classes.

Author:
Keith Donald, Jim Moore

Method Summary
static Class classForName(String name)
          Load the class with the specified name.
static Class convertPrimitiveToWrapper(Class clazz)
          Gets the equivalent class to convert to if the given clazz is a primitive.
static Method findMethod(String methodName, Class clazz, Class[] parmTypes)
           
static String getClassFieldNameWithValue(Class clazz, Object value)
          Returns the qualified class field name with the specified value.
static Object getFieldValue(String qualifiedFieldName)
          Gets the field value for the specified qualified field name.
static Class getPropertyClass(Class parentClass, String propertyName)
          Returns the class of the property.
static Method getStaticMethod(String name, Class locatorClass, Class[] args)
           
static Object getValueFromMapForClass(Class typeClass, Map classMap)
          Given a Mapwhere the keys are Classes, search the map for the closest match of the key to the typeClass.
static void initializeClass(Class clazz)
          Intializes the specified class if not initialized already.
static boolean isAProperty(Class theClass, String propertyName)
          Is the given name a property in the class? In other words, does it have a setter and/or a getter method?
static boolean isPrimitiveArray(Class clazz)
          Check if the given class represents a primitive array.
static boolean isSimpleScalar(Class clazz)
          Does the provided bean class represent a simple scalar property? A simple scalar property is considered a value property; that is, it is not another bean.
static String qualifier(String qualifiedName)
          Returns the qualifier for a name separated by dots.
static String unqualify(Class clazz)
          Returns the unqualified class name of the specified class.
static String unqualify(String qualifiedName)
           
static String unqualify(String qualifiedName, char separator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initializeClass

public static void initializeClass(Class clazz)
Intializes the specified class if not initialized already. This is required for EnumUtils if the enum class has not yet been loaded.


getClassFieldNameWithValue

public static String getClassFieldNameWithValue(Class clazz,
                                                Object value)
Returns the qualified class field name with the specified value. For example, with a class defined with a static field "NORMAL" with value = "0", passing in "0" would return: className.NORMAL.

Returns:
The qualified field.

getFieldValue

public static Object getFieldValue(String qualifiedFieldName)
Gets the field value for the specified qualified field name.


classForName

public static Class classForName(String name)
                          throws ClassNotFoundException
Load the class with the specified name.

Parameters:
name -
Returns:
The loaded class.
Throws:
ClassNotFoundException

findMethod

public static Method findMethod(String methodName,
                                Class clazz,
                                Class[] parmTypes)

unqualify

public static String unqualify(String qualifiedName)

unqualify

public static String unqualify(Class clazz)
Returns the unqualified class name of the specified class.

Parameters:
clazz - the class to get the name for
Returns:
The unqualified, short name.

unqualify

public static String unqualify(String qualifiedName,
                               char separator)

qualifier

public static String qualifier(String qualifiedName)
Returns the qualifier for a name separated by dots. The qualified part is everything up to the last dot separator.

Parameters:
qualifiedName - The qualified name.
Returns:
The qualifier portion.

isPrimitiveArray

public static boolean isPrimitiveArray(Class clazz)
Check if the given class represents a primitive array.


isSimpleScalar

public static boolean isSimpleScalar(Class clazz)
Does the provided bean class represent a simple scalar property? A simple scalar property is considered a value property; that is, it is not another bean. Examples include primitives, primitive wrappers, Enums, and Strings.


getStaticMethod

public static Method getStaticMethod(String name,
                                     Class locatorClass,
                                     Class[] args)

convertPrimitiveToWrapper

public static Class convertPrimitiveToWrapper(Class clazz)
Gets the equivalent class to convert to if the given clazz is a primitive.

Parameters:
clazz - Class to examin.
Returns:
the class to convert to or the inputted clazz.

getValueFromMapForClass

public static Object getValueFromMapForClass(Class typeClass,
                                             Map classMap)
Given a Mapwhere the keys are Classes, search the map for the closest match of the key to the typeClass. This is extremely useful to support polymorphism (and an absolute requirement to find proxied classes where classes are acting as keys in a map).

For example: If the Map has keys of Number.class and String.class, using a typeClass of Long.class will find the Number.class entry and return its value.

When doing the search, it looks for the most exact match it can, giving preference to interfaces over class inheritance. As a performance optimiziation, if it finds a match it stores the derived match in the map so it does not have to be derived again.

Parameters:
typeClass - the kind of class to search for
classMap - the map where the keys are of type Class
Returns:
null only if it can't find any match

isAProperty

public static boolean isAProperty(Class theClass,
                                  String propertyName)
Is the given name a property in the class? In other words, does it have a setter and/or a getter method?

Parameters:
theClass - the class to look for the property in
propertyName - the name of the property
Returns:
true if there is either a setter or a getter for the property
Throws:
IllegalArgumentException - if either argument is null

getPropertyClass

public static Class getPropertyClass(Class parentClass,
                                     String propertyName)
                              throws IllegalArgumentException
Returns the class of the property.

For example, getPropertyClass(JFrame.class, "size") would return the java.awt.Dimension class.

Parameters:
parentClass - the class to look for the property in
propertyName - the name of the property
Returns:
the class of the property; never null
Throws:
IllegalArgumentException - if either argument is null
IllegalArgumentException - propertyName is not a property of parentClass


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.