* @return The value of the enum
*/
private Object getEnumValue( final Class<?> containingClass, final Enum object, final String fieldName )
{
Object value = null;
PersistEnum annotation = null;
try
{
// if the field isn't found or no annotation is present, then we stay
// with the default date format
final Field field = ReflectionUtils.getDeclaredField( containingClass, fieldName );
annotation = field.getAnnotation( PersistEnum.class );
if( annotation != null )
{
value = object.getClass().getMethod( annotation.nameMethod() ).invoke( object );
}
}
catch( NoSuchFieldException e )
{
/* empty on purpose, this is ok, just means no annotation */
}
catch( NoSuchMethodException e )
{
final String error = "The method for getting the enums value specified in the annotation " + PersistEnum.class.getSimpleName() +
" is not found. Please check the name of the method and compare to the enum you are attempting to persist." +
" Containing class: " + containingClass.getSimpleName() + Constants.NEW_LINE +
" Field name: " + fieldName + Constants.NEW_LINE +
" Annotated method name: " + annotation.nameMethod() + Constants.NEW_LINE;
LOGGER.error( error, e );
throw new IllegalStateException( error, e );
}
catch( InvocationTargetException | IllegalAccessException e )
{
final String error = "The method for getting the enums value specified in the annotation " + PersistEnum.class.getSimpleName() +
" cannot be invoked." +
" Containing class: " + containingClass.getSimpleName() + Constants.NEW_LINE +
" Field name: " + fieldName + Constants.NEW_LINE +
" Annotated method name: " + annotation.nameMethod() + Constants.NEW_LINE;
LOGGER.error( error, e );
throw new IllegalStateException( error, e );
}
// grab the enum value using the default enum name