KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > dispatch > ServletInvocation


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.server.dispatch;
31
32 import com.caucho.log.Log;
33 import com.caucho.util.L10N;
34
35 import javax.servlet.FilterChain JavaDoc;
36 import javax.servlet.ServletException JavaDoc;
37 import javax.servlet.ServletRequest JavaDoc;
38 import javax.servlet.ServletResponse JavaDoc;
39 import java.io.IOException JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 /**
44  * A repository for request information gleaned from the uri.
45  */

46 public class ServletInvocation {
47   static final Logger JavaDoc log = Log.open(ServletInvocation.class);
48   static final L10N L = new L10N(ServletInvocation.class);
49
50   private ClassLoader JavaDoc _classLoader;
51   
52   private String JavaDoc _contextPath = "";
53   
54   private String JavaDoc _contextUri;
55   private String JavaDoc _servletPath;
56   private String JavaDoc _pathInfo;
57   
58   private String JavaDoc _queryString;
59   
60   private String JavaDoc _servletName;
61   private FilterChain JavaDoc _filterChain;
62
63   private HashMap JavaDoc<String JavaDoc,String JavaDoc> _securityRoleMap;
64
65   /**
66    * Creates a new invocation
67    *
68    * @param contextUri the section of the URI after the context path
69    */

70   public ServletInvocation()
71   {
72     _classLoader = Thread.currentThread().getContextClassLoader();
73   }
74
75   /**
76    * Returns the mapped context-path.
77    */

78   public final String JavaDoc getContextPath()
79   {
80     return _contextPath;
81   }
82
83   /**
84    * Sets the context-path.
85    */

86   public void setContextPath(String JavaDoc path)
87   {
88     _contextPath = path;
89   }
90
91   public void setContextURI(String JavaDoc contextURI)
92   {
93     _contextUri = contextURI;
94     _servletPath = contextURI;
95   }
96
97   /**
98    * Returns the URI tail, i.e. everything after the context path.
99    */

100   public final String JavaDoc getContextURI()
101   {
102     return _contextUri;
103   }
104
105   /**
106    * Returns the mapped servlet path.
107    */

108   public final String JavaDoc getServletPath()
109   {
110     return _servletPath;
111   }
112
113   /**
114    * Sets the mapped servlet path.
115    */

116   public void setServletPath(String JavaDoc servletPath)
117   {
118     _servletPath = servletPath;
119   }
120
121   /**
122    * Returns the mapped path info.
123    */

124   public final String JavaDoc getPathInfo()
125   {
126     return _pathInfo;
127   }
128
129   /**
130    * Sets the mapped path info
131    */

132   public void setPathInfo(String JavaDoc pathInfo)
133   {
134     _pathInfo = pathInfo;
135   }
136
137   /**
138    * Returns the query string. Characters remain unescaped.
139    */

140   public final String JavaDoc getQueryString()
141   {
142     return _queryString;
143   }
144
145   /**
146    * Returns the query string. Characters remain unescaped.
147    */

148   public final void setQueryString(String JavaDoc queryString)
149   {
150     _queryString = queryString;
151   }
152
153   /**
154    * Sets the class loader.
155    */

156   public void setClassLoader(ClassLoader JavaDoc loader)
157   {
158     _classLoader = loader;
159   }
160
161   /**
162    * Gets the class loader.
163    */

164   public ClassLoader JavaDoc getClassLoader()
165   {
166     return _classLoader;
167   }
168
169   /**
170    * Sets the servlet name
171    */

172   public void setServletName(String JavaDoc servletName)
173   {
174     _servletName = servletName;
175   }
176
177   /**
178    * Gets the servlet name
179    */

180   public String JavaDoc getServletName()
181   {
182     return _servletName;
183   }
184
185   /**
186    * Sets the filter chain
187    */

188   public void setFilterChain(FilterChain JavaDoc chain)
189   {
190     _filterChain = chain;
191   }
192
193   /**
194    * Gets the filter chain
195    */

196   public FilterChain JavaDoc getFilterChain()
197   {
198     return _filterChain;
199   }
200
201   /**
202    * Gets the security role map.
203    */

204   public HashMap JavaDoc<String JavaDoc,String JavaDoc> getSecurityRoleMap()
205   {
206     return _securityRoleMap;
207   }
208
209   /**
210    * Sets the security role map.
211    */

212   public void setSecurityRoleMap(HashMap JavaDoc<String JavaDoc,String JavaDoc> roleMap)
213   {
214     _securityRoleMap = roleMap;
215   }
216
217   /**
218    * Service a request.
219    *
220    * @param request the servlet request
221    * @param response the servlet response
222    */

223   public void service(ServletRequest JavaDoc request, ServletResponse JavaDoc response)
224     throws IOException JavaDoc, ServletException JavaDoc
225   {
226     _filterChain.doFilter(request, response);
227   }
228
229   /**
230    * Copies from the invocation.
231    */

232   public void copyFrom(ServletInvocation invocation)
233   {
234     _classLoader = invocation._classLoader;
235     _contextPath = invocation._contextPath;
236   
237     _contextUri = invocation._contextUri;
238     _servletPath = invocation._servletPath;
239     _pathInfo = invocation._pathInfo;
240   
241     _queryString = invocation._queryString;
242   
243     _servletName = invocation._servletName;
244     _filterChain = invocation._filterChain;
245   }
246
247   public String JavaDoc toString()
248   {
249     return "ServletInvocation[" + _contextUri + "]";
250   }
251 }
252
Popular Tags