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.cluster;
017:
018: import java.util.Map;
019:
020: import org.apache.geronimo.tomcat.BaseGBean;
021: import org.apache.geronimo.gbean.GBeanInfo;
022: import org.apache.geronimo.gbean.GBeanInfoBuilder;
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.apache.catalina.tribes.ChannelInterceptor;
026:
027: public class ChannelInterceptorGBean extends BaseGBean {
028:
029: private static final Log log = LogFactory.getLog(SenderGBean.class);
030:
031: public static final String J2EE_TYPE = "ChannelInterceptor";
032:
033: private final ChannelInterceptor interceptor;
034: private final ChannelInterceptorGBean nextInterceptor;
035:
036: public ChannelInterceptorGBean() {
037: interceptor = null;
038: nextInterceptor = null;
039: }
040:
041: public ChannelInterceptorGBean(String className, Map initParams,
042: ChannelInterceptorGBean nextInterceptor) throws Exception {
043:
044: super (); // TODO: make it an attribute
045:
046: // Validate
047: if (className == null) {
048: throw new IllegalArgumentException(
049: "Must have a 'className' attribute.");
050: }
051:
052: if (nextInterceptor != null) {
053: if (!(nextInterceptor.getInternalObject() instanceof ChannelInterceptor)) {
054: throw new IllegalArgumentException(
055: "nextInterceptor is not of type ChannelInterceptor.");
056: }
057:
058: this .nextInterceptor = nextInterceptor;
059: } else {
060: this .nextInterceptor = null;
061: }
062:
063: // Create the ChannelInterceptor object
064: interceptor = (ChannelInterceptor) Class.forName(className)
065: .newInstance();
066:
067: // Set the parameters
068: setParameters(interceptor, initParams);
069:
070: }
071:
072: public Object getInternalObject() {
073: return interceptor;
074: }
075:
076: public void doFail() {
077: log.warn("Failed");
078: }
079:
080: public void doStart() throws Exception {
081: log.debug("Started channel interceptor gbean.");
082: }
083:
084: public void doStop() throws Exception {
085: log.debug("Stopped channel interceptor gbean.");
086: }
087:
088: public ChannelInterceptorGBean getNextInterceptor() {
089: return nextInterceptor;
090: }
091:
092: public static final GBeanInfo GBEAN_INFO;
093:
094: static {
095: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
096: "ChannelInterceptor", ChannelInterceptorGBean.class,
097: J2EE_TYPE);
098: infoFactory.addAttribute("className", String.class, true);
099: infoFactory.addAttribute("initParams", Map.class, true);
100: infoFactory.addReference("NextInterceptor",
101: ChannelInterceptorGBean.class, J2EE_TYPE);
102: infoFactory.addOperation("getInternalObject", "Object");
103: infoFactory.addOperation("getNextInterceptor",
104: "ChannelInterceptorGBean");
105: infoFactory.setConstructor(new String[] { "className",
106: "initParams", "NextInterceptor" });
107:
108: GBEAN_INFO = infoFactory.getBeanInfo();
109: }
110:
111: public static GBeanInfo getGBeanInfo() {
112: return GBEAN_INFO;
113: }
114: }
|