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