001    /**
002    *
003    * Copyright 2003-2004 The Apache Software Foundation
004    *
005    *  Licensed under the Apache License, Version 2.0 (the "License");
006    *  you may not use this file except in compliance with the License.
007    *  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.Realm;
022    import org.apache.geronimo.gbean.GBeanInfo;
023    import org.apache.geronimo.gbean.GBeanInfoBuilder;
024    import org.apache.geronimo.gbean.GBeanLifecycle;
025    
026    public class RealmGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
027        
028        private final Realm realm;
029    
030        public RealmGBean(String className, Map initParams) throws Exception {
031            super(); // TODO: make it an attribute
032            
033            assert className != null;
034            
035            realm = (Realm)Class.forName(className).newInstance();
036            
037            setParameters(realm, initParams);
038            
039        }
040    
041        public Object getInternalObject() {
042            return realm;
043        }
044    
045        public void doFail() {
046        }
047    
048        public void doStart() throws Exception {
049        }
050    
051        public void doStop() throws Exception {
052        }
053    
054        public static final GBeanInfo GBEAN_INFO;
055    
056        static {
057            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("TomcatRealm", RealmGBean.class);
058            infoFactory.addAttribute("className", String.class, true);
059            infoFactory.addAttribute("initParams", Map.class, true);
060    
061            infoFactory.addOperation("getInternalObject");
062            infoFactory.setConstructor(new String[] { "className", "initParams" });
063            GBEAN_INFO = infoFactory.getBeanInfo();
064        }
065    
066        public static GBeanInfo getGBeanInfo() {
067            return GBEAN_INFO;
068        }
069    }