@NotStorableClass public final class HelperReflect extends Object
Modifier and Type | Method and Description |
---|---|
int |
arrayLength(Object array) |
void |
assertNotNullField(Object object,
ClassInfoFactory classInfoFactory)
assert that field annotated assert not null are not null
used for debug |
FieldInfo |
createFieldInfo(IClassInfoFactory classInfoFactory,
Field field) |
DeclaredFields |
declaredFieldsByReflection(Class<?> classForField,
IClassInfoFactory classInfoFactory)
get all declared fields to persist or not for a class using recursive
reflection on class and mother class
|
Object |
getArrayElement(Object array,
int index) |
Object |
getFieldValue(Object object,
FieldInfo fieldInfo,
boolean checkAssertNotNull)
Returns the value of the field represented by this
FieldInfo
, on the specified object. |
static HelperReflect |
getInstance() |
Object |
invokeMethod(Class<?> objectClass,
String methodName,
Object objectForInvoke,
Class<?>[] parameterTypes,
Object[] args) |
Object |
invokeMethod(Object objectForInvoke,
Method method,
Object[] args) |
Object |
invokeStaticMethod(Class<?> objectClass,
String methodName,
Class<?>[] parameterTypes,
Object[] args) |
Enum<?> |
newEnumInstance(Class<?> enumClass,
String constantName) |
Object |
newInstanceConstruct(Class<?> objectClass,
Class<?>[] parameterTypes,
Object[] initargs)
create a new instance
The parameterTypes parameter is an array of
Class objects that identify the constructor's formal
parameter types, in declared order. |
Object |
newInstanceDefaultConstructor(Class<?> objectClass) |
Object |
newInstanceNoConstruction(Class<?> objectClass)
create a new proxy instance not invoking constructor
|
void |
setAlwaysAcceptNullField(boolean alwaysAcceptNullField) |
void |
setArrayElement(Object array,
int index,
Object elementValue) |
void |
setFieldValue(Object object,
FieldInfo fieldInfo,
Object fieldValue) |
void |
setFieldValueToNull(Object object,
FieldInfo fieldInfo) |
public static HelperReflect getInstance()
@Fortest public void assertNotNullField(Object object, ClassInfoFactory classInfoFactory) throws ReflectException
object
- classInfoFactory
- ReflectException
public DeclaredFields declaredFieldsByReflection(Class<?> classForField, IClassInfoFactory classInfoFactory) throws ReflectException
classForField
- class definition where get all declared fields to persistclassInfoFactory
- ReflectException
public FieldInfo createFieldInfo(IClassInfoFactory classInfoFactory, Field field) throws ReflectException
ReflectException
public Object getFieldValue(Object object, FieldInfo fieldInfo, boolean checkAssertNotNull) throws ReflectException
FieldInfo
, on the specified object.object
- fieldInfo
- checkAssertNotNull
- ReflectException
NullFieldException
public void setFieldValue(Object object, FieldInfo fieldInfo, Object fieldValue) throws ReflectException, ReflectFailedSetException
object
- fieldInfo
- fieldValue
- ReflectException
ReflectFailedSetException
public void setFieldValueToNull(Object object, FieldInfo fieldInfo) throws ReflectException, ReflectFailedSetException
@Fortest public void setAlwaysAcceptNullField(boolean alwaysAcceptNullField)
public void setArrayElement(Object array, int index, Object elementValue) throws ReflectException, ReflectFailedSetException
array
- index
- elementValue
- ReflectException
ReflectFailedSetException
public int arrayLength(Object array) throws ReflectException
ReflectException
public Object getArrayElement(Object array, int index) throws ReflectException
array
- index
- ReflectException
public Object invokeStaticMethod(Class<?> objectClass, String methodName, Class<?>[] parameterTypes, Object[] args) throws ReflectException
ReflectException
public Object invokeMethod(Class<?> objectClass, String methodName, Object objectForInvoke, Class<?>[] parameterTypes, Object[] args) throws ReflectException
ReflectException
public Object invokeMethod(Object objectForInvoke, Method method, Object[] args) throws ReflectException
ReflectException
public Object newInstanceDefaultConstructor(Class<?> objectClass) throws ReflectException
ReflectException
public Object newInstanceConstruct(Class<?> objectClass, Class<?>[] parameterTypes, Object[] initargs) throws ReflectException
parameterTypes
parameter is an array of
Class
objects that identify the constructor's formal
parameter types, in declared order.objectClass
- class of the instance to createparameterTypes
- the parameter array.initargs
- array of objects to be passed as arguments to the constructor
call; values of primitive types are wrapped in a wrapper
object of the appropriate type (e.g. a float in a
Float
)ReflectException
public Object newInstanceNoConstruction(Class<?> objectClass) throws ReflectException, ReflectInvalidClassException
objectClass
- the instance to create classReflectException
- creation failureReflectInvalidClassException
public Enum<?> newEnumInstance(Class<?> enumClass, String constantName) throws ReflectInvalidClassException
ReflectInvalidClassException
Copyright © 2007-2012 Luc Peuvrier. All Rights Reserved.