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 StringgetContext(Object target) Gets the value of the field indicated by theContextannotation on the given object.static LonggetExpiration(Object target) Gets the value of the field indicated by theExpirationannotation on the given object, or null if none.private static FieldReturns aFieldfrom a target object.private static ObjectgetFieldValue(Object target, String fieldName) Returns the value of a field from an object using reflection.static StringGets the value of the field indicated by theKeyannotation on the given object.static StringGets the value of the field indicated by theValueannotation on the given object.static voidsetContext(Object target, String context) Sets the value of the field indicated by theContextannotation on the given object.static voidsetExpiration(Object target, Long expiration) Sets the value of the field indicated by theExpirationannotation on the given object.private static voidsetFieldValue(Object target, String fieldName, Object fieldValue) Returns the value of a field from an object using reflection.static voidSets the value of the field indicated by theKeyannotation on the given object.static voidSets the value of the field indicated by theValueannotation 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 theContextannotation 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 aContextannotationRuntimeException- if the field cannot be read on the target object
-
setContext
Sets the value of the field indicated by theContextannotation on the given object.- Parameters:
target- Object on which to set contextcontext- Context value- Throws:
IllegalArgumentException- if the target object doesn't declare aContextannotationRuntimeException- if the field cannot be set on the target object
-
getKey
Gets the value of the field indicated by theKeyannotation 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 aKeyannotationRuntimeException- if the field cannot be read on the target object
-
setKey
Sets the value of the field indicated by theKeyannotation on the given object.- Parameters:
target- Object on which to set keykey- Key value- Throws:
IllegalArgumentException- if the target object doesn't declare aKeyannotationRuntimeException- if the field cannot be set on the target object
-
getValue
Gets the value of the field indicated by theValueannotation 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 aValueannotationRuntimeException- if the field cannot be read on the target object
-
setValue
Sets the value of the field indicated by theValueannotation on the given object.- Parameters:
target- object on which to set valuevalue- Value field value- Throws:
IllegalArgumentException- if the target object doesn't declare aValueannotationRuntimeException- if the field cannot be set on the target object
-
getExpiration
Gets the value of the field indicated by theExpirationannotation 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 aExpirationannotationRuntimeException- 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 theExpirationannotation 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 aExpirationannotationRuntimeException- 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 aFieldfrom 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
-