KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22 import org.apache.catalina.Host;
23 import org.apache.catalina.Manager;
24 import org.apache.catalina.Realm;
25 import org.apache.catalina.Valve;
26 import org.apache.catalina.core.StandardHost;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.geronimo.gbean.GBeanInfo;
30 import org.apache.geronimo.gbean.GBeanInfoBuilder;
31 import org.apache.geronimo.gbean.GBeanLifecycle;
32 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
33
34 /**
35  * @version $Rev: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
36  */

37 public class HostGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
38
39     private static final Log log = LogFactory.getLog(HostGBean.class);
40     
41     public static final String JavaDoc J2EE_TYPE = "Host";
42     private static final String JavaDoc WORKDIR = "workDir";
43     private static final String JavaDoc NAME = "name";
44     
45     private final Host host;
46     
47     public HostGBean(){
48         host = null;
49     }
50
51     public HostGBean(String JavaDoc className,
52             Map JavaDoc initParams,
53             ArrayList JavaDoc aliases,
54             ObjectRetriever realmGBean,
55             ValveGBean tomcatValveChain,
56 // CatalinaClusterGBean clusterGBean,
57
ManagerGBean manager) throws Exception JavaDoc {
58         super(); // TODO: make it an attribute
59

60         //Validate
61
if (className == null){
62             className = "org.apache.catalina.core.StandardHost";
63         }
64         
65         if (initParams == null){
66             throw new IllegalArgumentException JavaDoc("Must have a 'name' value in initParams.");
67         }
68         
69         //Be sure the name has been declared.
70
if (!initParams.containsKey(NAME)){
71             throw new IllegalArgumentException JavaDoc("Must have a 'name' value initParams.");
72         }
73         
74         //Be sure we have a default working directory
75
if (!initParams.containsKey(WORKDIR)){
76             initParams.put(WORKDIR, "work");
77         }
78
79         //Create the Host object
80
host = (Host)Class.forName(className).newInstance();
81         
82         //Set the parameters
83
setParameters(host, initParams);
84         
85         //Add aliases, if any
86
if (aliases != null){
87             for (Iterator JavaDoc iter = aliases.iterator(); iter.hasNext();) {
88                 String JavaDoc alias = (String JavaDoc) iter.next();
89                 host.addAlias(alias);
90             }
91         }
92         
93         if (realmGBean != null)
94             host.setRealm((Realm)realmGBean.getInternalObject());
95
96         //Add the valve list
97
if (host instanceof StandardHost){
98             if (tomcatValveChain != null){
99                 ValveGBean valveGBean = tomcatValveChain;
100                 while(valveGBean != null){
101                     ((StandardHost)host).addValve((Valve)valveGBean.getInternalObject());
102                     valveGBean = valveGBean.getNextValve();
103                 }
104             }
105         }
106
107         //Add clustering
108
// if (clusterGBean != null){
109
// host.setCluster((Cluster)clusterGBean.getInternalObject());
110
// }
111

112         //Add manager
113
if (manager != null)
114             host.setManager((Manager)manager.getInternalObject());
115     }
116
117     public Object JavaDoc getInternalObject() {
118         return host;
119     }
120
121     public void doFail() {
122         log.warn("Failed");
123     }
124
125     public void doStart() throws Exception JavaDoc {
126         log.debug("Started host name '" + host.getName() + "'");
127     }
128
129     public void doStop() throws Exception JavaDoc {
130         log.debug("Stopped host '" + host.getName() + "'");
131     }
132
133     public static final GBeanInfo GBEAN_INFO;
134
135     static {
136         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("TomcatHost", HostGBean.class, J2EE_TYPE);
137         infoFactory.addAttribute("className", String JavaDoc.class, true);
138         infoFactory.addAttribute("initParams", Map JavaDoc.class, true);
139         infoFactory.addAttribute("aliases", ArrayList JavaDoc.class, true);
140         infoFactory.addReference("RealmGBean", ObjectRetriever.class, NameFactory.GERONIMO_SERVICE);
141         infoFactory.addReference("TomcatValveChain", ValveGBean.class, ValveGBean.J2EE_TYPE);
142 // infoFactory.addReference("CatalinaCluster", CatalinaClusterGBean.class, CatalinaClusterGBean.J2EE_TYPE);
143
infoFactory.addReference("Manager", ManagerGBean.class, ManagerGBean.J2EE_TYPE);
144         infoFactory.addOperation("getInternalObject");
145         infoFactory.setConstructor(new String JavaDoc[] {
146                 "className",
147                 "initParams",
148                 "aliases",
149                 "RealmGBean",
150                 "TomcatValveChain",
151 // "CatalinaCluster",
152
"Manager"});
153         GBEAN_INFO = infoFactory.getBeanInfo();
154     }
155
156     public static GBeanInfo getGBeanInfo() {
157         return GBEAN_INFO;
158     }
159 }
160
Popular Tags