KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > DefaultViewContext


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: DefaultViewContext.java,v 1.9 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp;
21
22 import java.util.*;
23 import javax.servlet.*;
24 import javax.servlet.http.*;
25 import org.w3c.dom.*;
26
27 import org.enhydra.barracuda.plankton.data.*;
28 import org.enhydra.barracuda.core.event.*;
29 import org.enhydra.barracuda.core.view.*;
30
31 /**
32  * This class provides the default implementation of a ViewContext. A View
33  * Context basically exists to provide the component models with the
34  * information they need to actually pass back the proper data to the
35  * component.
36  */

37 public class DefaultViewContext implements ViewContext {
38
39     //private vars
40
private StateMap statemap = new DefaultStateMap();
41
42     //--------------- Constructors -------------------------------
43
/**
44      * Create a DefaultViewContext
45      */

46     public DefaultViewContext() {}
47     
48     /**
49      * Create a DefaultViewContext for a specific ViewCapabilities obj
50      */

51     public DefaultViewContext(ViewCapabilities ivc, HttpServletRequest ireq, HttpServletResponse iresp) {
52         this.putState(ViewContext.VIEW_CAPABILITIES, ivc);
53         this.putState(ViewContext.REQUEST, ireq);
54         this.putState(ViewContext.RESPONSE, iresp);
55     }
56     
57     /**
58      * Create a DefaultViewContext for a specific EventContext
59      */

60     public DefaultViewContext(ViewEventContext ivec) {
61         this.putState(ViewContext.VIEW_CAPABILITIES, ivec.getViewCapabilities());
62         this.putState(ViewContext.EVENT_CONTEXT, ivec);
63         this.putState(ViewContext.REQUEST, ivec.getRequest());
64         this.putState(ViewContext.RESPONSE, ivec.getResponse());
65     }
66
67
68
69     //--------------- DefaultViewContext -------------------------
70
/**
71      * Get the underlying ViewCapabilities object
72      *
73      * @return the underlying ViewCapabilities object
74      */

75     public ViewCapabilities getViewCapabilities() {
76         return (ViewCapabilities) this.getState(ViewContext.VIEW_CAPABILITIES);
77     }
78
79     /**
80      * Get the underlying EventContext object
81      *
82      * @return the underlying EventContext object
83      */

84     public EventContext getEventContext() {
85         return (EventContext) this.getState(ViewContext.EVENT_CONTEXT);
86     }
87
88     /**
89      * Get the underlying ElementFactory object (if it exists)
90      *
91      * @return the underlying ElementFactory object (if it exists)
92      */

93     public ElementFactory getElementFactory() {
94         return (ElementFactory) this.getState(ViewContext.ELEMENT_FACTORY);
95     }
96     
97     /**
98      * Get the underlying template Node (if it exists)
99      *
100      * @return the underlying template Node (if it exists)
101      */

102     public Node getTemplateNode() {
103         return (Node) this.getState(ViewContext.TEMPLATE_NODE);
104     }
105
106     /**
107      * Get the underlying HttpServletRequest
108      *
109      * @return the underlying HttpServletRequest
110      */

111     public HttpServletRequest getRequest() {
112         return (HttpServletRequest) this.getState(ViewContext.REQUEST);
113     }
114
115     /**
116      * Get the underlying HttpServletResponse
117      *
118      * @return the underlying HttpServletResponse
119      */

120     public HttpServletResponse getResponse() {
121         return (HttpServletResponse) this.getState(ViewContext.RESPONSE);
122     }
123
124
125     
126     //-------------------- StateMap ------------------------------
127
/**
128      * set a property in this StateMap
129      *
130      * @param key the state key object
131      * @param val the state value object
132      */

133     public void putState(Object JavaDoc key, Object JavaDoc val) {
134         statemap.putState(key,val);
135     }
136     
137     /**
138      * get a property in this StateMap
139      *
140      * @param key the state key object
141      * @return the value for the given key
142      */

143     public Object JavaDoc getState(Object JavaDoc key) {
144         return statemap.getState(key);
145     }
146     
147     /**
148      * remove a property in this StateMap
149      *
150      * @param key the key object
151      * @return the object which was removed
152      */

153     public Object JavaDoc removeState(Object JavaDoc key) {
154         return statemap.removeState(key);
155     }
156     
157     /**
158      * get a list of the keys for this StateMap
159      *
160      * @return a list the keys for this StateMap
161      */

162     public List getStateKeys() {
163         return statemap.getStateKeys();
164     }
165     
166     /**
167      * get a copy of the underlying Map
168      *
169      * @return a copy of the underlying state Map
170      */

171     public Map getStateValues() {
172         return statemap.getStateValues();
173     }
174     
175     //csc_052803_2 - added
176
/**
177      * clear all state information
178      */

179     public void clearState() {
180         statemap.clearState();
181     }
182     
183 }
Popular Tags