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.openejb;
018    
019    import java.util.Properties;
020    
021    import org.apache.geronimo.gbean.GBeanInfo;
022    import org.apache.geronimo.gbean.GBeanInfoBuilder;
023    import org.apache.geronimo.gbean.GBeanLifecycle;
024    import org.apache.openejb.assembler.classic.ContainerInfo;
025    import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
026    import org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
027    import org.apache.openejb.assembler.classic.BmpEntityContainerInfo;
028    import org.apache.openejb.assembler.classic.CmpEntityContainerInfo;
029    import org.apache.openejb.assembler.classic.MdbContainerInfo;
030    
031    /**
032     * @version $Rev$ $Date$
033     */
034    public class EjbContainer implements GBeanLifecycle {
035        private OpenEjbSystem openEjbSystem;
036        private String id;
037        private Properties properties;
038        private String provider;
039        private String type;
040        private Class<? extends ContainerInfo> infoType;
041    
042        public OpenEjbSystem getOpenEjbSystem() {
043            return openEjbSystem;
044        }
045    
046        public void setOpenEjbSystem(OpenEjbSystem openEjbSystem) {
047            this.openEjbSystem = openEjbSystem;
048        }
049    
050        public String getId() {
051            return id;
052        }
053    
054        public void setId(String id) {
055            this.id = id;
056        }
057    
058        public Properties getProperties() {
059            return properties;
060        }
061    
062        public void setProperties(Properties properties) {
063            this.properties = properties;
064        }
065    
066        public String getProvider() {
067            return provider;
068        }
069    
070        public void setProvider(String provider) {
071            this.provider = provider;
072        }
073    
074        public String getType() {
075            return type;
076        }
077    
078        public void setType(String type) {
079            this.type = type;
080        }
081    
082        private Class<? extends ContainerInfo> getInfoType(String type) {
083            if ("STATELESS".equalsIgnoreCase(type)) return StatelessSessionContainerInfo.class;
084            if ("STATEFUL".equalsIgnoreCase(type)) return StatefulSessionContainerInfo.class;
085            if ("BMP_ENTITY".equalsIgnoreCase(type)) return BmpEntityContainerInfo.class;
086            if ("CMP_ENTITY".equalsIgnoreCase(type)) return CmpEntityContainerInfo.class;
087            if ("CMP2_ENTITY".equalsIgnoreCase(type)) return CmpEntityContainerInfo.class;
088            if ("MESSAGE".equalsIgnoreCase(type)) return MdbContainerInfo.class;
089            else return ContainerInfo.class;
090        }
091    
092        public Class<? extends ContainerInfo> getInfoType() {
093            return infoType == null? getInfoType(type): infoType;
094        }
095    
096        public void setInfoType(Class<? extends ContainerInfo> infoType) {
097            this.infoType = infoType;
098        }
099    
100        public void doStart() throws Exception {
101            openEjbSystem.createContainer(getInfoType(), id, properties, provider);
102        }
103    
104        public void doStop() throws Exception {
105        }
106    
107        public void doFail() {
108        }
109    
110        public static final GBeanInfo GBEAN_INFO;
111    
112        static {
113            GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(EjbContainer.class);
114            infoBuilder.addReference("OpenEjbSystem", OpenEjbSystem.class);
115            infoBuilder.addAttribute("id", String.class, true);
116            infoBuilder.addAttribute("properties", Properties.class, true);
117            infoBuilder.addAttribute("provider", String.class, true);
118            infoBuilder.addAttribute("type", String.class, true);
119            infoBuilder.addAttribute("infoType", Class.class, true);
120            GBEAN_INFO = infoBuilder.getBeanInfo();
121        }
122    
123        public static GBeanInfo getGBeanInfo() {
124            return GBEAN_INFO;
125        }
126    }