intarsys runtime library

de.intarsys.tools.reflect
Class ObjectTools

java.lang.Object
  extended by de.intarsys.tools.reflect.ObjectTools

public class ObjectTools
extends Object

A tool class for convenient object related tasks.

This tool contains some simple reflection implementations.


Field Summary
static String GET_PREFIX
           
static String IS_PREFIX
           
 
Constructor Summary
ObjectTools()
           
 
Method Summary
static
<T> T
createObject(Class clazz, Class<T> expectedClass)
          Create a new instance of Class "class"
static
<T> T
createObject(Class clazz, Class<T> expectedClass, Class[] parameterTypes, Object[] parameters)
          Create a new instance of Class "class"
static
<T> T
createObject(String className, Class<T> expectedClass, ClassLoader classLoader)
          Create a new instance of Class "className" via "classLoader".
static Method findGetter(Object object, String name)
           
static Method findInserter(Object object, String attribute, Object value)
           
static Method findMethod(Object object, String methodName, Object... parameters)
           
static Method findRemover(Object object, String attribute, Object value)
           
static Method findSetter(Object object, String attribute, Object value)
           
static Object get(Object object, String name)
          Get the value for field name in object.
static Object insert(Object object, String name, Object value)
          Insert value in the relation field name in object.
static Object invoke(Object object, String name, Object... values)
          Invoke method name in object.
static Object remove(Object object, String name, Object value)
          Remove value in the relation field name in object.
static Object set(Object object, String name, Object value)
          Set field name in object to value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET_PREFIX

public static final String GET_PREFIX
See Also:
Constant Field Values

IS_PREFIX

public static final String IS_PREFIX
See Also:
Constant Field Values
Constructor Detail

ObjectTools

public ObjectTools()
Method Detail

createObject

public static <T> T createObject(Class clazz,
                                 Class<T> expectedClass)
                      throws ObjectCreationException
Create a new instance of Class "class"

Parameters:
className -
expectedClass -
classLoader -
Returns:
The new instance
Throws:
ObjectCreationException

createObject

public static <T> T createObject(Class clazz,
                                 Class<T> expectedClass,
                                 Class[] parameterTypes,
                                 Object[] parameters)
                      throws ObjectCreationException
Create a new instance of Class "class"

Parameters:
className -
expectedClass -
parameterTypes -
parameters -
Returns:
The new instance
Throws:
ObjectCreationException

createObject

public static <T> T createObject(String className,
                                 Class<T> expectedClass,
                                 ClassLoader classLoader)
                      throws ObjectCreationException
Create a new instance of Class "className" via "classLoader".

Parameters:
className -
expectedClass -
classLoader -
Returns:
The new instance
Throws:
ObjectCreationException

findGetter

public static Method findGetter(Object object,
                                String name)
                         throws SecurityException,
                                NoSuchMethodException
Throws:
SecurityException
NoSuchMethodException

findInserter

public static Method findInserter(Object object,
                                  String attribute,
                                  Object value)
                           throws SecurityException,
                                  NoSuchMethodException
Throws:
SecurityException
NoSuchMethodException

findMethod

public static Method findMethod(Object object,
                                String methodName,
                                Object... parameters)
                         throws SecurityException,
                                NoSuchMethodException
Throws:
SecurityException
NoSuchMethodException

findRemover

public static Method findRemover(Object object,
                                 String attribute,
                                 Object value)
                          throws SecurityException,
                                 NoSuchMethodException
Throws:
SecurityException
NoSuchMethodException

findSetter

public static Method findSetter(Object object,
                                String attribute,
                                Object value)
                         throws SecurityException,
                                NoSuchMethodException
Throws:
SecurityException
NoSuchMethodException

get

public static Object get(Object object,
                         String name)
                  throws IllegalAccessException,
                         InvocationTargetException,
                         NoSuchFieldException
Get the value for field name in object.

Parameters:
object -
name -
Returns:
Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException

insert

public static Object insert(Object object,
                            String name,
                            Object value)
                     throws IllegalAccessException,
                            InvocationTargetException,
                            NoSuchFieldException
Insert value in the relation field name in object. The value that was really inserted is returned (if supported by the underlying object implementation). To be exact, the result of the insert method invoked is returned.

Parameters:
object -
name -
value -
Returns:
Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException

invoke

public static Object invoke(Object object,
                            String name,
                            Object... values)
                     throws IllegalAccessException,
                            InvocationTargetException,
                            SecurityException,
                            NoSuchMethodException,
                            NoSuchFieldException
Invoke method name in object. The result of the invocation is returned.

Parameters:
object -
name -
values -
Returns:
Throws:
IllegalAccessException
InvocationTargetException
SecurityException
NoSuchMethodException
NoSuchFieldException

remove

public static Object remove(Object object,
                            String name,
                            Object value)
                     throws IllegalAccessException,
                            InvocationTargetException,
                            NoSuchFieldException
Remove value in the relation field name in object. The value that was removed is returned (if supported by the underlying object implementation). To be exact, the result of the remove method invoked is returned.

Parameters:
object -
name -
value -
Returns:
Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException

set

public static Object set(Object object,
                         String name,
                         Object value)
                  throws IllegalAccessException,
                         InvocationTargetException,
                         NoSuchFieldException
Set field name in object to value. The old value is returned (if supported by the underlying object implementation). To be exact, the result of the setter method invoked is returned.

Parameters:
object -
name -
value -
Returns:
Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException

intarsys runtime library

Copyright © 2008 intarsys consulting GmbH. All Rights Reserved.