001: /*
002: * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EngineConfig.java,v 1.3 2001/07/22 20:25:13 pier Exp $
003: * $Revision: 1.3 $
004: * $Date: 2001/07/22 20:25:13 $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 1999 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.startup;
065:
066: import java.io.File;
067: import java.io.FileInputStream;
068: import java.io.FileNotFoundException;
069: import java.io.InputStream;
070: import java.io.IOException;
071: import java.lang.reflect.InvocationTargetException;
072: import java.net.MalformedURLException;
073: import java.net.URL;
074: import org.apache.catalina.Engine;
075: import org.apache.catalina.Lifecycle;
076: import org.apache.catalina.LifecycleEvent;
077: import org.apache.catalina.LifecycleListener;
078: import org.apache.catalina.Logger;
079: import org.apache.catalina.core.StandardEngine;
080: import org.apache.catalina.util.StringManager;
081:
082: /**
083: * Startup event listener for a <b>Engine</b> that configures the properties
084: * of that Engine, and the associated defined contexts.
085: *
086: * @author Craig R. McClanahan
087: * @version $Revision: 1.3 $ $Date: 2001/07/22 20:25:13 $
088: */
089:
090: public final class EngineConfig implements LifecycleListener {
091:
092: // ----------------------------------------------------- Instance Variables
093:
094: /**
095: * The debugging detail level for this component.
096: */
097: private int debug = 0;
098:
099: /**
100: * The Engine we are associated with.
101: */
102: private Engine engine = null;
103:
104: /**
105: * The string resources for this package.
106: */
107: private static final StringManager sm = StringManager
108: .getManager(Constants.Package);
109:
110: // ------------------------------------------------------------- Properties
111:
112: /**
113: * Return the debugging detail level for this component.
114: */
115: public int getDebug() {
116:
117: return (this .debug);
118:
119: }
120:
121: /**
122: * Set the debugging detail level for this component.
123: *
124: * @param debug The new debugging detail level
125: */
126: public void setDebug(int debug) {
127:
128: this .debug = debug;
129:
130: }
131:
132: // --------------------------------------------------------- Public Methods
133:
134: /**
135: * Process the START event for an associated Engine.
136: *
137: * @param event The lifecycle event that has occurred
138: */
139: public void lifecycleEvent(LifecycleEvent event) {
140:
141: // Identify the engine we are associated with
142: try {
143: engine = (Engine) event.getLifecycle();
144: if (engine instanceof StandardEngine) {
145: int engineDebug = ((StandardEngine) engine).getDebug();
146: if (engineDebug > this .debug)
147: this .debug = engineDebug;
148: }
149: } catch (ClassCastException e) {
150: log(sm.getString("engineConfig.cce", event.getLifecycle()),
151: e);
152: return;
153: }
154:
155: // Process the event that has occurred
156: if (event.getType().equals(Lifecycle.START_EVENT))
157: start();
158: else if (event.getType().equals(Lifecycle.STOP_EVENT))
159: stop();
160:
161: }
162:
163: // -------------------------------------------------------- Private Methods
164:
165: /**
166: * Log a message on the Logger associated with our Engine (if any)
167: *
168: * @param message Message to be logged
169: */
170: private void log(String message) {
171:
172: Logger logger = null;
173: if (engine != null)
174: logger = engine.getLogger();
175: if (logger != null)
176: logger.log("EngineConfig: " + message);
177: else
178: System.out.println("EngineConfig: " + message);
179:
180: }
181:
182: /**
183: * Log a message on the Logger associated with our Engine (if any)
184: *
185: * @param message Message to be logged
186: * @param throwable Associated exception
187: */
188: private void log(String message, Throwable throwable) {
189:
190: Logger logger = null;
191: if (engine != null)
192: logger = engine.getLogger();
193: if (logger != null)
194: logger.log("EngineConfig: " + message, throwable);
195: else {
196: System.out.println("EngineConfig: " + message);
197: System.out.println("" + throwable);
198: throwable.printStackTrace(System.out);
199: }
200:
201: }
202:
203: /**
204: * Process a "start" event for this Engine.
205: */
206: private void start() {
207:
208: if (debug > 0)
209: log(sm.getString("engineConfig.start"));
210:
211: }
212:
213: /**
214: * Process a "stop" event for this Engine.
215: */
216: private void stop() {
217:
218: if (debug > 0)
219: log(sm.getString("engineConfig.stop"));
220:
221: }
222:
223: }
|