1 17 20 package org.apache.forrest.forrestbot.webapp; 21 22 import java.lang.reflect.Field ; 23 import java.lang.reflect.Modifier ; 24 import java.util.Collections ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 import org.apache.log4j.Logger; 29 30 public class Constants { 31 32 private static Logger log = Logger.getLogger(Constants.class); 33 34 public static final String FORWARD_NAME_SUCCESS = "Success"; 36 public static final String FORWARD_NAME_FAILURE = "Failure"; 37 public static final String FORWARD_NAME_AUTHORIZED = "Authorized"; 38 39 public static final String BUILD_SUCCESS_STRING = "BUILD SUCCESSFUL"; 41 42 public static final int STATUS_UNKNOWN = 0; 44 public static final int STATUS_FAILED = 1; 45 public static final int STATUS_SUCCESS = 2; 46 public static final int STATUS_RUNNING = 3; 47 48 49 55 private static Map constantsMap; 56 public static Map getConstantFieldsAsMap() 57 throws IllegalAccessException { 58 59 if (constantsMap != null) 60 return constantsMap; 61 62 log.debug("building constants map"); 63 Field [] allFields = Constants.class.getDeclaredFields(); 64 int numFields = allFields.length; 65 Map propMap = new HashMap (numFields); 66 for (int i = 0; i < numFields; i++) { 67 Field f = allFields[i]; 68 int mods = f.getModifiers(); 69 if (Modifier.isPublic(mods) && 70 Modifier.isStatic(mods) && 71 Modifier.isFinal(mods)) { 72 String name = f.getName(); 73 Object value = f.get(null); 74 propMap.put(name, value); 75 } 76 } 77 constantsMap = Collections.unmodifiableMap(propMap); 78 return constantsMap; 79 } 80 } 81 | Popular Tags |