org.apache.lucene.gdata.utils
Class ReflectionUtils

java.lang.Object
  extended by org.apache.lucene.gdata.utils.ReflectionUtils

public class ReflectionUtils
extends Object

A collection of static helper methods solve common reflection problems

Author:
Simon Willnauer

Nested Class Summary
static class ReflectionUtils.ReflectionException
          Exception wrapper for all thrown exception in the ReflectionUtils methods
 
Constructor Summary
ReflectionUtils()
           
 
Method Summary
static boolean canCreateInstance(Class clazz)
          This method calls Class.newInstance() to get a new instance.
static boolean extendsType(Class typeToCheck, Class superType)
          Check if the given type extends a given super type
static
<T> T
getDefaultInstance(Class<T> clazz)
           
static Class getPrimitiveWrapper(Class primitive)
          Returns the wrapper type for the given primitive type.
static boolean hasDesiredConstructor(Class type, Class[] parameter)
           
static boolean implementsType(Class typeToCheck, Class superType)
          Check if the given type implements a given super type
static boolean isTypeOf(Class typeToCheck, Class superType)
          This method combines the extendsType and implementsType and checks interfaces and classes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtils

public ReflectionUtils()
Method Detail

implementsType

public static boolean implementsType(Class typeToCheck,
                                     Class superType)
Check if the given type implements a given super type

Parameters:
typeToCheck - - type supposed to implement an interface
superType - - the interface to be implemented by the type to check
Returns:
true if and only if the super type is above in the type hierarchy of the given type, otherwise false

extendsType

public static boolean extendsType(Class typeToCheck,
                                  Class superType)
Check if the given type extends a given super type

Parameters:
typeToCheck - - type supposed to extend an specific type
superType - - the type to be extended by the type to check
Returns:
true if and only if the super type is above in the type hierarchy of the given type, otherwise false

isTypeOf

public static boolean isTypeOf(Class typeToCheck,
                               Class superType)
This method combines the extendsType and implementsType and checks interfaces and classes

Parameters:
typeToCheck - - type supposed to extend / implement an specific type
superType - - the type to be extended / implemented by the type to check
Returns:
true if and only if the super type is above in the type hierarchy of the given type, otherwise false

hasDesiredConstructor

public static boolean hasDesiredConstructor(Class type,
                                            Class[] parameter)
Parameters:
type - - the type to check
parameter - - the constructor parameter
Returns:
true if and only if the type has a visible constructor with the desired parameters

getDefaultInstance

public static <T> T getDefaultInstance(Class<T> clazz)
Type Parameters:
T - the type of the class to instantiate
Parameters:
clazz - - class object of the type
Returns:
a new instance of T

canCreateInstance

public static boolean canCreateInstance(Class clazz)
This method calls Class.newInstance() to get a new instance. Use with care!

Parameters:
clazz - - the class to instantiate
Returns:
true if an instance could be created, otherwise false;

getPrimitiveWrapper

public static final Class getPrimitiveWrapper(Class primitive)
Returns the wrapper type for the given primitive type. Wrappers can be easily instantiated via reflection and will be boxed by the VM

Parameters:
primitive - - the primitive type
Returns:
- the corresponding wrapper type


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.