001: /*
002: * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngine.java,v 1.15 2002/05/02 22:14:45 craigmcc Exp $
003: * $Revision: 1.15 $
004: * $Date: 2002/05/02 22:14:45 $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
011: * reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions
015: * are met:
016: *
017: * 1. Redistributions of source code must retain the above copyright
018: * notice, this list of conditions and the following disclaimer.
019: *
020: * 2. Redistributions in binary form must reproduce the above copyright
021: * notice, this list of conditions and the following disclaimer in
022: * the documentation and/or other materials provided with the
023: * distribution.
024: *
025: * 3. The end-user documentation included with the redistribution, if
026: * any, must include the following acknowlegement:
027: * "This product includes software developed by the
028: * Apache Software Foundation (http://www.apache.org/)."
029: * Alternately, this acknowlegement may appear in the software itself,
030: * if and wherever such third-party acknowlegements normally appear.
031: *
032: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
033: * Foundation" must not be used to endorse or promote products derived
034: * from this software without prior written permission. For written
035: * permission, please contact apache@apache.org.
036: *
037: * 5. Products derived from this software may not be called "Apache"
038: * nor may "Apache" appear in their names without prior written
039: * permission of the Apache Group.
040: *
041: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
042: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
043: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
044: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
045: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
046: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
047: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
048: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
049: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
050: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
051: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
052: * SUCH DAMAGE.
053: * ====================================================================
054: *
055: * This software consists of voluntary contributions made by many
056: * individuals on behalf of the Apache Software Foundation. For more
057: * information on the Apache Software Foundation, please see
058: * <http://www.apache.org/>.
059: *
060: * [Additional notices, if required by prior licensing conditions]
061: *
062: */
063:
064: package org.apache.catalina.core;
065:
066: import java.io.IOException;
067: import javax.servlet.ServletException;
068: import javax.servlet.ServletRequest;
069: import javax.servlet.http.HttpServletResponse;
070: import org.apache.catalina.Container;
071: import org.apache.catalina.Context;
072: import org.apache.catalina.DefaultContext;
073: import org.apache.catalina.Engine;
074: import org.apache.catalina.Host;
075: import org.apache.catalina.LifecycleException;
076: import org.apache.catalina.Request;
077: import org.apache.catalina.Response;
078: import org.apache.catalina.Service;
079: import org.apache.catalina.util.ServerInfo;
080:
081: /**
082: * Standard implementation of the <b>Engine</b> interface. Each
083: * child container must be a Host implementation to process the specific
084: * fully qualified host name of that virtual host.
085: *
086: * @author Craig R. McClanahan
087: * @version $Revision: 1.15 $ $Date: 2002/05/02 22:14:45 $
088: */
089:
090: public class StandardEngine extends ContainerBase implements Engine {
091:
092: // ----------------------------------------------------------- Constructors
093:
094: /**
095: * Create a new StandardEngine component with the default basic Valve.
096: */
097: public StandardEngine() {
098:
099: super ();
100: pipeline.setBasic(new StandardEngineValve());
101:
102: }
103:
104: // ----------------------------------------------------- Instance Variables
105:
106: /**
107: * Host name to use when no server host, or an unknown host,
108: * is specified in the request.
109: */
110: private String defaultHost = null;
111:
112: /**
113: * The descriptive information string for this implementation.
114: */
115: private static final String info = "org.apache.catalina.core.StandardEngine/1.0";
116:
117: /**
118: * The Java class name of the default Mapper class for this Container.
119: */
120: private String mapperClass = "org.apache.catalina.core.StandardEngineMapper";
121:
122: /**
123: * The <code>Service</code> that owns this Engine, if any.
124: */
125: private Service service = null;
126:
127: /**
128: * DefaultContext config
129: */
130: private DefaultContext defaultContext;
131:
132: /**
133: * The JVM Route ID for this Tomcat instance. All Route ID's must be unique
134: * across the cluster.
135: */
136: private String jvmRouteId;
137:
138: // ------------------------------------------------------------- Properties
139:
140: /**
141: * Return the default host.
142: */
143: public String getDefaultHost() {
144:
145: return (defaultHost);
146:
147: }
148:
149: /**
150: * Set the default host.
151: *
152: * @param host The new default host
153: */
154: public void setDefaultHost(String host) {
155:
156: String oldDefaultHost = this .defaultHost;
157: if (host == null) {
158: this .defaultHost = null;
159: } else {
160: this .defaultHost = host.toLowerCase();
161: }
162: support.firePropertyChange("defaultHost", oldDefaultHost,
163: this .defaultHost);
164:
165: }
166:
167: /**
168: * Set the cluster-wide unique identifier for this Engine.
169: * This value is only useful in a load-balancing scenario.
170: * <p>
171: * This property should not be changed once it is set.
172: */
173: public void setJvmRoute(String routeId) {
174: this .log("setJvmRoute=" + routeId);
175: jvmRouteId = routeId;
176: }
177:
178: /**
179: * Retrieve the cluster-wide unique identifier for this Engine.
180: * This value is only useful in a load-balancing scenario.
181: */
182: public String getJvmRoute() {
183: return jvmRouteId;
184: }
185:
186: /**
187: * Set the DefaultContext
188: * for new web applications.
189: *
190: * @param defaultContext The new DefaultContext
191: */
192: public void addDefaultContext(DefaultContext defaultContext) {
193:
194: DefaultContext oldDefaultContext = this .defaultContext;
195: this .defaultContext = defaultContext;
196: support.firePropertyChange("defaultContext", oldDefaultContext,
197: this .defaultContext);
198:
199: }
200:
201: /**
202: * Retrieve the DefaultContext for new web applications.
203: */
204: public DefaultContext getDefaultContext() {
205: return (this .defaultContext);
206: }
207:
208: /**
209: * Return the default Mapper class name.
210: */
211: public String getMapperClass() {
212:
213: return (this .mapperClass);
214:
215: }
216:
217: /**
218: * Set the default Mapper class name.
219: *
220: * @param mapperClass The new default Mapper class name
221: */
222: public void setMapperClass(String mapperClass) {
223:
224: String oldMapperClass = this .mapperClass;
225: this .mapperClass = mapperClass;
226: support.firePropertyChange("mapperClass", oldMapperClass,
227: this .mapperClass);
228:
229: }
230:
231: /**
232: * Return the <code>Service</code> with which we are associated (if any).
233: */
234: public Service getService() {
235:
236: return (this .service);
237:
238: }
239:
240: /**
241: * Set the <code>Service</code> with which we are associated (if any).
242: *
243: * @param service The service that owns this Engine
244: */
245: public void setService(Service service) {
246:
247: this .service = service;
248:
249: }
250:
251: // --------------------------------------------------------- Public Methods
252:
253: /**
254: * Import the DefaultContext config into a web application context.
255: *
256: * @param context web application context to import default context
257: */
258: public void importDefaultContext(Context context) {
259:
260: if (this .defaultContext != null)
261: this .defaultContext.importDefaultContext(context);
262:
263: }
264:
265: /**
266: * Add a child Container, only if the proposed child is an implementation
267: * of Host.
268: *
269: * @param child Child container to be added
270: */
271: public void addChild(Container child) {
272:
273: if (!(child instanceof Host))
274: throw new IllegalArgumentException(sm
275: .getString("standardEngine.notHost"));
276: super .addChild(child);
277:
278: }
279:
280: /**
281: * Return descriptive information about this Container implementation and
282: * the corresponding version number, in the format
283: * <code><description>/<version></code>.
284: */
285: public String getInfo() {
286:
287: return (info);
288:
289: }
290:
291: /**
292: * Disallow any attempt to set a parent for this Container, since an
293: * Engine is supposed to be at the top of the Container hierarchy.
294: *
295: * @param container Proposed parent Container
296: */
297: public void setParent(Container container) {
298:
299: throw new IllegalArgumentException(sm
300: .getString("standardEngine.notParent"));
301:
302: }
303:
304: /**
305: * Start this Engine component.
306: *
307: * @exception LifecycleException if a startup error occurs
308: */
309: public void start() throws LifecycleException {
310:
311: // Log our server identification information
312: System.out.println(ServerInfo.getServerInfo());
313:
314: // Standard container startup
315: super .start();
316:
317: }
318:
319: /**
320: * Return a String representation of this component.
321: */
322: public String toString() {
323:
324: StringBuffer sb = new StringBuffer("StandardEngine[");
325: sb.append(getName());
326: sb.append("]");
327: return (sb.toString());
328:
329: }
330:
331: // ------------------------------------------------------ Protected Methods
332:
333: /**
334: * Add a default Mapper implementation if none have been configured
335: * explicitly.
336: *
337: * @param mapperClass The default mapper class name to add
338: */
339: protected void addDefaultMapper(String mapperClass) {
340:
341: super.addDefaultMapper(this.mapperClass);
342:
343: }
344:
345: }
|