com.mizar.commons.lang
Class ReflectUtils

java.lang.Object
  extended by com.mizar.commons.lang.ReflectUtils

public class ReflectUtils
extends java.lang.Object


Constructor Summary
protected ReflectUtils()
           
 
Method Summary
static java.util.HashMap<java.lang.String,java.lang.reflect.Type> buildMethodMap(java.lang.Class klass)
           
static java.util.HashMap<java.lang.String,java.lang.reflect.Type> buildMethodMap(java.lang.Object obj)
           
static java.util.HashMap<java.lang.String,java.lang.Object> buildPropertyMap(java.lang.Object obj)
           
static java.util.HashMap<java.lang.String,java.lang.Object> buildPropertyMap(java.lang.Object obj, boolean string, java.util.List<java.lang.String> properties)
          The method will return a HashMap of property names and value for all properties assignable to Number, Boolean, or CharSequence
static java.util.HashMap<java.lang.String,java.lang.Object> buildPropertyMap(java.lang.Object obj, java.util.List<java.lang.String> properties)
           
static java.util.HashMap<java.lang.String,java.lang.String> buildPropertyStringMap(java.lang.Object obj)
           
static java.util.HashMap<java.lang.String,java.lang.String> buildPropertyStringMap(java.lang.Object obj, java.util.List<java.lang.String> properties)
           
static void castFromSuperclass(java.lang.Object subObject, java.lang.Object superObject)
          This method is a work-around for the fact that you cannot cast a superclass to a subclass.
static void castToSuperclass(java.lang.Object subObject, java.lang.Object superObject)
           
static void copy(java.lang.Object a, java.lang.Object b)
           
static boolean equal(java.lang.Object o1, java.lang.Object o2)
           
static java.lang.Class getAnnotatedSuperClass(java.lang.Class subClass, java.lang.Class annotationClass)
           
static java.lang.String getAssumedMethodName(java.lang.String propertyName)
          Deprecated. 
static java.lang.String getAssumedPropertyName(java.lang.reflect.Method method)
           
static java.lang.String getAssumedPropertyName(java.lang.String methodName)
           
static java.lang.Class getClass(java.lang.Object caller, java.lang.String fullClassName)
           
static java.lang.Object getCurrentInstance(java.lang.Object caller, java.lang.String fullClassName)
           
static java.lang.Object getCurrentInstance(java.lang.Object caller, java.lang.String fullClassName, java.lang.Class[] parameters)
           
static java.lang.reflect.Method getCurrentInstanceMethod(java.lang.Object caller, java.lang.String fullClassName)
           
static java.lang.reflect.Method getGetter(java.lang.Class clazz, java.lang.String propertyName)
           
static java.lang.reflect.Method getMethod(java.lang.Class beanClass, java.lang.String name, java.lang.Class[] parameters)
           
static java.util.ArrayList<java.lang.reflect.Method> getMethods(java.lang.Class beanClass, java.lang.String name)
           
static java.lang.Class getReturnType(java.lang.Class beanClass, java.lang.String property)
           
static java.lang.reflect.Method getSetter(java.lang.Class clazz, java.lang.String propertyName)
           
static java.lang.String getSimpleName(java.lang.String fullClassName)
          The method will remove the package information from a full class name.
static java.lang.String getStackDump(int numberOfCallsToIgnore)
           
static java.lang.Object getValue(java.lang.Object bean, java.lang.String propertyExpression)
           
static boolean isSimpleType(java.lang.Object object)
           
static boolean looksLikeGetter(java.lang.reflect.Method method)
           
static boolean looksLikeGetter(java.lang.String methodName)
           
static void main(java.lang.String[] args)
           
static java.lang.Object newInstance(java.lang.Class clazz)
           
static java.lang.Object newInstance(java.lang.Class clazz, java.lang.Class[] parameters)
           
