- java.lang.Object
-
- org.refcodes.runtime.ReflectionUtility
-
public final class ReflectionUtility extends Object
The Class ReflectionUtility.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReflectionUtility.NonExistingValueClass
This class indicates a non existing value in the name-to-value mapping.
-
Field Summary
Fields Modifier and Type Field Description static String
ALIAS_GET
static String
ALIAS_HAS
static String
ALIAS_IS
static String
ALIAS_SET
static String
ALIAS_TOSTRING
static ReflectionUtility.NonExistingValueClass
NON_EXISTING_VALUE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Set<Annotation>
annotations(Class<?> aClass)
Gatherers all annotations annotating a providedClass
.static Set<Annotation>
annotations(Object aObj)
Gatherers all annotations annotating a providedObject
.static Set<Annotation>
annotations(Field aField)
Gatherers all annotations annotating a providedField
.static Set<Annotation>
annotations(Method aMethod)
Gatherers all annotations annotating a providedMethod
.static Annotation
findAnnotation(Class<? extends Annotation> aAnnotation, Class<?> aClass)
Seeks for anAnnotation
of the given type annotating a providedClass
, also reckoning annotations nested inside annotations (recursively).static Annotation
findAnnotation(Class<? extends Annotation> aAnnotation, Object aObj)
Seeks for anAnnotation
of the given type annotating a providedObject
, also reckoning annotations nested inside annotations (recursively).static Annotation
findAnnotation(Class<? extends Annotation> aAnnotation, Field aField)
Seeks for anAnnotation
of the given type annotating a providedField
, also reckoning annotations nested inside annotations (recursively).static Annotation
findAnnotation(Class<? extends Annotation> aAnnotation, Method aMethod)
Seeks for anAnnotation
of the given type annotating a providedMethod
, also reckoning annotations nested inside annotations (recursively).static boolean
hasAnnotation(Class<? extends Annotation> aAnnotation, Class<?> aClass)
Tests if anAnnotation
of the given type annotates a providedClass
, also reckoning annotations nested inside annotations (recursively).static boolean
hasAnnotation(Class<? extends Annotation> aAnnotation, Object aObj)
Tests if anAnnotation
of the given type annotates a providedObject
, also reckoning annotations nested inside annotations (recursively).static boolean
hasAnnotation(Class<? extends Annotation> aAnnotation, Field aField)
Tests if anAnnotation
of the given type annotates a providedField
, also reckoning annotations nested inside annotations (recursively).static boolean
hasAnnotation(Class<? extends Annotation> aAnnotation, Method aMethod)
Tests if anAnnotation
of the given type annotates a providedMethod
, also reckoning annotations nested inside annotations (recursively).static boolean
hasGetterAttribute(Object anObject, String anAttributeName, Class<?> aReturnType)
This method tests whether the given java beans getter attribute is found for the given object.static boolean
hasSetterAttribute(Object anObject, String anAttributeName, Class<?> anAttributeType)
This method tests whether the given java beans setter attribute is found for the given object.static void
setAttribute(Object anObject, String anAttributeName, Object anAttributeValue)
This method sets a java beans attribute for the given object.static void
setAttribute(Object anObject, org.refcodes.struct.Attribute anAttributeValueStruct)
This method sets a java beans attribute for the given object.static org.refcodes.struct.Attribute[]
toBeanAttributes(Object anObject)
This method uses reflection on order to analyze a given object.
-
-
-
Field Detail
-
ALIAS_SET
public static final String ALIAS_SET
- See Also:
- Constant Field Values
-
ALIAS_GET
public static final String ALIAS_GET
- See Also:
- Constant Field Values
-
ALIAS_HAS
public static final String ALIAS_HAS
- See Also:
- Constant Field Values
-
ALIAS_IS
public static final String ALIAS_IS
- See Also:
- Constant Field Values
-
ALIAS_TOSTRING
public static final String ALIAS_TOSTRING
- See Also:
- Constant Field Values
-
NON_EXISTING_VALUE
public static final ReflectionUtility.NonExistingValueClass NON_EXISTING_VALUE
-
-
Method Detail
-
annotations
public static Set<Annotation> annotations(Class<?> aClass)
Gatherers all annotations annotating a providedClass
.
-
annotations
public static Set<Annotation> annotations(Field aField)
Gatherers all annotations annotating a providedField
.
-
annotations
public static Set<Annotation> annotations(Method aMethod)
Gatherers all annotations annotating a providedMethod
.
-
annotations
public static Set<Annotation> annotations(Object aObj)
Gatherers all annotations annotating a providedObject
.
-
findAnnotation
public static Annotation findAnnotation(Class<? extends Annotation> aAnnotation, Class<?> aClass)
Seeks for anAnnotation
of the given type annotating a providedClass
, also reckoning annotations nested inside annotations (recursively).- Parameters:
aAnnotation
- theAnnotation
type for which to seek.aClass
- theClass
which's annotations to crawl.- Returns:
- the
Annotation
annotating the givenClass
or null if none was found
-
findAnnotation
public static Annotation findAnnotation(Class<? extends Annotation> aAnnotation, Field aField)
Seeks for anAnnotation
of the given type annotating a providedField
, also reckoning annotations nested inside annotations (recursively).- Parameters:
aAnnotation
- theAnnotation
type for which to seek.aField
- theField
which's annotations to crawl.- Returns:
- the
Annotation
annotating the givenField
or null if none was found
-
findAnnotation
public static Annotation findAnnotation(Class<? extends Annotation> aAnnotation, Method aMethod)
Seeks for anAnnotation
of the given type annotating a providedMethod
, also reckoning annotations nested inside annotations (recursively).- Parameters:
aAnnotation
- theAnnotation
type for which to seek.aMethod
- theMethod
which's annotations to crawl.- Returns:
- the
Annotation
annotating the givenMethod
or null if none was found
-
findAnnotation
public static Annotation findAnnotation(Class<? extends Annotation> aAnnotation, Object aObj)
Seeks for anAnnotation
of the given type annotating a providedObject
, also reckoning annotations nested inside annotations (recursively).- Parameters:
aAnnotation
- theAnnotation
type for which to seek.aObj
- theObject
which's annotations to crawl.- Returns:
- the
Annotation
annotating the givenObject
or null if none was found
-
hasAnnotation
public static boolean hasAnnotation(Class<? extends Annotation> aAnnotation, Class<?> aClass)
Tests if anAnnotation
of the given type annotates a providedClass
, also reckoning annotations nested inside annotations (recursively).- Parameters:
aAnnotation
- theAnnotation
type for which to seek.aClass
- theClass
which's annotations to crawl.- Returns:
- True in case the
Annotation
annotates the givenClass
.
-
hasAnnotation
public static boolean hasAnnotation(Class<? extends Annotation> aAnnotation, Field aField)
Tests if anAnnotation
of the given type annotates a providedField
, also reckoning annotations nested inside annotations (recursively).- Parameters:
aAnnotation
- theAnnotation
type for which to seek.aField
- theField
which's annotations to crawl.- Returns:
- True in case the
Annotation
annotates the givenField
.
-
hasAnnotation
public static boolean hasAnnotation(Class<? extends Annotation> aAnnotation, Method aMethod)
Tests if anAnnotation
of the given type annotates a providedMethod
, also reckoning annotations nested inside annotations (recursively).- Parameters:
aAnnotation
- theAnnotation
type for which to seek.aMethod
- theMethod
which's annotations to crawl.- Returns:
- True in case the
Annotation
annotates the givenMethod
.
-
hasAnnotation
public static boolean hasAnnotation(Class<? extends Annotation> aAnnotation, Object aObj)
Tests if anAnnotation
of the given type annotates a providedObject
, also reckoning annotations nested inside annotations (recursively).- Parameters:
aAnnotation
- theAnnotation
type for which to seek.aObj
- theObject
which's annotations to crawl.- Returns:
- True in case the
Annotation
annotates the givenObject
.
-
hasGetterAttribute
public static boolean hasGetterAttribute(Object anObject, String anAttributeName, Class<?> aReturnType)
This method tests whether the given java beans getter attribute is found for the given object.- Parameters:
anObject
- The object which is to be tested.anAttributeName
- The attribute name.aReturnType
- The expected (sub-) aClass of the return value- Returns:
- True if the object has a method with the given java beans name which returns the given (super-) aClass.
-
hasSetterAttribute
public static boolean hasSetterAttribute(Object anObject, String anAttributeName, Class<?> anAttributeType)
This method tests whether the given java beans setter attribute is found for the given object.- Parameters:
anObject
- The object which is to be tested.anAttributeName
- The attribute name.anAttributeType
- The expected (sub-) aClass of the attribute- Returns:
- True if the object has a method with the given java beans name which can be called with an argument of the given aClass.
-
setAttribute
public static void setAttribute(Object anObject, org.refcodes.struct.Attribute anAttributeValueStruct) throws NoSuchMethodException
This method sets a java beans attribute for the given object.- Parameters:
anObject
- The object which's attribute is to be set.anAttributeValueStruct
- The name-to-value struct for the attrubute to be set.- Throws:
NoSuchMethodException
- Description of the Exception
-
setAttribute
public static void setAttribute(Object anObject, String anAttributeName, Object anAttributeValue) throws NoSuchMethodException
This method sets a java beans attribute for the given object. The corresponding java beans method must begin with a 'set', the following letter must be in upper case and it must only take one argument being of the same (or super-) aClass as the attribute's aClass.- Parameters:
anObject
- The object which's java beans method is to be called.anAttributeName
- The attribute name of the java beans method.anAttributeValue
- The value of the attribute to be set.- Throws:
NoSuchMethodException
- Description of the Exception
-
toBeanAttributes
public static org.refcodes.struct.Attribute[] toBeanAttributes(Object anObject)
This method uses reflection on order to analyze a given object. The java beans attributes and their values are retrieved and returned in an array of name-to-value pairs.- Parameters:
anObject
- The object to be analyzed.- Returns:
- An array of objects containing the java beans name-to-value pairs.
-
-