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.web.deployment;
019    
020    import javax.enterprise.deploy.model.DDBean;
021    import javax.enterprise.deploy.spi.DConfigBean;
022    import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
023    import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
024    
025    import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
026    import org.apache.geronimo.naming.deployment.ENCHelper;
027    import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
028    import org.apache.xmlbeans.SchemaTypeLoader;
029    
030    /**
031     * @version $Rev: 495635 $ $Date: 2007-01-12 11:46:40 -0500 (Fri, 12 Jan 2007) $
032     */
033    public class WebAppDConfigBean extends DConfigBeanSupport {
034        private final ENCHelper encHelper;
035    
036        WebAppDConfigBean(DDBean ddBean, GerWebAppType webApp) {
037            super(ddBean, webApp);
038    
039            ENCHelper.XmlEnvRefs envRefs = new ENCHelper.XmlEnvRefs(webApp.getEjbRefArray(), webApp.getEjbLocalRefArray(), webApp.getResourceRefArray(), webApp.getResourceEnvRefArray()); 
040    
041            //which version are we dealing with?
042            String version = ddBean.getRoot().getAttributeValue("version");
043            if ("2.4".equals(version)) {
044                encHelper = new ENCHelper(ddBean, envRefs, getXPathsForJ2ee_1_4(ENCHelper.ENC_XPATHS), getXPathsForJ2ee_1_4(ENCHelper.NAME_XPATHS));
045            } else {
046                encHelper = new ENCHelper(ddBean, envRefs, getXPathsWithPrefix(null, ENCHelper.ENC_XPATHS), getXPathsWithPrefix(null, ENCHelper.NAME_XPATHS));
047            }
048    
049        }
050    
051        GerWebAppType getWebApp() {
052            return (GerWebAppType) getXmlObject();
053        }
054    
055        public String getContextRoot() {
056            return getWebApp().getContextRoot();
057        }
058    
059        public void setContextRoot(String contextRoot) {
060            pcs.firePropertyChange("contextRoot", getContextRoot(), contextRoot);
061            getWebApp().setContextRoot(contextRoot);
062        }
063    
064        public DConfigBean getDConfigBean(DDBean ddBean) throws ConfigurationException {
065            return encHelper.getDConfigBean(ddBean);
066        }
067    
068        public void removeDConfigBean(DConfigBean dcBean) throws BeanNotFoundException {
069            encHelper.removeDConfigBean(dcBean);
070        }
071    
072        public String[] getXpaths() {
073            return getXPathsForJ2ee_1_4(ENCHelper.ENC_XPATHS);
074        }
075    
076        protected SchemaTypeLoader getSchemaTypeLoader() {
077            return WebAppDConfigRoot.SCHEMA_TYPE_LOADER;
078        }
079    
080    }