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: */package org.apache.geronimo.tomcat;
017:
018: import java.util.Map;
019:
020: import org.apache.catalina.LifecycleListener;
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023: import org.apache.geronimo.gbean.GBeanInfo;
024: import org.apache.geronimo.gbean.GBeanInfoBuilder;
025: import org.apache.geronimo.gbean.GBeanLifecycle;
026:
027: /**
028: * @version $Rev: 486195 $ $Date: 2006-12-12 08:42:02 -0700 (Tue, 12 Dec 2006) $
029: */
030: public class LifecycleListenerGBean extends BaseGBean implements
031: GBeanLifecycle, ObjectRetriever {
032:
033: private static final Log log = LogFactory
034: .getLog(LifecycleListenerGBean.class);
035:
036: public static final String J2EE_TYPE = "TomcatLifecycleListener";
037:
038: private final LifecycleListener listener;
039: private final LifecycleListenerGBean nextListener;
040: private final String className;
041:
042: public LifecycleListenerGBean() {
043: listener = null;
044: nextListener = null;
045: className = null;
046: }
047:
048: public LifecycleListenerGBean(String className, Map initParams,
049: LifecycleListenerGBean nextListener) throws Exception {
050:
051: //Validate
052: if (className == null) {
053: throw new IllegalArgumentException(
054: "className cannot be null.");
055: }
056:
057: if (nextListener != null) {
058: if (!(nextListener.getInternalObject() instanceof LifecycleListener)) {
059: throw new IllegalArgumentException(
060: "The class given as the NextListener attribute does not wrap an object of org.apache.catalina.LifecycleListener type.");
061: }
062: this .nextListener = nextListener;
063: } else {
064: this .nextListener = null;
065: }
066:
067: this .className = className;
068:
069: //Create the Listener object
070: listener = (LifecycleListener) Class.forName(className)
071: .newInstance();
072:
073: //Set the parameters
074: setParameters(listener, initParams);
075:
076: }
077:
078: public void doStart() throws Exception {
079: log.debug(className + " started.");
080: }
081:
082: public void doStop() throws Exception {
083: log.debug(className + " stopped.");
084: }
085:
086: public void doFail() {
087: log.warn(className + " failed.");
088: }
089:
090: public Object getInternalObject() {
091: return listener;
092: }
093:
094: public LifecycleListenerGBean getNextListener() {
095: return nextListener;
096: }
097:
098: public static final GBeanInfo GBEAN_INFO;
099:
100: static {
101: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
102: LifecycleListenerGBean.class, J2EE_TYPE);
103: infoFactory.addAttribute("className", String.class, true);
104: infoFactory.addAttribute("initParams", Map.class, true);
105: infoFactory.addReference("NextListener",
106: LifecycleListenerGBean.class, J2EE_TYPE);
107: infoFactory.addOperation("getInternalObject");
108: infoFactory.addOperation("getNextListener");
109: infoFactory.setConstructor(new String[] { "className",
110: "initParams", "NextListener" });
111: GBEAN_INFO = infoFactory.getBeanInfo();
112: }
113:
114: public static GBeanInfo getGBeanInfo() {
115: return GBEAN_INFO;
116: }
117:
118: }
|