Package org.opensaml.storage.annotation
Class AnnotationSupport
java.lang.Object
org.opensaml.storage.annotation.AnnotationSupport
Support class that reads and writes fields decorated with storage annotations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionSimple cache of fields we have seen. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T extends Annotation>
TgetAnnotation
(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 theContext
annotation on the given object.static Long
getExpiration
(Object target) Gets the value of the field indicated by theExpiration
annotation on the given object, or null if none.private static Field
Returns aField
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
Gets the value of the field indicated by theKey
annotation on the given object.static String
Gets the value of the field indicated by theValue
annotation on the given object.static void
setContext
(Object target, String context) Sets the value of the field indicated by theContext
annotation on the given object.static void
setExpiration
(Object target, Long expiration) Sets the value of the field indicated by theExpiration
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
Sets the value of the field indicated by theKey
annotation on the given object.static void
Sets the value of the field indicated by theValue
annotation on the given object.
-
Field Details
-
FIELD_CACHE
Simple cache of fields we have seen.
-
-
Constructor Details
-
AnnotationSupport
private AnnotationSupport()Private constructor of utility class.
-
-
Method Details
-
getContext
Gets the value of the field indicated by theContext
annotation on the given object.If the value is not a
String
, then it is converted to one by callingObject.toString()
on the object.- Parameters:
target
- object from which to get context- Returns:
- Context field value
- Throws:
IllegalArgumentException
- if the target object doesn't declare aContext
annotationRuntimeException
- if the field cannot be read on the target object
-
setContext
Sets the value of the field indicated by theContext
annotation on the given object.- Parameters:
target
- Object on which to set contextcontext
- Context value- Throws:
IllegalArgumentException
- if the target object doesn't declare aContext
annotationRuntimeException
- if the field cannot be set on the target object
-
getKey
Gets the value of the field indicated by theKey
annotation on the given object.If the value is not a
String
, then it is converted to one by callingObject.toString()
on the object.- Parameters:
target
- object from which to get key- Returns:
- Key field value
- Throws:
IllegalArgumentException
- if the target object doesn't declare aKey
annotationRuntimeException
- if the field cannot be read on the target object
-
setKey
Sets the value of the field indicated by theKey
annotation on the given object.- Parameters:
target
- Object on which to set keykey
- Key value- Throws:
IllegalArgumentException
- if the target object doesn't declare aKey
annotationRuntimeException
- if the field cannot be set on the target object
-
getValue
Gets the value of the field indicated by theValue
annotation on the given object.If the value is not a
String
, then it is converted to one by callingObject.toString()
on the object.- Parameters:
target
- Object from which to get value- Returns:
- Value field value
- Throws:
IllegalArgumentException
- if the target object doesn't declare aValue
annotationRuntimeException
- if the field cannot be read on the target object
-
setValue
Sets the value of the field indicated by theValue
annotation on the given object.- Parameters:
target
- object on which to set valuevalue
- Value field value- Throws:
IllegalArgumentException
- if the target object doesn't declare aValue
annotationRuntimeException
- if the field cannot be set on the target object
-
getExpiration
Gets the value of the field indicated by theExpiration
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:
- Parameters:
target
- Object from which to get expiration- Returns:
- Expiration field value, or null
- Throws:
IllegalArgumentException
- if the target object doesn't declare aExpiration
annotationRuntimeException
- if the field cannot be read on the target object or if it is an unsupported data type
-
setExpiration
Sets the value of the field indicated by theExpiration
annotation on the given object.The expiration is expressed in milliseconds since the beginning of the Unix epoch. The following data types are supported:
- Parameters:
target
- object on which to set expirationexpiration
- value to set- Throws:
IllegalArgumentException
- if the target object doesn't declare aExpiration
annotationRuntimeException
- if the field cannot be set on the target object or if it is an unsupported data type
-
getAnnotation
@Nonnull private static <T extends Annotation> T getAnnotation(@Nonnull Object target, @Nonnull Class<T> annotationType) Returns an annotation of a specified type attached to a target object.- Type Parameters:
T
- type of annotation- Parameters:
target
- target object to examineannotationType
- class type of annotation to find- Returns:
- the annotation found on the object
- Throws:
IllegalArgumentException
- if the target object doesn't declare the annotation
-
getFieldValue
Returns the value of a field from an object using reflection.- Parameters:
target
- target object to examinefieldName
- name of the field to retrieve- Returns:
- the value of the field
- Throws:
RuntimeException
- if the field cannot be read
-
setFieldValue
private static void setFieldValue(@Nonnull Object target, @Nonnull String fieldName, @Nullable Object fieldValue) Returns the value of a field from an object using reflection.- Parameters:
target
- target object to updatefieldName
- name of the field to setfieldValue
- value to set- Throws:
RuntimeException
- if the field cannot be set
-
getField
Returns aField
from a target object.- Parameters:
target
- target object to examinefieldName
- name of the field to retrieve- Returns:
- the specified field from the object
- Throws:
RuntimeException
- if the target object doesn't declare the annotation
-