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     */
017    package org.apache.geronimo.tomcat;
018    
019    import java.util.Map;
020    
021    import org.apache.catalina.Manager;
022    import org.apache.commons.logging.Log;
023    import org.apache.commons.logging.LogFactory;
024    import org.apache.geronimo.gbean.GBeanInfo;
025    import org.apache.geronimo.gbean.GBeanInfoBuilder;
026    import org.apache.geronimo.gbean.GBeanLifecycle;
027    
028    public class ManagerGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever{
029    
030        private static final Log log = LogFactory.getLog(ManagerGBean.class);
031        
032        public static final String J2EE_TYPE = "Manager";
033        
034        protected final Manager manager;
035    
036        protected ManagerGBean(String className) throws Exception{
037           super();     
038           manager = (Manager)Class.forName(className).newInstance();
039        }
040        
041        public ManagerGBean(String className, 
042                Map initParams) throws Exception {
043            super(); // TODO: make it an attribute
044            //Validate
045            if (className == null){
046                className = "org.apache.catalina.core.StandardHost";
047            }
048            
049            //Create the Manager object
050            manager = (Manager)Class.forName(className).newInstance();
051            
052            //Set the parameters
053            setParameters(manager, initParams);
054            
055        }
056        
057        public void doStart() throws Exception {
058        }
059    
060        public void doStop() throws Exception {
061        }
062    
063        public void doFail() {
064        }
065    
066        public Object getInternalObject() {
067            // TODO Auto-generated method stub
068            return manager;
069        }
070        
071        public static final GBeanInfo GBEAN_INFO;
072    
073        static {
074            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("TomcatManager", ManagerGBean.class, J2EE_TYPE);
075            infoFactory.addAttribute("className", String.class, true);
076            infoFactory.addAttribute("initParams", Map.class, true);
077            infoFactory.addOperation("getInternalObject");
078            infoFactory.setConstructor(new String[] { 
079                    "className", 
080                    "initParams"});
081            GBEAN_INFO = infoFactory.getBeanInfo();
082        }
083    
084        public static GBeanInfo getGBeanInfo() {
085            return GBEAN_INFO;
086        }
087    }