ProgramixGenericLib v5.0.1

com.programix.util
Class ReflectTools

java.lang.Object
  extended by com.programix.util.ReflectTools

public class ReflectTools
extends Object

Commonly needed utilities for working with Java's Reflection mechanism.


Nested Class Summary
static class ReflectTools.ReflectException
          Used to indicate that something went wrong in one of the ReflectTools functions.
 
Method Summary
static void checkType(Object obj, Class<?> targetType)
          Checks type of obj and throws an exception if it is not the specified type or if the reference is null.
static void checkType(Object obj, Class<?> targetType, boolean allowNull)
          Checks to see if the object pointed to by obj is an instance of the specified target type.
static
<T> T
construct(String className, Class<T> targetType)
          Used to lookup and instantiate the specified class using the class's zero-argument constuctor and to validate that it can be typecast into the target type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

construct

public static <T> T construct(String className,
                              Class<T> targetType)
                   throws ReflectTools.ReflectException
Used to lookup and instantiate the specified class using the class's zero-argument constuctor and to validate that it can be typecast into the target type.

Parameters:
className - the class to lookup and construct
targetType - the type to check to see if the constructed object can be cast into.
Throws:
ReflectTools.ReflectException - if the requested class can not be found, or if it doesn't have a public zero-argument constructor, or if the constructed object can't be typecast into the target type, or if either parameter is null.

checkType

public static void checkType(Object obj,
                             Class<?> targetType,
                             boolean allowNull)
                      throws ReflectTools.ReflectException
Checks to see if the object pointed to by obj is an instance of the specified target type. If allowNull is true, no exception is thrown if obj is null.

Throws:
ReflectTools.ReflectException

checkType

public static void checkType(Object obj,
                             Class<?> targetType)
                      throws ReflectTools.ReflectException
Checks type of obj and throws an exception if it is not the specified type or if the reference is null. Calls checkType(Object, Class, boolean) with allowNull set to false.

Throws:
ReflectTools.ReflectException

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.