KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > model > ModelResolutionRegistry


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.model;
8
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import javax.servlet.jsp.PageContext JavaDoc;
14
15 import com.inversoft.verge.mvc.model.ModelResolution;
16
17
18 /**
19  * <p>
20  * This class is used to store ModelResoltuion information
21  * into the page context about beans used on the page. This
22  * is mostly used by the model tags and also by the custom
23  * useBean tags.
24  * </p>
25  *
26  * @author Brian Pontarelli
27  * @since 2.0
28  * @version 2.0
29  */

30 public class ModelResolutionRegistry {
31
32     /**
33      * The name that the Map of MetaData's is store in the page context under
34      */

35     public static final String JavaDoc MAP_KEY = "_inversoftModelResolutions_";
36
37
38     /**
39      * Constructor for ModelResolutionRegistry.
40      */

41     public ModelResolutionRegistry() {
42         super();
43     }
44
45
46     /**
47      * Puts the given ModelResolution under the given key. This can be retrieved
48      * out again using the get method on this class
49      *
50      * @param key The key to store the ModelResolution under
51      * @param modelResolution The ModelResolution to store
52      * @param pageContext The PageContext to store the ModelResolution in
53      */

54     public static void store(String JavaDoc key, ModelResolution modelResolution,
55             PageContext JavaDoc pageContext) {
56
57         assert (key != null) : "key == null";
58         assert (modelResolution != null) : "modelResolution == null";
59
60         Map JavaDoc map = (Map JavaDoc) pageContext.getAttribute(MAP_KEY);
61         if (map == null) {
62             map = new HashMap JavaDoc();
63             pageContext.setAttribute(MAP_KEY, map);
64         }
65
66         map.put(key, modelResolution);
67     }
68
69     /**
70      * Retrieves the ModelResolution from the PageContext using the given key
71      *
72      * @param key The key of the ModelResolution to lookup
73      * @param pageContext The PageContext that the ModelResolution was store in
74      */

75     public static ModelResolution lookup(String JavaDoc key, PageContext JavaDoc pageContext) {
76
77         assert (key != null) : "key == null";
78
79         Map JavaDoc map = (Map JavaDoc) pageContext.getAttribute(MAP_KEY);
80         if (map == null) {
81             map = new HashMap JavaDoc();
82             pageContext.setAttribute(MAP_KEY, map);
83         }
84
85         return (ModelResolution) map.get(key);
86     }
87 }
88
Popular Tags