|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.domian.util.ReflectionUtils
public final class ReflectionUtils
Generic static convenience methods dealing with reflection stuff.
Field Summary | |
---|---|
static java.lang.Boolean |
DO_COPY_ENTITIES
Often there is no real necessity to copy entity objects. |
static java.lang.Boolean |
DO_COPY_OBJECTS
This flag is used by the cloneOrDeepCopyIfNotImmutable() method. |
private static org.slf4j.Logger |
log
|
static int |
RECURSIVE_COPYING_DEPTH_TRESHOLD
Recursive copying of objects cannot go on forever! |
Constructor Summary | |
---|---|
ReflectionUtils()
|
Method Summary | ||
---|---|---|
static java.lang.Boolean |
canCast(java.lang.Class fromClass,
java.lang.Class toClass)
|
|
static java.lang.Boolean |
canCast(java.lang.reflect.Type fromType,
java.lang.reflect.Type toType)
|
|
static java.lang.Boolean |
canCastAtLeastOneWay(java.lang.reflect.Type type1,
java.lang.reflect.Type type2)
|
|
static java.lang.Boolean |
canCastFrom_To(java.lang.Class fromClass,
java.lang.Class toClass)
|
|
static java.lang.Boolean |
canCastFrom_To(java.lang.reflect.Type fromType,
java.lang.reflect.Type toType)
|
|
static
|
cloneOrDeepCopyIfNotImmutable(T object)
|
|
static
|
cloneOrDeepCopyIfNotImmutable(T object,
java.lang.Boolean doCopyEntities)
|
|
(package private) static
|
cloneOrDeepCopyIfNotImmutable(T object,
java.util.Map mapOfObjectsInprocess,
int recursiveDepth,
int recursiveDepthTreshold,
boolean doCopyObject,
boolean doCopyEntities,
boolean entityCopyingInProcess)
|
|
(package private) static
|
copyEntity(T entityObject,
java.util.Map<T,T> mapOfObjectsBeingProcessed,
int recursiveDepth,
int recursiveDepthTreshold,
boolean doCopyObject)
|
|
(package private) static
|
doCloneIfNotTheCloningIsJustShallowCopying(T object)
|
|
static java.util.Map<java.lang.String,java.lang.reflect.AccessibleObject> |
getAllAccessibleObjectsFrom(java.lang.Object object)
|
|
static java.lang.Class<?> |
getClass(java.lang.reflect.Type type)
|
|
(package private) static
|
getEntityIdField(T object)
|
|
static
|
getFieldByName(java.lang.String fieldName,
java.lang.Class<T> declaringType)
|
|
static
|
getMethodByName(java.lang.String methodName,
java.lang.Class[] parameterArray,
java.lang.Class<T> declaringType)
|
|
static
|
getMethodByName(java.lang.String methodName,
java.lang.Class<T> declaringType)
|
|
static
|
getMethodByNameWithPossiblePrefix(java.lang.String methodName,
java.lang.Class<T> declaringType,
java.util.List<java.lang.String> possibleMethodPrefixes)
If no method is found with the given name, each of the prefixes in the given list will be added until a valid method are found, or no more prefixes are left to try. |
|
static
|
getTypeArguments(java.lang.Class<T> baseClass,
java.lang.Class<? extends T> subclass)
Gets the actual type arguments a subclass has used to extend a generic base class. |
|
(package private) static boolean |
hasEntityIdField(java.lang.Object object)
|
|
(package private) static
|
invokeBooleanMethod(T object,
java.lang.String methodName)
|
|
(package private) static
|
invokeBooleanMethod(T object,
java.lang.String methodName,
java.lang.Object[] parameterArray)
|
|
(package private) static
|
invokeMethod(T object,
java.lang.String methodName)
|
|
static
|
invokeMethod(T object,
java.lang.String methodName,
java.lang.Object[] parameterArray)
|
|
(package private) static
|
isAlreadyBeingProcessed(T object,
java.util.Map<?,?> mapOfObjectsBeingProcessed)
|
|
(package private) static
|
isCloneableObject(T object)
|
|
static java.lang.Boolean |
isDate(java.lang.Object candidateObject)
|
|
static java.lang.Boolean |
isDecimalNumber(java.lang.Object number)
|
|
static
|
isEntity(T object)
An object is regarded as an entity if and only if: the object is an instance of AbstractEntity
The reason instances have to be of type AbstractEntity , and not just Entity ,
is simply that for Entity objects there is no assurance that the semantics of consistent/unchanging
equals /hashCode methods are addressed. |
|
(package private) static
|
isImmutableObject(T object)
|
|
static
|
replicate(T object)
Replicates the given object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final org.slf4j.Logger log
public static java.lang.Boolean DO_COPY_OBJECTS
cloneOrDeepCopyIfNotImmutable()
method.
The default value is true
.
If object copying is not wanted, override it by setting this flag to false
.
Such an operation is completely sound, given the premis of objects in use being either immutable value objets,
or entity objects having equals
/hashCode
methods not affected by mutable state.
WARNING!
By setting this field to false
, certain specifications turn mutable,
e.g. the ValueBoundSpecification
.
This is because the state of the object given to the specification (the value that is) may be altered.
WARNING!
For now, this is simply a static non-thread-safe JVM wide flag.
public static java.lang.Boolean DO_COPY_ENTITIES
equals
/hashCode
methods should not be allowed to change in any way.
In cases where only the equals
/hashCode
methods are to be invoked, copying the object is not really needed.
This flag is used by the
cloneOrDeepCopyIfNotImmutable()
method.
Which objects that are regarded as entities is specified by the isEntity()
method
The default value is false
.
If entity copying is wanted, override it by setting this flag to true
.
WARNING!
For now, this is simply a static non-thread-safe JVM wide flag.
ReflectionUtils.isEntity(T)
public static int RECURSIVE_COPYING_DEPTH_TRESHOLD
ValueBoundSpecification
s
should not include more than five levels of referencing in its equals()
or compareTo()
method.
(If you are doing such a thing, you should seriously consider refactoring anyway!)
This flag is used by the
cloneOrDeepCopyIfNotImmutable()
method.
WARNING!
For now, this is simply a static non-thread-safe JVM wide flag.
Constructor Detail |
---|
public ReflectionUtils()
Method Detail |
---|
public static java.lang.Boolean canCast(java.lang.Class fromClass, java.lang.Class toClass)
true
if the fromClass
class parameter can be casted to the toClass
class parameterpublic static java.lang.Boolean canCast(java.lang.reflect.Type fromType, java.lang.reflect.Type toType)
true
if the fromType
type parameter can be casted to the toType
type parameterpublic static java.lang.Boolean canCastFrom_To(java.lang.Class fromClass, java.lang.Class toClass)
true
if the fromClass
class parameter can be casted to the toClass
class parameterpublic static java.lang.Boolean canCastFrom_To(java.lang.reflect.Type fromType, java.lang.reflect.Type toType)
true
if the fromType
type parameter can be casted to the toType
type parameterpublic static java.lang.Boolean canCastAtLeastOneWay(java.lang.reflect.Type type1, java.lang.reflect.Type type2)
true
if it is possible to cast on way or another between the two type parameterspublic static java.lang.Boolean isDecimalNumber(java.lang.Object number)
true
if given number is a decimal number/floating point numberpublic static java.lang.Boolean isDate(java.lang.Object candidateObject)
public static <T> java.lang.reflect.Field getFieldByName(java.lang.String fieldName, java.lang.Class<T> declaringType)
null
if no field is foundpublic static <T> java.lang.reflect.Method getMethodByName(java.lang.String methodName, java.lang.Class<T> declaringType)
null
if no method is foundpublic static <T> java.lang.reflect.Method getMethodByName(java.lang.String methodName, java.lang.Class[] parameterArray, java.lang.Class<T> declaringType)
null
if no method is foundpublic static <T> java.lang.reflect.Method getMethodByNameWithPossiblePrefix(java.lang.String methodName, java.lang.Class<T> declaringType, java.util.List<java.lang.String> possibleMethodPrefixes)
null
if no method is foundpublic static <T> java.lang.Object invokeMethod(T object, java.lang.String methodName, java.lang.Object[] parameterArray)
static <T> java.lang.Object invokeMethod(T object, java.lang.String methodName)
static <T> java.lang.Boolean invokeBooleanMethod(T object, java.lang.String methodName, java.lang.Object[] parameterArray)
static <T> java.lang.Boolean invokeBooleanMethod(T object, java.lang.String methodName)
public static java.util.Map<java.lang.String,java.lang.reflect.AccessibleObject> getAllAccessibleObjectsFrom(java.lang.Object object)
public static <T> T replicate(T object)
Cloneable
.
If not, it is deep-copied, except if the given object is regarded as immutable.
Deep-copying follows the DO_COPY_OBJECTS
, DO_COPY_ENTITIES
, and RECURSIVE_COPYING_DEPTH_TRESHOLD
settings.
object
- object to replicate
java.lang.SecurityException
- if a security manager exists and if the caller does not have granted java.lang.reflect.ReflectPermission.suppressAccessCheckspublic static <T> T cloneOrDeepCopyIfNotImmutable(T object)
object
- object to clone or deep copy, if necessery
java.lang.SecurityException
- if a security manager exists and if the caller does not have granted java.lang.reflect.ReflectPermission.suppressAccessCheckspublic static <T> T cloneOrDeepCopyIfNotImmutable(T object, java.lang.Boolean doCopyEntities)
object
- object to clone or deep copy, if necesserydoCopyEntities
- flag to indicate whether copying of entites are wanted or not
java.lang.SecurityException
- if a security manager exists and if the caller does not have granted java.lang.reflect.ReflectPermission.suppressAccessChecksstatic <T> T cloneOrDeepCopyIfNotImmutable(T object, java.util.Map mapOfObjectsInprocess, int recursiveDepth, int recursiveDepthTreshold, boolean doCopyObject, boolean doCopyEntities, boolean entityCopyingInProcess)
java.lang.SecurityException
- if a security manager exists and if the caller does not have granted java.lang.reflect.ReflectPermission.suppressAccessChecksstatic <T> java.lang.Boolean isAlreadyBeingProcessed(T object, java.util.Map<?,?> mapOfObjectsBeingProcessed)
static <T> java.lang.Boolean isCloneableObject(T object)
static <T> java.lang.Boolean isImmutableObject(T object)
public static <T> java.lang.Boolean isEntity(T object)
AbstractEntity
AbstractEntity
, and not just Entity
,
is simply that for Entity
objects there is no assurance that the semantics of consistent/unchanging
equals
/hashCode
methods are addressed.
For AbstractEntity
objects on the other hand, there is.
true
if the given object is safely regarded by Domian as a real entity objectstatic boolean hasEntityIdField(java.lang.Object object)
static <T> java.lang.reflect.Field getEntityIdField(T object)
static <T extends Entity> T copyEntity(T entityObject, java.util.Map<T,T> mapOfObjectsBeingProcessed, int recursiveDepth, int recursiveDepthTreshold, boolean doCopyObject)
java.lang.IllegalArgumentException
- if the entity object to copy is missing a proper entity id
java.lang.SecurityException
- if a security manager exists and if the caller does not have granted java.lang.reflect.ReflectPermission.suppressAccessChecksstatic <T> T doCloneIfNotTheCloningIsJustShallowCopying(T object)
null
if shallow copying is known to take place...public static java.lang.Class<?> getClass(java.lang.reflect.Type type)
type
- the type
null
if the type is a variable typepublic static <T> java.util.List<java.lang.Class<?>> getTypeArguments(java.lang.Class<T> baseClass, java.lang.Class<? extends T> subclass)
baseClass
- the base classsubclass
- the subclass
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |