KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > forrestbot > webapp > Constants


1 /*
2 * Copyright 2002-2004 The Apache Software Foundation or its licensors,
3 * as applicable.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */

17 /*
18  * Created on Oct 21, 2003
19  */

20 package org.apache.forrest.forrestbot.webapp;
21
22 import java.lang.reflect.Field JavaDoc;
23 import java.lang.reflect.Modifier JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.apache.log4j.Logger;
29
30 public class Constants {
31
32     private static Logger log = Logger.getLogger(Constants.class);
33     
34     // FORWARD NAMES
35
public static final String JavaDoc FORWARD_NAME_SUCCESS = "Success";
36     public static final String JavaDoc FORWARD_NAME_FAILURE = "Failure";
37     public static final String JavaDoc FORWARD_NAME_AUTHORIZED = "Authorized";
38
39     // string tokens
40
public static final String JavaDoc BUILD_SUCCESS_STRING = "BUILD SUCCESSFUL";
41
42     // status values
43
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     /**
50      * Creates a map of our constants so it can be passed to struts JSPs
51      * only objects, not static stuff can be accessed in a JSP expression
52      *
53      * http://www.mail-archive.com/taglibs-user@jakarta.apache.org/msg05024.html
54      */

55     private static Map JavaDoc constantsMap;
56     public static Map JavaDoc getConstantFieldsAsMap()
57       throws IllegalAccessException JavaDoc {
58         
59         if (constantsMap != null)
60             return constantsMap;
61         
62         log.debug("building constants map");
63         Field JavaDoc[] allFields = Constants.class.getDeclaredFields();
64         int numFields = allFields.length;
65         Map JavaDoc propMap = new HashMap JavaDoc(numFields);
66         for (int i = 0; i < numFields; i++) {
67             Field JavaDoc f = allFields[i];
68             int mods = f.getModifiers();
69             if (Modifier.isPublic(mods) &&
70                 Modifier.isStatic(mods) &&
71                 Modifier.isFinal(mods)) {
72                 String JavaDoc name = f.getName();
73                 Object JavaDoc value = f.get(null);
74                 propMap.put(name, value);
75             }
76         }
77         constantsMap = Collections.unmodifiableMap(propMap);
78         return constantsMap;
79     }
80 }
81
Popular Tags