KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > tomcat > ValveGBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.tomcat;
18
19 import java.util.Map JavaDoc;
20
21 import org.apache.catalina.Valve;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.gbean.GBeanLifecycle;
27
28 /**
29  * @version $Rev: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
30  */

31 public class ValveGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
32
33     private static final Log log = LogFactory.getLog(ValveGBean.class);
34
35     public static final String JavaDoc J2EE_TYPE = "TomcatValve";
36         
37     private final Valve valve;
38     private final ValveGBean nextValve;
39     private final String JavaDoc className;
40  
41     
42     public ValveGBean(){
43         valve = null;
44         nextValve = null;
45         className = null;
46     }
47     
48     public ValveGBean(String JavaDoc className, Map JavaDoc initParams, ValveGBean nextValve) throws Exception JavaDoc{
49
50         //Validate
51
if (className == null){
52             throw new IllegalArgumentException JavaDoc("className cannot be null.");
53         }
54         
55         if (nextValve != null){
56             if (!(nextValve.getInternalObject() instanceof Valve)){
57                 throw new IllegalArgumentException JavaDoc("The class given as the NextValve attribute does not wrap an object of org.apache.catalina.Valve type.");
58             }
59             this.nextValve = nextValve;
60         } else {
61             this.nextValve = null;
62         }
63         
64         this.className = className;
65         
66         //Create the Valve object
67
valve = (Valve)Class.forName(className).newInstance();
68
69         //Set the parameters
70
setParameters(valve, initParams);
71         
72     }
73     
74     public void doStart() throws Exception JavaDoc {
75         log.debug(className + " started.");
76     }
77
78     public void doStop() throws Exception JavaDoc {
79         log.debug(className + " stopped.");
80     }
81
82     public void doFail() {
83         log.warn(className + " failed.");
84     }
85
86     public Object JavaDoc getInternalObject() {
87         return valve;
88     }
89
90     public ValveGBean getNextValve() {
91         return nextValve;
92     }
93     
94     public static final GBeanInfo GBEAN_INFO;
95
96     static {
97         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ValveGBean.class, J2EE_TYPE);
98         infoFactory.addAttribute("className", String JavaDoc.class, true);
99         infoFactory.addAttribute("initParams", Map JavaDoc.class, true);
100         infoFactory.addReference("NextValve", ValveGBean.class, J2EE_TYPE);
101         infoFactory.addOperation("getInternalObject");
102         infoFactory.addOperation("getNextValve");
103         infoFactory.setConstructor(new String JavaDoc[] { "className", "initParams", "NextValve" });
104         GBEAN_INFO = infoFactory.getBeanInfo();
105     }
106
107     public static GBeanInfo getGBeanInfo() {
108         return GBEAN_INFO;
109     }
110
111 }
112
Popular Tags