|
||||||||||
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. |
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)
|
|
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)
|
|
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. |
|
static
|
invokeMethod(T object,
java.lang.String methodName,
java.lang.Object[] parameterArray)
|
|
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. |
|
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 |
---|
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)
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.suppressAccessCheckspublic 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 objectpublic 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 |