Package org.freezedry.persistence.annotations

Examples of org.freezedry.persistence.annotations.PersistEnum


   * @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
View Full Code Here

TOP

Related Classes of org.freezedry.persistence.annotations.PersistEnum

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.