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 Object basicGet(Object object, String name)
           
static Object basicInsert(Object object, String name, Object value)
           
static Object basicInvoke(Object object, String name, Object... values)
           
static Object basicRemove(Object object, String name, Object value)
           
static Object basicSet(Object object, String name, Object value)
           
static Object convert(Object value, String typeName, ClassLoader classLoader)
           
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 findMethodPrefixed(Object object, String methodPrefix, Object... parameters)
           
static Method findRegister(Object object, Object value)
           
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 boolean isAssignable(Class target, Class source)
           
static Object register(Object registry, Object value)
           
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

basicGet

public static Object basicGet(Object object,
                              String name)
                       throws FieldException
Throws:
FieldException

basicInsert

public static Object basicInsert(Object object,
                                 String name,
                                 Object value)
                          throws FieldException
Throws:
FieldException

basicInvoke

public static Object basicInvoke(Object object,
                                 String name,
                                 Object... values)
                          throws MethodException
Throws:
MethodException

basicRemove

public static Object basicRemove(Object object,
                                 String name,
                                 Object value)
                          throws FieldException
Throws:
FieldException

basicSet

public static Object basicSet(Object object,
                              String name,
                              Object value)
                       throws FieldException
Throws:
FieldException

convert

public static Object convert(Object value,
                             String typeName,
                             ClassLoader classLoader)
                      throws ObjectCreationException
Throws:
ObjectCreationException

createObject

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

Parameters:
clazz -
expectedClass -
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:
clazz -
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 MethodException
Throws:
MethodException

findInserter

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

findMethod

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

findMethodPrefixed

public static Method findMethodPrefixed(Object object,
                                        String methodPrefix,
                                        Object... parameters)
                                 throws MethodException
Throws:
MethodException

findRegister

public static Method findRegister(Object object,
                                  Object value)
                           throws MethodException
Throws:
MethodException

findRemover

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

findSetter

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

get

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

Parameters:
object -
name -
Returns:
the value for field name in object.
Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException
FieldException

insert

public static Object insert(Object object,
                            String name,
                            Object value)
                     throws FieldException
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:
the result of the insert method invoked is returned.
Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException
FieldException

invoke

public static Object invoke(Object object,
                            String name,
                            Object... values)
                     throws MethodException
Invoke method name in object. The result of the invocation is returned.

Parameters:
object -
name -
values -
Returns:
The result of the invocation is returned.
Throws:
MethodException

isAssignable

public static boolean isAssignable(Class target,
                                   Class source)

register

public static Object register(Object registry,
                              Object value)
                       throws MethodException
Throws:
MethodException

remove

public static Object remove(Object object,
                            String name,
                            Object value)
                     throws FieldException
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:
the result of the remove method invoked is returned.
Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException
FieldException

set

public static Object set(Object object,
                         String name,
                         Object value)
                  throws FieldException
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:
the result of the setter method invoked is returned.
Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException
FieldException

intarsys runtime library

Copyright © 2012 intarsys consulting GmbH. All Rights Reserved.