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    
018    package org.apache.geronimo.connector.deployment;
019    
020    import javax.enterprise.deploy.model.DeployableObject;
021    import javax.enterprise.deploy.shared.ModuleType;
022    import javax.enterprise.deploy.spi.DeploymentConfiguration;
023    
024    import org.apache.geronimo.connector.deployment.dconfigbean.ResourceAdapterDConfigRoot;
025    import org.apache.geronimo.connector.deployment.dconfigbean.ResourceAdapter_1_0DConfigRoot;
026    import org.apache.geronimo.connector.deployment.jsr88.Connector15DCBRoot;
027    import org.apache.geronimo.deployment.ModuleConfigurer;
028    import org.apache.geronimo.gbean.GBeanInfo;
029    import org.apache.geronimo.gbean.GBeanInfoBuilder;
030    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
031    
032    /**
033     *
034     *
035     * @version $Rev: 493181 $ $Date: 2007-01-05 15:32:03 -0500 (Fri, 05 Jan 2007) $
036     */
037    public class RARConfigurer implements ModuleConfigurer {
038    
039        public DeploymentConfiguration createConfiguration(DeployableObject deployable) {
040            if (ModuleType.RAR.equals(deployable.getType())) {
041                String ddBeanRootVersion = deployable.getDDBeanRoot().getDDBeanRootVersion();
042                if (ddBeanRootVersion != null && ddBeanRootVersion.equals("1.5")) {
043                    return new RARConfiguration(deployable, new Connector15DCBRoot(deployable.getDDBeanRoot()));
044                }
045                String[] specVersion = deployable.getDDBeanRoot().getText("connector/spec-version");
046                if (specVersion.length > 0 && "1.0".equals(specVersion[0])) {
047                    return new RARConfiguration(deployable, new ResourceAdapter_1_0DConfigRoot(deployable.getDDBeanRoot()));
048                }
049                throw new IllegalArgumentException("Unknown resource adapter version: " + deployable.getDDBeanRoot().getDDBeanRootVersion());
050            } else {
051                return null;
052            }
053        }
054    
055        public ModuleType getModuleType() {
056            return ModuleType.RAR;
057        }
058    
059        public static final GBeanInfo GBEAN_INFO;
060    
061        static {
062            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(RARConfigurer.class, NameFactory.DEPLOYMENT_CONFIGURER);
063            infoFactory.addInterface(ModuleConfigurer.class);
064            GBEAN_INFO = infoFactory.getBeanInfo();
065        }
066    
067        public static GBeanInfo getGBeanInfo() {
068            return GBEAN_INFO;
069        }
070    }