001 package hirondelle.web4jtools.codegenerator.codes; 002 003 import javax.servlet.ServletContext; 004 005 /** Place enumerations in application scope upon startup. */ 006 public final class Enumerations { 007 008 /** 009 * Place all needed enumerations into application scope. 010 * 011 * <P>Enums are placed in app scope as an array, using the enum's simple class name as key, and 012 * the enum <tt>values()</tt> as the value (which returns an array). 013 * 014 * <P>When such values are posted, it is recommended that they be immediately translated into 015 * a member of the enum, using, <tt>valueOf(String)</tt>. 016 */ 017 public static void init(ServletContext aContext){ 018 initEnum(FieldType.class, FieldType.values(), aContext); 019 initEnum(UiStyle.class, UiStyle.values(), aContext); 020 initEnum(ControlStyle.class, ControlStyle.values(), aContext); 021 initEnum(ShowOperation.class, ShowOperation.values(), aContext); 022 initEnum(ApplyOperation.class, ApplyOperation.values(), aContext); 023 } 024 025 // PRIVATE // 026 private static <T> void initEnum(Class<T> aEnumClass, T[] aValues, ServletContext aContext){ 027 aContext.setAttribute(aEnumClass.getSimpleName(), aValues); 028 } 029 }