org.dbmaintain.util
Class ReflectionUtils

java.lang.Object
  extended by org.dbmaintain.util.ReflectionUtils

public class ReflectionUtils
extends Object

Utility methods that use reflection for instance creation or class inspection.

Author:
Filip Neven, Tim Ducheyne

Constructor Summary
ReflectionUtils()
           
 
Method Summary
static
<T> T
createInstanceOfType(Class<T> type, boolean bypassAccessibility, Class<?>[] parameterTypes, Object[] parameters)
          Creates an instance of the given type
static
<T> T
createInstanceOfType(String className, boolean bypassAccessibility)
          Creates an instance of the class with the given name.
static
<T> Class<T>
getClassWithName(String className)
          Gets the class for the given name.
 
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

createInstanceOfType

public static <T> T createInstanceOfType(String className,
                                         boolean bypassAccessibility)
Creates an instance of the class with the given name. The class's no argument constructor is used to create an instance.

Parameters:
className - The name of the class, not null
bypassAccessibility - If true, no exception is thrown if the parameterless constructor is not public
Returns:
An instance of this class
Throws:
DbMaintainException - if the class could not be found or no instance could be created

createInstanceOfType

public static <T> T createInstanceOfType(Class<T> type,
                                         boolean bypassAccessibility,
                                         Class<?>[] parameterTypes,
                                         Object[] parameters)
Creates an instance of the given type

Type Parameters:
T - The type of the instance
Parameters:
type - The type of the instance
bypassAccessibility - If true, no exception is thrown if the parameterless constructor is not public
parameterTypes - Types of the constructor arguments
parameters - Constructor arguments
Returns:
An instance of this type
Throws:
DbMaintainException - If an instance could not be created

getClassWithName

public static <T> Class<T> getClassWithName(String className)
Gets the class for the given name. An DbMaintainException is thrown when the class could not be loaded.

Parameters:
className - The name of the class, not null
Returns:
The class, not null


Copyright © 2011. All Rights Reserved.