/** * Gets the value of the field indicated by the {@link Key} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target object from which to get key * * @return Key field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Key} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getKey(@Nonnull final Object target) { final Key keyField = getAnnotation(target, Key.class); final Object value = getFieldValue(target, keyField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
/** * Gets the value of the field indicated by the {@link Context} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target object from which to get context * * @return Context field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Context} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getContext(@Nonnull final Object target) { final Context ctxField = getAnnotation(target, Context.class); final Object value = getFieldValue(target, ctxField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
/** * Gets the value of the field indicated by the {@link Value} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target Object from which to get value * * @return Value field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Value} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getValue(@Nonnull final Object target) { final Value valueField = getAnnotation(target, Value.class); final Object value = getFieldValue(target, valueField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
final Object value = getFieldValue(target, expField.value()); if (value == null) { return null;