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.corba;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.omg.CORBA.ORB;
023    import org.omg.CORBA.Policy;
024    import org.omg.PortableServer.POA;
025    import org.apache.openejb.ContainerType;
026    
027    /**
028     * @version $Revision: 477657 $ $Date: 2006-11-21 04:54:49 -0800 (Tue, 21 Nov 2006) $
029     */
030    public final class AdapterWrapper {
031        private final static Map adapters = new HashMap();
032        private final TSSLink tssLink;
033        private Adapter generator;
034    
035        public AdapterWrapper(TSSLink tssLink) {
036            this.tssLink = tssLink;
037    
038        }
039    
040        public void start(ORB orb, POA poa, Policy securityPolicy) throws CORBAException {
041            ContainerType containerType = tssLink.getDeployment().getContainer().getContainerType();
042            switch (containerType) {
043                case STATELESS:
044                    generator = new AdapterStateless(tssLink, orb, poa, securityPolicy);
045                    break;
046                case STATEFUL:
047                    generator = new AdapterStateful(tssLink, orb, poa, securityPolicy);
048                    break;
049                case BMP_ENTITY:
050                case CMP_ENTITY:
051                    generator = new AdapterEntity(tssLink, orb, poa, securityPolicy);
052                    break;
053                default:
054                    throw new CORBAException("CORBA Adapter does not handle MDB containers");
055            }
056            adapters.put(tssLink.getContainerId(), generator);
057        }
058    
059        public void stop() throws CORBAException {
060            generator.stop();
061            adapters.remove(tssLink.getContainerId());
062        }
063    
064        public static RefGenerator getRefGenerator(String containerId) {
065            return (RefGenerator) adapters.get(containerId);
066        }
067    }