Package de.intarsys.tools.reflect
Class ObjectTools
java.lang.Object
de.intarsys.tools.reflect.ObjectTools
A tool class for convenient object related tasks.
This tool contains some simple reflection implementations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static Object
protected static Object
basicInsert
(Object object, String name, Object value) protected static Object
basicInvoke
(Object object, String name, Object... values) protected static Object
basicRemove
(Object object, String name, Object value) protected static Object
protected static boolean
checkCandidate
(Method method, String methodName, Class[] pClasses) protected static boolean
checkCandidateClass
(Class mClass, Class pClass) protected static boolean
checkCandidateClasses
(Class[] mClasses, Class[] pClasses) 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".protected static Method
findAnyMethod
(Class clazz, String name, Class... classes) static Method
findGetter
(Object object, String name) static Method
findInserter
(Object object, String attribute, Object value) protected static Method
findMatchingMethod
(Class clazz, String name, Class[] classes) 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) protected static Method
findSimpleMethod
(Class clazz, String name, Class... classes) static Object
Get the value for fieldname
inobject
.static Object
Insertvalue
in the relation fieldname
inobject
.static Object
Invoke methodname
inobject
.static Object
Removevalue
in the relation fieldname
inobject
.static Object
Set fieldname
inobject
tovalue
.
-
Field Details
-
GET_PREFIX
- See Also:
-
IS_PREFIX
- See Also:
-
-
Constructor Details
-
ObjectTools
public ObjectTools()
-
-
Method Details
-
basicGet
- Throws:
FieldException
-
basicInsert
- Throws:
FieldException
-
basicInvoke
protected static Object basicInvoke(Object object, String name, Object... values) throws MethodException - Throws:
MethodException
-
basicRemove
- Throws:
FieldException
-
basicSet
- Throws:
FieldException
-
checkCandidate
-
checkCandidateClass
-
checkCandidateClasses
-
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:
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
-
findAnyMethod
protected static Method findAnyMethod(Class clazz, String name, Class... classes) throws MethodException - Throws:
MethodException
-
findGetter
- Throws:
MethodException
-
findInserter
public static Method findInserter(Object object, String attribute, Object value) throws MethodException - Throws:
MethodException
-
findMatchingMethod
protected static Method findMatchingMethod(Class clazz, String name, Class[] classes) throws MethodException - Throws:
MethodException
-
findMethod
public static Method findMethod(Object object, String methodName, Object... parameters) 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
-
findSimpleMethod
protected static Method findSimpleMethod(Class clazz, String name, Class... classes) throws MethodException - Throws:
MethodException
-
get
Get the value for fieldname
inobject
.- Parameters:
object
-name
-- Returns:
- the value for field
name
inobject
. - Throws:
IllegalAccessException
InvocationTargetException
NoSuchFieldException
FieldException
-
insert
Insertvalue
in the relation fieldname
inobject
. 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
Invoke methodname
inobject
. The result of the invocation is returned.- Parameters:
object
-name
-values
-- Returns:
- The result of the invocation is returned.
- Throws:
MethodException
-
remove
Removevalue
in the relation fieldname
inobject
. 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
Set fieldname
inobject
tovalue
. 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
-