001: /*
002: * Copyright 1999,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.catalina;
018:
019: import java.util.EventObject;
020: import javax.servlet.Filter;
021: import javax.servlet.Servlet;
022: import javax.servlet.ServletRequest;
023: import javax.servlet.ServletResponse;
024:
025: /**
026: * General event for notifying listeners of significant events related to
027: * a specific instance of a Servlet, or a specific instance of a Filter,
028: * as opposed to the Wrapper component that manages it.
029: *
030: * @author Craig R. McClanahan
031: * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:38 $
032: */
033:
034: public final class InstanceEvent extends EventObject {
035:
036: // ----------------------------------------------------- Manifest Constants
037:
038: /**
039: * The event indicating that the <code>init()</code> method is about
040: * to be called for this instance.
041: */
042: public static final String BEFORE_INIT_EVENT = "beforeInit";
043:
044: /**
045: * The event indicating that the <code>init()</code> method has returned.
046: */
047: public static final String AFTER_INIT_EVENT = "afterInit";
048:
049: /**
050: * The event indicating that the <code>service()</code> method is about
051: * to be called on a servlet. The <code>servlet</code> property contains
052: * the servlet being called, and the <code>request</code> and
053: * <code>response</code> properties contain the current request and
054: * response being processed.
055: */
056: public static final String BEFORE_SERVICE_EVENT = "beforeService";
057:
058: /**
059: * The event indicating that the <code>service()</code> method has
060: * returned. The <code>servlet</code> property contains the servlet
061: * that was called, and the <code>request</code> and
062: * <code>response</code> properties contain the current request and
063: * response being processed.
064: */
065: public static final String AFTER_SERVICE_EVENT = "afterService";
066:
067: /**
068: * The event indicating that the <code>destroy</code> method is about
069: * to be called for this instance.
070: */
071: public static final String BEFORE_DESTROY_EVENT = "beforeDestroy";
072:
073: /**
074: * The event indicating that the <code>destroy()</code> method has
075: * returned.
076: */
077: public static final String AFTER_DESTROY_EVENT = "afterDestroy";
078:
079: /**
080: * The event indicating that the <code>service()</code> method of a
081: * servlet accessed via a request dispatcher is about to be called.
082: * The <code>servlet</code> property contains a reference to the
083: * dispatched-to servlet instance, and the <code>request</code> and
084: * <code>response</code> properties contain the current request and
085: * response being processed. The <code>wrapper</code> property will
086: * contain a reference to the dispatched-to Wrapper.
087: */
088: public static final String BEFORE_DISPATCH_EVENT = "beforeDispatch";
089:
090: /**
091: * The event indicating that the <code>service()</code> method of a
092: * servlet accessed via a request dispatcher has returned. The
093: * <code>servlet</code> property contains a reference to the
094: * dispatched-to servlet instance, and the <code>request</code> and
095: * <code>response</code> properties contain the current request and
096: * response being processed. The <code>wrapper</code> property will
097: * contain a reference to the dispatched-to Wrapper.
098: */
099: public static final String AFTER_DISPATCH_EVENT = "afterDispatch";
100:
101: /**
102: * The event indicating that the <code>doFilter()</code> method of a
103: * Filter is about to be called. The <code>filter</code> property
104: * contains a reference to the relevant filter instance, and the
105: * <code>request</code> and <code>response</code> properties contain
106: * the current request and response being processed.
107: */
108: public static final String BEFORE_FILTER_EVENT = "beforeFilter";
109:
110: /**
111: * The event indicating that the <code>doFilter()</code> method of a
112: * Filter has returned. The <code>filter</code> property contains
113: * a reference to the relevant filter instance, and the
114: * <code>request</code> and <code>response</code> properties contain
115: * the current request and response being processed.
116: */
117: public static final String AFTER_FILTER_EVENT = "afterFilter";
118:
119: // ----------------------------------------------------------- Constructors
120:
121: /**
122: * Construct a new InstanceEvent with the specified parameters. This
123: * constructor is used for filter lifecycle events.
124: *
125: * @param wrapper Wrapper managing this servlet instance
126: * @param filter Filter instance for which this event occurred
127: * @param type Event type (required)
128: */
129: public InstanceEvent(Wrapper wrapper, Filter filter, String type) {
130:
131: super (wrapper);
132: this .wrapper = wrapper;
133: this .filter = filter;
134: this .servlet = null;
135: this .type = type;
136:
137: }
138:
139: /**
140: * Construct a new InstanceEvent with the specified parameters. This
141: * constructor is used for filter lifecycle events.
142: *
143: * @param wrapper Wrapper managing this servlet instance
144: * @param filter Filter instance for which this event occurred
145: * @param type Event type (required)
146: * @param exception Exception that occurred
147: */
148: public InstanceEvent(Wrapper wrapper, Filter filter, String type,
149: Throwable exception) {
150:
151: super (wrapper);
152: this .wrapper = wrapper;
153: this .filter = filter;
154: this .servlet = null;
155: this .type = type;
156: this .exception = exception;
157:
158: }
159:
160: /**
161: * Construct a new InstanceEvent with the specified parameters. This
162: * constructor is used for filter processing events.
163: *
164: * @param wrapper Wrapper managing this servlet instance
165: * @param filter Filter instance for which this event occurred
166: * @param type Event type (required)
167: * @param request Servlet request we are processing
168: * @param response Servlet response we are processing
169: */
170: public InstanceEvent(Wrapper wrapper, Filter filter, String type,
171: ServletRequest request, ServletResponse response) {
172:
173: super (wrapper);
174: this .wrapper = wrapper;
175: this .filter = filter;
176: this .servlet = null;
177: this .type = type;
178: this .request = request;
179: this .response = response;
180:
181: }
182:
183: /**
184: * Construct a new InstanceEvent with the specified parameters. This
185: * constructor is used for filter processing events.
186: *
187: * @param wrapper Wrapper managing this servlet instance
188: * @param filter Filter instance for which this event occurred
189: * @param type Event type (required)
190: * @param request Servlet request we are processing
191: * @param response Servlet response we are processing
192: * @param exception Exception that occurred
193: */
194: public InstanceEvent(Wrapper wrapper, Filter filter, String type,
195: ServletRequest request, ServletResponse response,
196: Throwable exception) {
197:
198: super (wrapper);
199: this .wrapper = wrapper;
200: this .filter = filter;
201: this .servlet = null;
202: this .type = type;
203: this .request = request;
204: this .response = response;
205: this .exception = exception;
206:
207: }
208:
209: /**
210: * Construct a new InstanceEvent with the specified parameters. This
211: * constructor is used for processing servlet lifecycle events.
212: *
213: * @param wrapper Wrapper managing this servlet instance
214: * @param servlet Servlet instance for which this event occurred
215: * @param type Event type (required)
216: */
217: public InstanceEvent(Wrapper wrapper, Servlet servlet, String type) {
218:
219: super (wrapper);
220: this .wrapper = wrapper;
221: this .filter = null;
222: this .servlet = servlet;
223: this .type = type;
224:
225: }
226:
227: /**
228: * Construct a new InstanceEvent with the specified parameters. This
229: * constructor is used for processing servlet lifecycle events.
230: *
231: * @param wrapper Wrapper managing this servlet instance
232: * @param servlet Servlet instance for which this event occurred
233: * @param type Event type (required)
234: * @param exception Exception that occurred
235: */
236: public InstanceEvent(Wrapper wrapper, Servlet servlet, String type,
237: Throwable exception) {
238:
239: super (wrapper);
240: this .wrapper = wrapper;
241: this .filter = null;
242: this .servlet = servlet;
243: this .type = type;
244: this .exception = exception;
245:
246: }
247:
248: /**
249: * Construct a new InstanceEvent with the specified parameters. This
250: * constructor is used for processing servlet processing events.
251: *
252: * @param wrapper Wrapper managing this servlet instance
253: * @param servlet Servlet instance for which this event occurred
254: * @param type Event type (required)
255: * @param request Servlet request we are processing
256: * @param response Servlet response we are processing
257: */
258: public InstanceEvent(Wrapper wrapper, Servlet servlet, String type,
259: ServletRequest request, ServletResponse response) {
260:
261: super (wrapper);
262: this .wrapper = wrapper;
263: this .filter = null;
264: this .servlet = servlet;
265: this .type = type;
266: this .request = request;
267: this .response = response;
268:
269: }
270:
271: /**
272: * Construct a new InstanceEvent with the specified parameters. This
273: * constructor is used for processing servlet processing events.
274: *
275: * @param wrapper Wrapper managing this servlet instance
276: * @param servlet Servlet instance for which this event occurred
277: * @param type Event type (required)
278: * @param request Servlet request we are processing
279: * @param response Servlet response we are processing
280: * @param exception Exception that occurred
281: */
282: public InstanceEvent(Wrapper wrapper, Servlet servlet, String type,
283: ServletRequest request, ServletResponse response,
284: Throwable exception) {
285:
286: super (wrapper);
287: this .wrapper = wrapper;
288: this .filter = null;
289: this .servlet = servlet;
290: this .type = type;
291: this .request = request;
292: this .response = response;
293: this .exception = exception;
294:
295: }
296:
297: // ----------------------------------------------------- Instance Variables
298:
299: /**
300: * The exception that was thrown during the processing being reported
301: * by this event (AFTER_INIT_EVENT, AFTER_SERVICE_EVENT,
302: * AFTER_DESTROY_EVENT, AFTER_DISPATCH_EVENT, and AFTER_FILTER_EVENT only).
303: */
304: private Throwable exception = null;
305:
306: /**
307: * The Filter instance for which this event occurred (BEFORE_FILTER_EVENT
308: * and AFTER_FILTER_EVENT only).
309: */
310: private Filter filter = null;
311:
312: /**
313: * The servlet request being processed (BEFORE_FILTER_EVENT,
314: * AFTER_FILTER_EVENT, BEFORE_SERVICE_EVENT, and AFTER_SERVICE_EVENT).
315: */
316: private ServletRequest request = null;
317:
318: /**
319: * The servlet response being processed (BEFORE_FILTER_EVENT,
320: * AFTER_FILTER_EVENT, BEFORE_SERVICE_EVENT, and AFTER_SERVICE_EVENT).
321: */
322: private ServletResponse response = null;
323:
324: /**
325: * The Servlet instance for which this event occurred (not present on
326: * BEFORE_FILTER_EVENT or AFTER_FILTER_EVENT events).
327: */
328: private Servlet servlet = null;
329:
330: /**
331: * The event type this instance represents.
332: */
333: private String type = null;
334:
335: /**
336: * The Wrapper managing the servlet instance for which this event occurred.
337: */
338: private Wrapper wrapper = null;
339:
340: // ------------------------------------------------------------- Properties
341:
342: /**
343: * Return the exception that occurred during the processing
344: * that was reported by this event.
345: */
346: public Throwable getException() {
347:
348: return (this .exception);
349:
350: }
351:
352: /**
353: * Return the filter instance for which this event occurred.
354: */
355: public Filter getFilter() {
356:
357: return (this .filter);
358:
359: }
360:
361: /**
362: * Return the servlet request for which this event occurred.
363: */
364: public ServletRequest getRequest() {
365:
366: return (this .request);
367:
368: }
369:
370: /**
371: * Return the servlet response for which this event occurred.
372: */
373: public ServletResponse getResponse() {
374:
375: return (this .response);
376:
377: }
378:
379: /**
380: * Return the servlet instance for which this event occurred.
381: */
382: public Servlet getServlet() {
383:
384: return (this .servlet);
385:
386: }
387:
388: /**
389: * Return the event type of this event.
390: */
391: public String getType() {
392:
393: return (this .type);
394:
395: }
396:
397: /**
398: * Return the Wrapper managing the servlet instance for which this
399: * event occurred.
400: */
401: public Wrapper getWrapper() {
402:
403: return (this.wrapper);
404:
405: }
406:
407: }
|