/** * Sets the value of the field indicated by the {@link Value} annotation on the given object. * * @param target object on which to set value * @param value Value field value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Value} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setValue(@Nonnull final Object target, @Nonnull @NotEmpty final String value) { final Value valueField = getAnnotation(target, Value.class); setFieldValue(target, valueField.value(), value); }
/** * Sets the value of the field indicated by the {@link Key} annotation on the given object. * * @param target Object on which to set key * @param key Key value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Key} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setKey(@Nonnull final Object target, @Nonnull @NotEmpty final String key) { final Key keyField = getAnnotation(target, Key.class); setFieldValue(target, keyField.value(), key); }
/** * Sets the value of the field indicated by the {@link Context} annotation on the given object. * * @param target Object on which to set context * @param context Context value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Context} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setContext(@Nonnull final Object target, @Nonnull @NotEmpty final String context) { final Context ctxField = getAnnotation(target, Context.class); setFieldValue(target, ctxField.value(), context); }
final Expiration expField = getAnnotation(target, Expiration.class); if (expiration == null) { setFieldValue(target, expField.value(), null); setFieldValue(target, expField.value(), expiration); } else if (Date.class.isAssignableFrom(type)) { setFieldValue(target, expField.value(), new Date(expiration)); } else if (ReadableInstant.class.isAssignableFrom(type)) { setFieldValue(target, expField.value(), new Instant(expiration)); } else { throw new RuntimeException(type + " is an unsupported data type for an expiration field.");