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        // no-arg constructor required for gbean refs
037        public ManagerGBean(){
038            manager = null;
039        }
040        
041        protected ManagerGBean(String className) throws Exception{
042           super();     
043           manager = (Manager)Class.forName(className).newInstance();
044        }
045        
046        public ManagerGBean(String className, 
047                Map initParams) throws Exception {
048            super(); // TODO: make it an attribute
049            //Validate
050            if (className == null){
051                className = "org.apache.catalina.core.StandardHost";
052            }
053            
054            //Create the Manager object
055            manager = (Manager)Class.forName(className).newInstance();
056            
057            //Set the parameters
058            setParameters(manager, initParams);
059            
060        }
061        
062        public void doStart() throws Exception {
063        }
064    
065        public void doStop() throws Exception {
066        }
067    
068        public void doFail() {
069        }
070    
071        public Object getInternalObject() {
072            // TODO Auto-generated method stub
073            return manager;
074        }
075        
076        public static final GBeanInfo GBEAN_INFO;
077    
078        static {
079            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("TomcatManager", ManagerGBean.class, J2EE_TYPE);
080            infoFactory.addAttribute("className", String.class, true);
081            infoFactory.addAttribute("initParams", Map.class, true);
082            infoFactory.addOperation("getInternalObject");
083            infoFactory.setConstructor(new String[] { 
084                    "className", 
085                    "initParams"});
086            GBEAN_INFO = infoFactory.getBeanInfo();
087        }
088    
089        public static GBeanInfo getGBeanInfo() {
090            return GBEAN_INFO;
091        }
092    }