Map < String , Object > doGetValues ( Annotation annotation ) { /* Holds the value map. */ Map < String , Object > values = new HashMap < String , Object > ( ) ; /* Get the declared staticMethodMap from the actual annotation. */ Method [ ] methods = annotation . annotationType ( ) . getDeclaredMethods ( ) ; final Object [ ] noargs = ( Object [ ] ) null ; /* Iterate through declared staticMethodMap and extract values * by invoking decalared staticMethodMap if they are no arg staticMethodMap. */ for ( Method method : methods ) { /* If it is a no arg method assume it is an annoation value. */ if ( method . getParameterTypes ( ) . length == 0 ) { try { /* Get the value. */ Object value = method . invoke ( annotation , noargs ) ; if ( value instanceof Enum ) { Enum enumVal = ( Enum ) value ; value = enumVal . name ( ) ; } values . put ( method . getName ( ) , value ) ; } catch ( Exception ex ) { throw new RuntimeException ( ex ) ; } } } return values ; }
Get the values from the annotation . We use reflection to turn the annotation into a simple HashMap of values .