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