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.connector;
019:
020: import java.io.IOException;
021:
022: import javax.servlet.ServletException;
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: import org.apache.catalina.CometEvent;
027: import org.apache.catalina.util.StringManager;
028:
029: public class CometEventImpl implements CometEvent {
030:
031: /**
032: * The string manager for this package.
033: */
034: protected static StringManager sm = StringManager
035: .getManager(Constants.Package);
036:
037: public CometEventImpl(Request request, Response response) {
038: this .request = request;
039: this .response = response;
040: }
041:
042: // ----------------------------------------------------- Instance Variables
043:
044: /**
045: * Associated request.
046: */
047: protected Request request = null;
048:
049: /**
050: * Associated response.
051: */
052: protected Response response = null;
053:
054: /**
055: * Event type.
056: */
057: protected EventType eventType = EventType.BEGIN;
058:
059: /**
060: * Event sub type.
061: */
062: protected EventSubType eventSubType = null;
063:
064: // --------------------------------------------------------- Public Methods
065:
066: /**
067: * Clear the event.
068: */
069: public void clear() {
070: request = null;
071: response = null;
072: }
073:
074: public void setEventType(EventType eventType) {
075: this .eventType = eventType;
076: }
077:
078: public void setEventSubType(EventSubType eventSubType) {
079: this .eventSubType = eventSubType;
080: }
081:
082: public void close() throws IOException {
083: if (request == null) {
084: throw new IllegalStateException(sm
085: .getString("cometEvent.nullRequest"));
086: }
087: request.setComet(false);
088: response.finishResponse();
089: }
090:
091: public EventSubType getEventSubType() {
092: return eventSubType;
093: }
094:
095: public EventType getEventType() {
096: return eventType;
097: }
098:
099: public HttpServletRequest getHttpServletRequest() {
100: return request.getRequest();
101: }
102:
103: public HttpServletResponse getHttpServletResponse() {
104: return response.getResponse();
105: }
106:
107: public void setTimeout(int timeout) throws IOException,
108: ServletException, UnsupportedOperationException {
109: if (request
110: .getAttribute("org.apache.tomcat.comet.timeout.support") == Boolean.TRUE) {
111: request.setAttribute("org.apache.tomcat.comet.timeout",
112: new Integer(timeout));
113: } else {
114: throw new UnsupportedOperationException();
115: }
116: }
117:
118: }
|