KickJava   Java API By Example, From Geeks To Geeks.

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


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.server.webapp.WebApp;
34 import com.caucho.util.L10N;
35 import com.caucho.vfs.Dependency;
36
37 import java.util.logging.Logger JavaDoc;
38
39 /**
40  * A repository for request information gleaned from the uri.
41  */

42 public class Invocation extends ServletInvocation implements Dependency {
43   static final L10N L = new L10N(Invocation.class);
44   static final Logger JavaDoc log = Log.open(Invocation.class);
45
46   private String JavaDoc _rawHost;
47
48   // canonical host and port
49
private String JavaDoc _hostName;
50   private int _port;
51
52   private String JavaDoc _rawURI;
53   private boolean _isSecure;
54
55   private String JavaDoc _uri;
56   private String JavaDoc _sessionId;
57
58   private WebApp _webApp;
59
60   private Dependency _dependency;
61
62   public Invocation()
63   {
64   }
65   
66   /**
67    * Returns the secure flag
68    */

69   public final boolean isSecure()
70   {
71     return _isSecure;
72   }
73
74   /**
75    * Sets the secure flag
76    */

77   public final void setSecure(boolean isSecure)
78   {
79     _isSecure = isSecure;
80   }
81
82   /**
83    * Returns the raw host from the protocol. This may be different
84    * from the canonical host name.
85    */

86   public final String JavaDoc getHost()
87   {
88     return _rawHost;
89   }
90
91   /**
92    * Sets the protocol's host.
93    */

94   public final void setHost(String JavaDoc host)
95   {
96     _rawHost = host;
97   }
98
99   /**
100    * Returns canonical host name.
101    */

102   public final String JavaDoc getHostName()
103   {
104     return _hostName;
105   }
106
107   /**
108    * Sets the protocol's host.
109    */

110   public final void setHostName(String JavaDoc hostName)
111   {
112     if (hostName != null && ! hostName.equals(""))
113       _hostName = hostName;
114   }
115
116   /**
117    * Returns canonical port
118    */

119   public final int getPort()
120   {
121     return _port;
122   }
123
124   /**
125    * Sets the canonical port
126    */

127   public final void setPort(int port)
128   {
129     _port = port;
130   }
131
132   /**
133    * Returns the raw URI from the protocol before any normalization.
134    * The raw URI includes the query string. (?)
135    */

136   public final String JavaDoc getRawURI()
137   {
138     return _rawURI;
139   }
140
141   /**
142    * Sets the raw URI from the protocol before any normalization.
143    * The raw URI includes the query string. (?)
144    */

145   public final void setRawURI(String JavaDoc uri)
146   {
147     _rawURI = uri;
148   }
149
150   /**
151    * Returns the raw URI length.
152    */

153   public int getURLLength()
154   {
155     if (_rawURI != null)
156       return _rawURI.length();
157     else
158       return 0;
159   }
160
161   /**
162    * Returns the URI after normalization, e.g. character escaping,
163    * URL session, and query string.
164    */

165   public final String JavaDoc getURI()
166   {
167     return _uri;
168   }
169
170   /**
171    * Sets the URI after normalization.
172    */

173   public final void setURI(String JavaDoc uri)
174   {
175     _uri = uri;
176
177     setContextURI(uri);
178   }
179
180   /**
181    * Returns a URL-based session id.
182    */

183   public final String JavaDoc getSessionId()
184   {
185     return _sessionId;
186   }
187
188   /**
189    * Sets the URL-based session id.
190    */

191   public final void setSessionId(String JavaDoc sessionId)
192   {
193     _sessionId = sessionId;
194   }
195
196   /**
197    * Returns the mapped webApp.
198    */

199   public final WebApp getWebApp()
200   {
201     return _webApp;
202   }
203
204   /**
205    * Sets the mapped webApp.
206    */

207   public void setWebApp(WebApp app)
208   {
209     _webApp = app;
210   }
211
212   /**
213    * Sets the dependency.
214    */

215   public void setDependency(Dependency dependency)
216   {
217     _dependency = dependency;
218   }
219
220   /**
221    * Returns the dependency list.
222    */

223   public Dependency getDependency()
224   {
225     return _dependency;
226   }
227
228   /**
229    * Returns true if the invocation has been modified. Generally only
230    * true if the webApp has been modified.
231    */

232   public boolean isModified()
233   {
234     Dependency depend = _dependency;
235
236     if (depend != null && depend.isModified())
237       return true;
238
239     WebApp app = _webApp;
240
241     if (app != null) {
242       depend = app.getInvocationDependency();
243
244       if (depend != null)
245     return depend.isModified();
246     }
247
248     return true;
249   }
250
251   /**
252    * Copies from the invocation.
253    */

254   public void copyFrom(Invocation invocation)
255   {
256     super.copyFrom(invocation);
257
258     _rawHost = invocation._rawHost;
259     _rawURI = invocation._rawURI;
260
261     _hostName = invocation._hostName;
262     _port = invocation._port;
263     _uri = invocation._uri;
264
265     _webApp = invocation._webApp;
266     _dependency = invocation._dependency;
267   }
268
269   /**
270    * Returns the invocation's hash code.
271    */

272   public int hashCode()
273   {
274     int hash = _rawURI.hashCode();
275
276     if (_rawHost != null)
277       hash = hash * 65521 + _rawHost.hashCode();
278
279     hash = hash * 65521 + _port;
280
281     return hash;
282   }
283
284   /**
285    * Checks for equality
286    */

287   public boolean equals(Object JavaDoc o)
288   {
289     if (this == o)
290       return true;
291     else if (o == null)
292       return false;
293
294     if (getClass() != o.getClass())
295       return false;
296
297     Invocation inv = (Invocation) o;
298
299     if (_isSecure != inv._isSecure)
300       return false;
301
302     if (_rawURI != inv._rawURI &&
303     (_rawURI == null || ! _rawURI.equals(inv._rawURI)))
304       return false;
305
306     if (_rawHost != inv._rawHost &&
307     (_rawHost == null || ! _rawHost.equals(inv._rawHost)))
308       return false;
309
310     if (_port != inv._port)
311       return false;
312
313     String JavaDoc aQuery = getQueryString();
314     String JavaDoc bQuery = inv.getQueryString();
315
316     if (aQuery != bQuery &&
317     (aQuery == null || ! aQuery.equals(bQuery)))
318       return false;
319
320     return true;
321   }
322
323   void close()
324   {
325     _webApp = null;
326   }
327 }
328
Popular Tags