net.sf.xbus.base.core.reflection
Class ReflectionSupport

java.lang.Object
  extended by net.sf.xbus.base.core.reflection.ReflectionSupport

public class ReflectionSupport
extends java.lang.Object

ReflectionSupport provides methods to create objects and call methods with the reflection API more easy.


Constructor Summary
ReflectionSupport()
           
 
Method Summary
static java.lang.Object callMethod(java.lang.String methodname, java.lang.Object inObject, java.lang.Class[] parameterTypes, java.lang.Object[] arguments)
          Calls a method with the help of the reflection API.
static java.lang.Class classForName(java.lang.String className)
          Returns the Class object associated with the class or interface with the given string name.
static java.lang.Object createObject(java.lang.String classname)
          Create an object of the class with the given name.
static java.lang.Object createObject(java.lang.String classname, java.lang.Class[] conArgsClass, java.lang.Object[] conArgs)
          Creates an object of the class with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionSupport

public ReflectionSupport()
Method Detail

createObject

public static java.lang.Object createObject(java.lang.String classname)
                                     throws XException
Create an object of the class with the given name. The class must have a constructor without parameters.

Parameters:
classname - fully qualified name of the class
Returns:
an object of the class with the given name
Throws:
XException - if the object cannot be created

createObject

public static java.lang.Object createObject(java.lang.String classname,
                                            java.lang.Class[] conArgsClass,
                                            java.lang.Object[] conArgs)
                                     throws XException
Creates an object of the class with the given name.

Parameters:
classname - fully qualified name of the class
conArgsClass - the parameter types for the constructor
conArgs - array of objects to be passed as arguments to the constructor call
Returns:
a new object created by calling the constructor this object represents
Throws:
XException - if the object cannot be created

classForName

public static java.lang.Class classForName(java.lang.String className)
                                    throws XException
Returns the Class object associated with the class or interface with the given string name.

Parameters:
className - the fully qualified name of the desired class
Returns:
the Class object for the class with the specified name
Throws:
XException - if the class cannot be found

callMethod

public static java.lang.Object callMethod(java.lang.String methodname,
                                          java.lang.Object inObject,
                                          java.lang.Class[] parameterTypes,
                                          java.lang.Object[] arguments)
                                   throws XException
Calls a method with the help of the reflection API.

Parameters:
methodname - the name of the method to be called
inObject - the object for which the method shall be called
parameterTypes - an array containing the classes of the parameters
arguments - an array with the parameters
Returns:
the result of the method call
Throws:
XException - if the method cannot be called