View Javadoc

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;
18  
19  import java.util.Map;
20  
21  import org.apache.catalina.Manager;
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  public class ManagerGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever{
29  
30      private static final Log log = LogFactory.getLog(ManagerGBean.class);
31      
32      public static final String J2EE_TYPE = "Manager";
33      
34      protected final Manager manager;
35  
36      protected ManagerGBean(String className) throws Exception{
37         super();     
38         manager = (Manager)Class.forName(className).newInstance();
39      }
40      
41      public ManagerGBean(String className, 
42              Map initParams) throws Exception {
43          super(); // TODO: make it an attribute
44          //Validate
45          if (className == null){
46              className = "org.apache.catalina.core.StandardHost";
47          }
48          
49          //Create the Manager object
50          manager = (Manager)Class.forName(className).newInstance();
51          
52          //Set the parameters
53          setParameters(manager, initParams);
54          
55      }
56      
57      public void doStart() throws Exception {
58      }
59  
60      public void doStop() throws Exception {
61      }
62  
63      public void doFail() {
64      }
65  
66      public Object getInternalObject() {
67          // TODO Auto-generated method stub
68          return manager;
69      }
70      
71      public static final GBeanInfo GBEAN_INFO;
72  
73      static {
74          GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("TomcatManager", ManagerGBean.class, J2EE_TYPE);
75          infoFactory.addAttribute("className", String.class, true);
76          infoFactory.addAttribute("initParams", Map.class, true);
77          infoFactory.addOperation("getInternalObject");
78          infoFactory.setConstructor(new String[] { 
79                  "className", 
80                  "initParams"});
81          GBEAN_INFO = infoFactory.getBeanInfo();
82      }
83  
84      public static GBeanInfo getGBeanInfo() {
85          return GBEAN_INFO;
86      }
87  }