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 java.io.IOException;
021    import java.io.InputStream;
022    import javax.enterprise.deploy.model.DDBean;
023    import javax.enterprise.deploy.model.DDBeanRoot;
024    import javax.enterprise.deploy.spi.DConfigBean;
025    import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
026    
027    import org.apache.geronimo.deployment.plugin.DConfigBeanRootSupport;
028    import org.apache.geronimo.xbeans.geronimo.web.GerWebAppDocument;
029    import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
030    import org.apache.xmlbeans.SchemaTypeLoader;
031    import org.apache.xmlbeans.XmlBeans;
032    import org.apache.xmlbeans.XmlException;
033    
034    /**
035     * @version $Rev: 495635 $ $Date: 2007-01-12 11:46:40 -0500 (Fri, 12 Jan 2007) $
036     */
037    public class WebAppDConfigRoot extends DConfigBeanRootSupport {
038        static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{
039            XmlBeans.typeLoaderForClassLoader(org.apache.geronimo.xbeans.javaee.String.class.getClassLoader()),
040            XmlBeans.typeLoaderForClassLoader(GerWebAppDocument.class.getClassLoader())
041        });
042    
043        private static String[] XPATHS = {
044            "web-app"
045        };
046    
047        private WebAppDConfigBean webAppBean;
048    
049        public WebAppDConfigRoot(DDBeanRoot ddBean) {
050            super(ddBean, GerWebAppDocument.Factory.newInstance());
051            GerWebAppType webApp = getWebAppDocument().addNewWebApp();
052            replaceWebAppDConfigBean(webApp);
053        }
054    
055        private void replaceWebAppDConfigBean(GerWebAppType webApp) {
056            DDBean ddBean = getDDBean();
057            webAppBean = new WebAppDConfigBean(ddBean.getChildBean(XPATHS[0])[0], webApp);
058        }
059    
060        GerWebAppDocument getWebAppDocument() {
061            return (GerWebAppDocument) getXmlObject();
062        }
063    
064        public String[] getXpaths() {
065            return XPATHS;
066        }
067    
068        public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException {
069            if (XPATHS[0].equals(bean.getXpath())) {
070                return webAppBean;
071            }
072            return null;
073        }
074    
075        public void fromXML(InputStream inputStream) throws XmlException, IOException {
076            super.fromXML(inputStream);
077            replaceWebAppDConfigBean(getWebAppDocument().getWebApp());
078        }
079    
080        protected SchemaTypeLoader getSchemaTypeLoader() {
081            return SCHEMA_TYPE_LOADER;
082        }
083    
084    
085    }