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.startup;
018:
019: import org.apache.catalina.Engine;
020: import org.apache.catalina.Lifecycle;
021: import org.apache.catalina.LifecycleEvent;
022: import org.apache.catalina.LifecycleListener;
023: import org.apache.catalina.Logger;
024: import org.apache.catalina.core.StandardEngine;
025: import org.apache.catalina.util.StringManager;
026:
027: /**
028: * Startup event listener for a <b>Engine</b> that configures the properties
029: * of that Engine, and the associated defined contexts.
030: *
031: * @author Craig R. McClanahan
032: * @version $Revision: 1.3 $ $Date: 2004/02/27 14:58:49 $
033: */
034:
035: public final class EngineConfig implements LifecycleListener {
036:
037: // ----------------------------------------------------- Instance Variables
038:
039: /**
040: * The debugging detail level for this component.
041: */
042: private int debug = 0;
043:
044: /**
045: * The Engine we are associated with.
046: */
047: private Engine engine = null;
048:
049: /**
050: * The string resources for this package.
051: */
052: private static final StringManager sm = StringManager
053: .getManager(Constants.Package);
054:
055: // ------------------------------------------------------------- Properties
056:
057: /**
058: * Return the debugging detail level for this component.
059: */
060: public int getDebug() {
061:
062: return (this .debug);
063:
064: }
065:
066: /**
067: * Set the debugging detail level for this component.
068: *
069: * @param debug The new debugging detail level
070: */
071: public void setDebug(int debug) {
072:
073: this .debug = debug;
074:
075: }
076:
077: // --------------------------------------------------------- Public Methods
078:
079: /**
080: * Process the START event for an associated Engine.
081: *
082: * @param event The lifecycle event that has occurred
083: */
084: public void lifecycleEvent(LifecycleEvent event) {
085:
086: // Identify the engine we are associated with
087: try {
088: engine = (Engine) event.getLifecycle();
089: if (engine instanceof StandardEngine) {
090: int engineDebug = ((StandardEngine) engine).getDebug();
091: if (engineDebug > this .debug)
092: this .debug = engineDebug;
093: }
094: } catch (ClassCastException e) {
095: log(sm.getString("engineConfig.cce", event.getLifecycle()),
096: e);
097: return;
098: }
099:
100: // Process the event that has occurred
101: if (event.getType().equals(Lifecycle.START_EVENT))
102: start();
103: else if (event.getType().equals(Lifecycle.STOP_EVENT))
104: stop();
105:
106: }
107:
108: // -------------------------------------------------------- Private Methods
109:
110: /**
111: * Log a message on the Logger associated with our Engine (if any)
112: *
113: * @param message Message to be logged
114: */
115: private void log(String message) {
116:
117: Logger logger = null;
118: if (engine != null)
119: logger = engine.getLogger();
120: if (logger != null)
121: logger.log("EngineConfig: " + message);
122: else
123: System.out.println("EngineConfig: " + message);
124:
125: }
126:
127: /**
128: * Log a message on the Logger associated with our Engine (if any)
129: *
130: * @param message Message to be logged
131: * @param throwable Associated exception
132: */
133: private void log(String message, Throwable throwable) {
134:
135: Logger logger = null;
136: if (engine != null)
137: logger = engine.getLogger();
138: if (logger != null)
139: logger.log("EngineConfig: " + message, throwable);
140: else {
141: System.out.println("EngineConfig: " + message);
142: System.out.println("" + throwable);
143: throwable.printStackTrace(System.out);
144: }
145:
146: }
147:
148: /**
149: * Process a "start" event for this Engine.
150: */
151: private void start() {
152:
153: if (debug > 0)
154: log(sm.getString("engineConfig.start"));
155:
156: }
157:
158: /**
159: * Process a "stop" event for this Engine.
160: */
161: private void stop() {
162:
163: if (debug > 0)
164: log(sm.getString("engineConfig.stop"));
165:
166: }
167:
168: }
|