View Javadoc
1 package net.mlw.fball.web;
2
3 import javax.servlet.http.HttpServletRequest;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7
8 /***
9 * @author Matthew L. Wilson
10 * @version $Revision: 1.6 $ $Date: 2004/05/21 20:43:48 $
11 */
12 public final class RequestConstants
13 {
14 /*** Commons Logger */
15 public static final Log LOGGER = LogFactory.getFactory().getInstance(RequestConstants.class);
16
17 /*** protect singleton. **/
18 private RequestConstants()
19 {
20 }
21
22 /*** Gets the requested object, in the following way:
23 * <ol>
24 * <li>Determines if the objec tis already in the request/session.</li>
25 * <li>If needed, uses the ObjectRetriever to get the object.</li>
26 * <li>If needed, places the object in the request/session.</li>
27 * <li>Returns the object.</li>
28 * </ol>
29 *
30 * @param request The servlet request to bind this object to.
31 * @param key The Key used to save this object to the request.
32 * @param retriever The ObjectRetriever used to retrieve the object if needed
33 * @return The retrieved object.
34 */
35 public static Object getObjectIfNotInRequest(HttpServletRequest request, Key key, ObjectRetriever retriever) throws Exception
36 {
37 Object bean = request.getAttribute(key.toString());
38 if (bean == null)
39 {
40 bean = retriever.getObject();
41 LOGGER.info("Saving " + bean + " to the request (" + key.getStringLiteral() + ")");
42 request.setAttribute(key.getStringLiteral(), bean);
43 }
44 return bean;
45 }
46
47 /*** This class is used to represent a key in the request.
48 * I have choosed to use the typesave enum pattern as described in
49 * Effective Java Pg.105
50 *
51 * @author Matthew L. Wilson
52 * @version $Revision: 1.6 $ $Date: 2004/05/21 20:43:48 $
53 */
54 public static final class Key
55 {
56 /*** Holds the League object. **/
57 public static final Key LEAGUE = new Key("League");
58 /*** Holds the Coach object. **/
59 public static final Key COACH = new Key("Coach");
60
61 /*** Holds a List of League objects. **/
62 public static final Key LEAGUES = new Key("Leagues");
63 /*** Holds the Coach object. **/
64 public static final Key CHANNELS = new Key("Channels");
65
66 /*** Holds a List of available players. **/
67 public static final Key FREE_AGENTS = new Key("freeAgents");
68
69 /*** The string literal that is stored in the request. **/
70 private String name;
71
72 /*** Default constructor.
73 * @param name The string literal
74 */
75 private Key(String name)
76 {
77 this.name = name;
78 }
79
80 /*** Gets the String literal this key represents.
81 *
82 * @return The String literal
83 */
84 public String getStringLiteral()
85 {
86 return name;
87 }
88
89 /***
90 * @see java.lang.Object#toString()
91 */
92 public String toString()
93 {
94 return name;
95 }
96 }
97
98 public static final class Parameters
99 {
100 public static final String LEAGUE_ID = "leagueId";
101 public static final String PROVIDER_COACH_ID = "providerCoachId";
102 }
103 }
This page was automatically generated by Maven