1 /**
2 *
3 * Copyright 2003-2005 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * 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.cluster;
18
19 import java.util.Map;
20
21 import org.apache.catalina.cluster.ClusterDeployer;
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 import org.apache.geronimo.tomcat.BaseGBean;
28 import org.apache.geronimo.tomcat.ObjectRetriever;
29
30 public class ClusterDeployerGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
31
32 private static final Log log = LogFactory
33 .getLog(ClusterDeployerGBean.class);
34
35 public static final String J2EE_TYPE = "ClusterDeployer";
36
37 protected final ClusterDeployer deployer;
38
39 public ClusterDeployerGBean() {
40 deployer = null;
41 }
42
43 protected ClusterDeployerGBean(String className) throws Exception{
44 super();
45 deployer = (ClusterDeployer)Class.forName(className).newInstance();
46 }
47
48 public ClusterDeployerGBean(String className, Map initParams) throws Exception {
49
50 super();
51
52
53 if (className == null) {
54 throw new IllegalArgumentException(
55 "Must have a 'className' attribute.");
56 }
57
58
59 deployer = (ClusterDeployer) Class.forName(className).newInstance();
60
61
62 setParameters(deployer, initParams);
63
64 }
65
66 public Object getInternalObject() {
67 return deployer;
68 }
69
70 public void doFail() {
71 log.warn("Failed: "+ deployer.getClass().getName());
72 }
73
74 public void doStart() throws Exception {
75 log.debug("Started "+ deployer.getClass().getName() +" gbean.");
76 }
77
78 public void doStop() throws Exception {
79 log.debug("Stopped " + deployer.getClass().getName() + " gbean.");
80 }
81
82 public static final GBeanInfo GBEAN_INFO;
83
84 static {
85 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("ClusterDeployer", ClusterDeployerGBean.class, J2EE_TYPE);
86 infoFactory.addAttribute("className", String.class, true);
87 infoFactory.addAttribute("initParams", Map.class, true);
88 infoFactory.addOperation("getInternalObject");
89 infoFactory.setConstructor(new String[] { "className", "initParams" });
90 GBEAN_INFO = infoFactory.getBeanInfo();
91 }
92
93 public static GBeanInfo getGBeanInfo() {
94 return GBEAN_INFO;
95 }
96 }