Package org.opensaml.storage.annotation

# Class AnnotationSupport

java.lang.Object
org.opensaml.storage.annotation.AnnotationSupport

public final class AnnotationSupport extends Object
Support class that reads and writes fields decorated with storage annotations.

## Field Summary

Fields
Modifier and Type
Field
Description
`private static final Map<String,Field>`
`FIELD_CACHE`
Simple cache of fields we have seen.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`private`
`AnnotationSupport()`
Private constructor of utility class.

## Method Summary

Modifier and Type
Method
Description
`private static <T extends Annotation>
T`
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### FIELD_CACHE

@Nonnull private static final Map<String,Field> FIELD_CACHE
Simple cache of fields we have seen.

## Constructor Details

### AnnotationSupport

private AnnotationSupport()
Private constructor of utility class.

## Method Details

### getContext

@Nullable @NotEmpty public static String getContext(@Nonnull Object target)
Gets the value of the field indicated by the `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.

Parameters:
  `target` - object from which to get context
Returns:
  Context field value
Throws:
  `IllegalArgumentException` - if the target object doesn't declare a `Context` annotation
  `RuntimeException` - if the field cannot be read on the target object

### setContext

public static void setContext(@Nonnull Object target, @Nonnull @NotEmpty String context)
Sets the value of the field indicated by the `Context` annotation on the given object.

Parameters:
  `target` - Object on which to set context
  `context` - Context value
Throws:
  `IllegalArgumentException` - if the target object doesn't declare a `Context` annotation
  `RuntimeException` - if the field cannot be set on the target object

### getKey

@Nullable @NotEmpty public static String getKey(@Nonnull Object target)
Gets the value of the field indicated by the `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.

Parameters:
  `target` - object from which to get key
Returns:
  Key field value
Throws:
  `IllegalArgumentException` - if the target object doesn't declare a `Key` annotation
  `RuntimeException` - if the field cannot be read on the target object

### setKey

public static void setKey(@Nonnull Object target, @Nonnull @NotEmpty String key)
Sets the value of the field indicated by the `Key` annotation on the given object.

Parameters:
  `target` - Object on which to set key
  `key` - Key value
Throws:
  `IllegalArgumentException` - if the target object doesn't declare a `Key` annotation
  `RuntimeException` - if the field cannot be set on the target object

### getValue

@Nullable @NotEmpty public static String getValue(@Nonnull Object target)
Gets the value of the field indicated by the `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.

Parameters:
  `target` - Object from which to get value
Returns:
  Value field value
Throws:
  `IllegalArgumentException` - if the target object doesn't declare a `Value` annotation
  `RuntimeException` - if the field cannot be read on the target object

### setValue

public static void setValue(@Nonnull Object target, @Nonnull @NotEmpty String value)
Sets the value of the field indicated by the `Value` annotation on the given object.

Parameters:
  `target` - object on which to set value
  `value` - Value field value
Throws:
  `IllegalArgumentException` - if the target object doesn't declare a `Value` annotation
  `RuntimeException` - if the field cannot be set on the target object

### getExpiration

@Nullable public static Long getExpiration(@Nonnull Object target)
Gets the value of the field indicated by the `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:

- `long`
- `Date`
- `Instant`

Parameters:
  `target` - Object from which to get expiration
Returns:
  Expiration field value, or null
Throws:
  `IllegalArgumentException` - if the target object doesn't declare a `Expiration` annotation
  `RuntimeException` - if the field cannot be read on the target object or if it is an unsupported data type

### setExpiration

public static void setExpiration(@Nonnull Object target, @Nullable Long expiration)
Sets the value of the field indicated by the `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:

- `long`
- `Date`
- `Instant`

Parameters:
  `target` - object on which to set expiration
  `expiration` - value to set
Throws:
  `IllegalArgumentException` - if the target object doesn't declare a `Expiration` annotation
  `RuntimeException` - 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 examine
  `annotationType` - 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

@Nullable private static Object getFieldValue(@Nonnull Object target, @Nonnull String fieldName)
Returns the value of a field from an object using reflection.

Parameters:
  `target` - target object to examine
  `fieldName` - 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 update
  `fieldName` - name of the field to set
  `fieldValue` - value to set
Throws:
  `RuntimeException` - if the field cannot be set

### getField

@Nonnull private static Field getField(@Nonnull Object target, @Nonnull String fieldName)
Returns a `Field` from a target object.

Parameters:
  `target` - target object to examine
  `fieldName` - name of the field to retrieve
Returns:
  the specified field from the object
Throws:
  `RuntimeException` - if the target object doesn't declare the annotation