public final class AnnotationSupport extends Object
| Modifier and Type | Field and Description |
|---|---|
private static Map<String,Field> |
FIELD_CACHE
Simple cache of fields we have seen.
|
| Modifier | Constructor and Description |
|---|---|
private |
AnnotationSupport()
Private constructor of utility class.
|
| Modifier and Type | Method and Description |
|---|---|
private static <T extends Annotation> |
getAnnotation(Object target,
Class<T> annotationType)
Returns an annotation of a specified type attached to a target object.
|
static String |
getContext(Object target)
Gets the value of the field indicated by the
Context annotation on the given object. |
static Long |
getExpiration(Object target)
Gets the value of the field indicated by the
Expiration annotation on the given object,
or null if none. |
private static Field |
getField(Object target,
String fieldName)
Returns a
Field from a target object. |
private static Object |
getFieldValue(Object target,
String fieldName)
Returns the value of a field from an object using reflection.
|
static String |
getKey(Object target)
Gets the value of the field indicated by the
Key annotation on the given object. |
static String |
getValue(Object target)
Gets the value of the field indicated by the
Value annotation on the given object. |
static void |
setContext(Object target,
String context)
Sets the value of the field indicated by the
Context annotation on the given object. |
static void |
setExpiration(Object target,
Long expiration)
Sets the value of the field indicated by the
Expiration annotation on the given object. |
private static void |
setFieldValue(Object target,
String fieldName,
Object fieldValue)
Returns the value of a field from an object using reflection.
|
static void |
setKey(Object target,
String key)
Sets the value of the field indicated by the
Key annotation on the given object. |
static void |
setValue(Object target,
String value)
Sets the value of the field indicated by the
Value annotation on the given object. |
private AnnotationSupport()
@Nonnull @NotEmpty public static String getContext(@Nonnull Object target)
Context annotation on the given object.
If the value is not a String, then it is converted to one
by calling Object.toString() on the object.
target - object from which to get contextIllegalArgumentException - if the target object doesn't declare a Context annotationRuntimeException - if the field cannot be read on the target objectpublic static void setContext(@Nonnull Object target, @Nonnull@NotEmpty String context)
Context annotation on the given object.target - Object on which to set contextcontext - Context valueIllegalArgumentException - if the target object doesn't declare a Context annotationRuntimeException - if the field cannot be set on the target object@Nonnull @NotEmpty public static String getKey(@Nonnull Object target)
Key annotation on the given object.
If the value is not a String, then it is converted to one
by calling Object.toString() on the object.
target - object from which to get keyIllegalArgumentException - if the target object doesn't declare a Key annotationRuntimeException - if the field cannot be read on the target objectpublic static void setKey(@Nonnull Object target, @Nonnull@NotEmpty String key)
Key annotation on the given object.target - Object on which to set keykey - Key valueIllegalArgumentException - if the target object doesn't declare a Key annotationRuntimeException - if the field cannot be set on the target object@Nonnull @NotEmpty public static String getValue(@Nonnull Object target)
Value annotation on the given object.
If the value is not a String, then it is converted to one
by calling Object.toString() on the object.
target - Object from which to get valueIllegalArgumentException - if the target object doesn't declare a Value annotationRuntimeException - if the field cannot be read on the target objectpublic static void setValue(@Nonnull Object target, @Nonnull@NotEmpty String value)
Value annotation on the given object.target - object on which to set valuevalue - Value field valueIllegalArgumentException - if the target object doesn't declare a Value annotationRuntimeException - if the field cannot be set on the target object@Nullable public static Long getExpiration(@Nonnull Object target)
Expiration annotation on the given object,
or null if none.
The value is returned as a long, in milliseconds since the beginning of the Unix epoch. The following data types are supported:
longDateReadableInstanttarget - Object from which to get expirationIllegalArgumentException - if the target object doesn't declare a Expiration annotationRuntimeException - if the field cannot be read on the target object or if it is an unsupported data typepublic static void setExpiration(@Nonnull Object target, @Nullable Long expiration)
Expiration annotation on the given object.
The expiration is expressed in milliseconds since the beginning of the Unix epoch. The following data types are supported:
longDateReadableInstanttarget - object on which to set expirationexpiration - value to setIllegalArgumentException - if the target object doesn't declare a Expiration annotationRuntimeException - if the field cannot be set on the target object or if it is an unsupported data type@Nonnull private static <T extends Annotation> T getAnnotation(@Nonnull Object target, @Nonnull Class<T> annotationType)
T - type of annotationtarget - target object to examineannotationType - class type of annotation to findIllegalArgumentException - if the target object doesn't declare the annotation@Nullable private static Object getFieldValue(@Nonnull Object target, @Nonnull String fieldName)
target - target object to examinefieldName - name of the field to retrieveRuntimeException - if the field cannot be readprivate static void setFieldValue(@Nonnull Object target, @Nonnull String fieldName, @Nullable Object fieldValue)
target - target object to updatefieldName - name of the field to setfieldValue - value to setRuntimeException - if the field cannot be set@Nonnull private static Field getField(@Nonnull Object target, @Nonnull String fieldName)
Field from a target object.target - target object to examinefieldName - name of the field to retrieveRuntimeException - if the target object doesn't declare the annotationCopyright © 1999–2020 Shibboleth Consortium. All rights reserved.