static void setValue(java.lang.Object bean, java.lang.String property, java.lang.Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectUtils

protected ReflectUtils()
Method Detail

getClass

public static java.lang.Class getClass(java.lang.Object caller,
                                       java.lang.String fullClassName)
                                throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getAnnotatedSuperClass

public static java.lang.Class getAnnotatedSuperClass(java.lang.Class subClass,
                                                     java.lang.Class annotationClass)
Parameters:
subClass - a class to start searching for the first parent that contains annotationClass
annotationClass -
Returns:

newInstance

public static java.lang.Object newInstance(java.lang.Class clazz)
                                    throws java.lang.InstantiationException,
                                           java.lang.IllegalArgumentException,
                                           java.lang.reflect.InvocationTargetException,
                                           java.lang.IllegalAccessException,
                                           java.lang.SecurityException,
                                           java.lang.NoSuchMethodException
Throws:
java.lang.InstantiationException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.SecurityException
java.lang.NoSuchMethodException

newInstance

public static java.lang.Object newInstance(java.lang.Class clazz,
                                           java.lang.Class[] parameters)
                                    throws java.lang.InstantiationException,
                                           java.lang.IllegalArgumentException,
                                           java.lang.reflect.InvocationTargetException,
                                           java.lang.IllegalAccessException,
                                           java.lang.SecurityException,
                                           java.lang.NoSuchMethodException
Throws:
java.lang.InstantiationException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.SecurityException
java.lang.NoSuchMethodException

getCurrentInstanceMethod

public static java.lang.reflect.Method getCurrentInstanceMethod(java.lang.Object caller,
                                                                java.lang.String fullClassName)
                                                         throws java.lang.ClassNotFoundException,
                                                                java.lang.NoSuchMethodException
Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException

getCurrentInstance

public static java.lang.Object getCurrentInstance(java.lang.Object caller,
                                                  java.lang.String fullClassName)
                                           throws java.lang.ClassNotFoundException,
                                                  java.lang.NoSuchMethodException
Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException

getCurrentInstance

public static java.lang.Object getCurrentInstance(java.lang.Object caller,
                                                  java.lang.String fullClassName,
                                                  java.lang.Class[] parameters)
                                           throws java.lang.ClassNotFoundException,
                                                  java.lang.NoSuchMethodException
Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException

castFromSuperclass

public static void castFromSuperclass(java.lang.Object subObject,
                                      java.lang.Object superObject)
This method is a work-around for the fact that you cannot cast a superclass to a subclass. If the class of Object a has a superclass that is b; if (a.getClass().getSuperclass().isinstance(b)) then all the contents of all the non-Final fields of b are copied to a.

Parameters:
subObject - an Object that is a direct subclass of b
superObject - an Object that is an immediate superclass of a If an IllegalAccessException occurs this method does a printStackTrace()

castToSuperclass

public static void castToSuperclass(java.lang.Object subObject,
                                    java.lang.Object superObject)

copy

public static void copy(java.lang.Object a,
                        java.lang.Object b)

getAssumedPropertyName

public static java.lang.String getAssumedPropertyName(java.lang.String methodName)

getAssumedMethodName

@Deprecated
public static java.lang.String getAssumedMethodName(java.lang.String propertyName)
Deprecated. 


getGetter

public static java.lang.reflect.Method getGetter(java.lang.Class clazz,
                                                 java.lang.String propertyName)

getReturnType

public static java.lang.Class getReturnType(java.lang.Class beanClass,
                                            java.lang.String property)

getValue

public static java.lang.Object getValue(java.lang.Object bean,
                                        java.lang.String propertyExpression)
Parameters:
bean - the object to find the property value for
propertyExpression - may be "prop" or "parent.prop" or "parent.grandparent.prop", etc.
Returns:
the value of bean.getProperty()

getSetter

public static java.lang.reflect.Method getSetter(java.lang.Class clazz,
                                                 java.lang.String propertyName)

setValue

public static void setValue(java.lang.Object bean,
                            java.lang.String property,
                            java.lang.Object value)

getAssumedPropertyName

public static java.lang.String getAssumedPropertyName(java.lang.reflect.Method method)

looksLikeGetter

public static boolean looksLikeGetter(java.lang.String methodName)

looksLikeGetter

public static boolean looksLikeGetter(java.lang.reflect.Method method)

isSimpleType

public static boolean isSimpleType(java.lang.Object object)
Parameters:
object -
Returns:
true if object's class is assignable by Number, CharSequence, or Boolean

buildMethodMap

public static java.util.HashMap<java.lang.String,java.lang.reflect.Type> buildMethodMap(java.lang.Object obj)

buildMethodMap

public static java.util.HashMap<java.lang.String,java.lang.reflect.Type> buildMethodMap(java.lang.Class klass)

buildPropertyMap

public static java.util.HashMap<java.lang.String,java.lang.Object> buildPropertyMap(java.lang.Object obj,
                                                                                    boolean string,
                                                                                    java.util.List<java.lang.String> properties)
The method will return a HashMap of property names and value for all properties assignable to Number, Boolean, or CharSequence

Parameters:
obj - an object to build a property map from
string - if true then return a value object of type String
properties - an optional list of property names to include, excluding all others.
Returns:
See Also:
isSimpleType(java.lang.Object)

buildPropertyMap

public static java.util.HashMap<java.lang.String,java.lang.Object> buildPropertyMap(java.lang.Object obj)
Parameters:
obj - an object to build a property map from
Returns:

buildPropertyStringMap

public static java.util.HashMap<java.lang.String,java.lang.String> buildPropertyStringMap(java.lang.Object obj)
Parameters:
obj - an object to build a property map from
Returns:

buildPropertyMap

public static java.util.HashMap<java.lang.String,java.lang.Object> buildPropertyMap(java.lang.Object obj,
                                                                                    java.util.List<java.lang.String> properties)
Parameters:
obj - an object to build a property map from
properties - an optional list of property names to include, excluding all others.
Returns:

buildPropertyStringMap

public static java.util.HashMap<java.lang.String,java.lang.String> buildPropertyStringMap(java.lang.Object obj,
                                                                                          java.util.List<java.lang.String> properties)
Parameters:
obj - an object to build a property map from
properties - an optional list of property names to include, excluding all others.
Returns:

getStackDump

public static java.lang.String getStackDump(int numberOfCallsToIgnore)
Parameters:
numberOfCallsToIgnore - currently ignored -- reserved for future use
Returns:
the stack dump

getSimpleName

public static java.lang.String getSimpleName(java.lang.String fullClassName)
The method will remove the package information from a full class name. It does so be looking for the last period character in fullClassName and returning the remainder of the String. It is safe to pass a simpleName, with no period character, the method will just return the input value.

Parameters:
fullClassName -
Returns:
the simple class name.

getMethods

public static java.util.ArrayList<java.lang.reflect.Method> getMethods(java.lang.Class beanClass,
                                                                       java.lang.String name)

getMethod

public static java.lang.reflect.Method getMethod(java.lang.Class beanClass,
                                                 java.lang.String name,
                                                 java.lang.Class[] parameters)

main

public static void main(java.lang.String[] args)

equal

public static boolean equal(java.lang.Object o1,
                            java.lang.Object o2)