com.zmicer.utils
Class ReflexionUtils

java.lang.Object
  extended by com.zmicer.utils.ReflexionUtils

public class ReflexionUtils
extends Object

Utility class for working with reflexion mechanism

$Author:: zmicer $
$Rev:: 67 $
$Date:: 2007-08-28 21:37:07 #$


Field Summary
static org.apache.log4j.Logger LOG
          Logger instance.
static Pattern PATTERN
          Pattern to find the name of the method is currently running.
 
Constructor Summary
ReflexionUtils()
           
 
Method Summary
static String getBaseName(Class claz)
          Get the base name of the provided String - the name of the class.
static String getCallerFullClassName()
          note [zmicer]: only for the test purposes (for JPatterns test engine allowing to setup the props/xml environment per the folders)
static String getClassNameOfArrayMembers(Class claz)
          Get the full name of the class from instances of which the certain array object class of which is passed as the single input param.
static boolean instanceOf(Object obj, Class<?> baseClass)
          Analog of the instance of construction (e.g. obj instanceof Serializable)
static Object reflectObject(String className, boolean throwIfNotInitialized)
          Get the instance of Object using the provided full class name.
static Map<String,Object> reflectObjects(Map<String,String> info, boolean throwIfNotInitialized)
          Get the instance of Object using the provided full class name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.log4j.Logger LOG
Logger instance.


PATTERN

public static final Pattern PATTERN
Pattern to find the name of the method is currently running.

Constructor Detail

ReflexionUtils

public ReflexionUtils()
Method Detail

reflectObject

public static Object reflectObject(String className,
                                   boolean throwIfNotInitialized)
Get the instance of Object using the provided full class name.
All the exception may appear during reflexion are catched and logged. In this case null is returned.

Parameters:
className - the full class name ro be reflected, Can not be null (otherwise IllegalArgumentException would appear).
throwIfNotInitialized - if this is true we throw exception (IllegalStateException) if some implementations can not be instantiated
Returns:
Object, reflected object

reflectObjects

public static Map<String,Object> reflectObjects(Map<String,String> info,
                                                boolean throwIfNotInitialized)
Get the instance of Object using the provided full class name.
All the exception may appear during reflexion are catched and logged. In this case null is returned as the value.

Parameters:
info - the map with #key type of the object to be reflected #value. Can not contains null as neither key or value Can not be null (otherwise IllegalArgumentException would appear).
throwIfNotInitialized - if this is true we throw exception (IllegalStateException) if some implementations can not be instantiated
Returns:
map of the relflected objects with the appropaite keys

getBaseName

public static String getBaseName(Class claz)
Get the base name of the provided String - the name of the class.

Parameters:
claz - Class instance. Can not be null (otherwise IllegalArgumentException would appear).
Returns:
String, the base name of the class (without the packages pathes)

getClassNameOfArrayMembers

public static String getClassNameOfArrayMembers(Class claz)
Get the full name of the class from instances of which the certain array object class of which is passed as the single input param.

todo [zmicer]: please clarify if this method to determine this full class name is correct for another versions of Java JDK. May be there are another ways to clarify this.

Example: imagine we have the array of the Global object. This appropriate class for this array would have the name "[Lcom.sourceforge.jpatterns.schema.Global;", and String we need is "com.sourceforge.jpatterns.schema.Global".

Parameters:
claz - Class of an array for which we need to determine the class of the objects this array stores. Can not be null (otherwise IllegalArgumentException would appear). In the case the class provided do not correspond to the array of objects the IllegalArgumentException would appear too.
Returns:
String, the full name of class instances of which are the members of the array class of which is passed to this method.

getCallerFullClassName

public static String getCallerFullClassName()
note [zmicer]: only for the test purposes (for JPatterns test engine allowing to setup the props/xml environment per the folders)

Returns:
the caller class full name.

instanceOf

public static boolean instanceOf(Object obj,
                                 Class<?> baseClass)
Analog of the instance of construction (e.g. obj instanceof Serializable)

Parameters:
obj - object to be checked. Can not be null (otherwise IllegalArgumentException would appear).
baseClass - base class (interface class) which should be used for the determining if obj is instace of this class Can not be null (otherwise IllegalArgumentException would appear).
Returns:
the true if this is "instance of" of the provided class (it is called base class here)


Copyright © 2007 jzmicer.team. All Rights Reserved.