KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > controller > TestContext


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.controller;
14
15 import java.util.Enumeration JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Locale JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.Vector JavaDoc;
20
21 import javax.servlet.ServletContext JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24 import javax.servlet.http.HttpSession JavaDoc;
25 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
26 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
27
28 import org.apache.commons.fileupload.FileItem;
29
30 import com.tonbeller.tbutils.res.Resources;
31 import com.tonbeller.wcf.convert.Converter;
32 import com.tonbeller.wcf.convert.ConverterFactory;
33 import com.tonbeller.wcf.expr.ExprContext;
34 import com.tonbeller.wcf.expr.ExprUtils;
35 import com.tonbeller.wcf.format.Formatter;
36 import com.tonbeller.wcf.format.FormatterFactory;
37
38 /**
39  * Created on 28.11.2002
40  *
41  * @author av
42  */

43 public class TestContext extends RequestContext {
44
45   Formatter formatter = FormatterFactory.instance(getLocale());
46   Converter converter = ConverterFactory.instance(formatter);
47   ExprContext exprContext;
48   Map JavaDoc parameters = new HashMap JavaDoc();
49   HttpSession JavaDoc session = new TestSession();
50
51   /**
52    * @see com.tonbeller.wcf.controller.RequestContext#getRequest()
53    */

54   public HttpServletRequest JavaDoc getRequest() {
55     return null;
56   }
57
58   /**
59    * @see com.tonbeller.wcf.controller.RequestContext#getResponse()
60    */

61   public HttpServletResponse JavaDoc getResponse() {
62     return null;
63   }
64
65   /**
66    * @see com.tonbeller.wcf.controller.RequestContext#getServletContext()
67    */

68   public ServletContext JavaDoc getServletContext() {
69     return null;
70   }
71
72   /**
73    * @see com.tonbeller.wcf.controller.RequestContext#getSession()
74    */

75   public HttpSession JavaDoc getSession() {
76     return session;
77   }
78
79   /**
80    * @see com.tonbeller.wcf.controller.RequestContext#getConverter()
81    */

82   public Converter getConverter() {
83     return converter;
84   }
85
86   /**
87    * @see com.tonbeller.wcf.controller.RequestContext#getFormatter()
88    */

89   public Formatter getFormatter() {
90     return formatter;
91   }
92
93   public Map JavaDoc getParameters() {
94     return parameters;
95   }
96
97   public void setParameters(Map JavaDoc map) {
98     this.parameters = map;
99   }
100
101   public String JavaDoc[] getParameters(String JavaDoc name) {
102     return (String JavaDoc[])parameters.get(name);
103   }
104
105   public String JavaDoc getParameter(String JavaDoc name) {
106     String JavaDoc[] values = getParameters(name);
107     if (values != null && values.length > 0)
108       return values[0];
109     return null;
110   }
111
112   public Locale JavaDoc getLocale() {
113     return Locale.US;
114   }
115
116   /**
117    * Returns the exprContext.
118    * @return ExprContext
119    */

120   public ExprContext getExprContext() {
121     return exprContext;
122   }
123
124   /**
125    * Sets the exprContext.
126    * @param exprContext The exprContext to set
127    */

128   public void setExprContext(ExprContext exprContext) {
129     this.exprContext = exprContext;
130   }
131
132   /**
133    * @see com.tonbeller.wcf.controller.RequestContext#getModelReference(String)
134    */

135   public Object JavaDoc getModelReference(String JavaDoc expr) {
136     return ExprUtils.getModelReference(exprContext, expr);
137   }
138
139   /**
140    * @see com.tonbeller.wcf.controller.RequestContext#setModelReference(String, Object)
141    */

142   public void setModelReference(String JavaDoc expr, Object JavaDoc value) {
143     ExprUtils.setModelReference(exprContext, expr, value);
144   }
145
146   public boolean isUserInRole(String JavaDoc roleExpr) {
147     return false;
148   }
149
150   public Resources getResources() {
151     return Resources.instance(getLocale());
152   }
153
154   public Resources getResources(String JavaDoc bundleName) {
155     return Resources.instance(getLocale(), bundleName);
156   }
157
158   public Resources getResources(Class JavaDoc clasz) {
159     return Resources.instance(getLocale(), clasz);
160   }
161
162   public String JavaDoc getRemoteUser() {
163     return "guest";
164   }
165
166   public String JavaDoc getRemoteDomain() {
167     return null;
168   }
169
170   public boolean isAdmin() {
171     return false;
172   }
173   public class TestSession implements HttpSession JavaDoc {
174     HashMap JavaDoc attrs = new HashMap JavaDoc();
175
176     public long getCreationTime() {
177       return 0;
178     }
179
180     public String JavaDoc getId() {
181       return "testSessionID";
182     }
183
184     public long getLastAccessedTime() {
185       return 0;
186     }
187
188     public ServletContext JavaDoc getServletContext() {
189       return null;
190     }
191
192     public void setMaxInactiveInterval(int arg0) {
193     }
194
195     public int getMaxInactiveInterval() {
196       return 0;
197     }
198
199     /** @deprecated */
200     public javax.servlet.http.HttpSessionContext JavaDoc getSessionContext() {
201       return null;
202     }
203
204     public Object JavaDoc getAttribute(String JavaDoc id) {
205       return attrs.get(id);
206     }
207
208     /** @deprecated */
209     public Object JavaDoc getValue(String JavaDoc id) {
210       return getAttribute(id);
211     }
212
213     public Enumeration JavaDoc getAttributeNames() {
214       Vector JavaDoc v = new Vector JavaDoc();
215       v.addAll(attrs.keySet());
216       return v.elements();
217     }
218
219     /** @deprecated */
220     public String JavaDoc[] getValueNames() {
221       return (String JavaDoc[]) attrs.keySet().toArray(new String JavaDoc[0]);
222     }
223
224     public void setAttribute(String JavaDoc id, Object JavaDoc att) {
225       removeAttribute(id);
226       attrs.put(id, att);
227       if (att instanceof HttpSessionBindingListener JavaDoc) {
228         HttpSessionBindingEvent JavaDoc e = new HttpSessionBindingEvent JavaDoc(this, id);
229         ((HttpSessionBindingListener JavaDoc)att).valueBound(e);
230       }
231     }
232
233     /** @deprecated */
234     public void putValue(String JavaDoc id, Object JavaDoc attr) {
235       setAttribute(id, attr);
236     }
237
238     public void removeAttribute(String JavaDoc id) {
239       Object JavaDoc attr = attrs.get(id);
240       if (attr instanceof HttpSessionBindingListener JavaDoc) {
241         HttpSessionBindingEvent JavaDoc e = new HttpSessionBindingEvent JavaDoc(this, id);
242         ((HttpSessionBindingListener JavaDoc)attr).valueUnbound(e);
243       }
244     }
245
246     /** @deprecated */
247     public void removeValue(String JavaDoc id) {
248       removeAttribute(id);
249     }
250
251     public void invalidate() {
252     }
253
254     public boolean isNew() {
255       return false;
256     }
257   }
258
259   public Object JavaDoc findBean(String JavaDoc name) {
260     return exprContext.findBean(name);
261   }
262
263   public void setBean(String JavaDoc name, Object JavaDoc bean) {
264     exprContext.setBean(name, bean);
265   }
266
267   public void setLocale(Locale JavaDoc locale) {
268   }
269
270   public FileItem getFileItem(String JavaDoc name) {
271     return null;
272   }
273
274   public Map JavaDoc getFileParameters() {
275     return null;
276   }
277 }
278
Popular Tags