001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package org.apache.geronimo.web.deployment; 020 021 import java.io.IOException; 022 import java.io.InputStream; 023 import javax.enterprise.deploy.model.DDBean; 024 import javax.enterprise.deploy.model.DDBeanRoot; 025 import javax.enterprise.deploy.spi.DConfigBean; 026 import javax.enterprise.deploy.spi.exceptions.ConfigurationException; 027 028 import org.apache.geronimo.deployment.plugin.DConfigBeanRootSupport; 029 import org.apache.geronimo.xbeans.geronimo.web.GerWebAppDocument; 030 import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType; 031 import org.apache.xmlbeans.SchemaTypeLoader; 032 import org.apache.xmlbeans.XmlBeans; 033 import org.apache.xmlbeans.XmlException; 034 035 /** 036 * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $ 037 */ 038 public class WebAppDConfigRoot extends DConfigBeanRootSupport { 039 static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{ 040 XmlBeans.typeLoaderForClassLoader(org.apache.geronimo.xbeans.j2ee.String.class.getClassLoader()), 041 XmlBeans.typeLoaderForClassLoader(GerWebAppDocument.class.getClassLoader()) 042 }); 043 044 private static String[] XPATHS = { 045 "web-app" 046 }; 047 048 private WebAppDConfigBean webAppBean; 049 050 public WebAppDConfigRoot(DDBeanRoot ddBean) { 051 super(ddBean, GerWebAppDocument.Factory.newInstance()); 052 GerWebAppType webApp = getWebAppDocument().addNewWebApp(); 053 replaceWebAppDConfigBean(webApp); 054 } 055 056 private void replaceWebAppDConfigBean(GerWebAppType webApp) { 057 DDBean ddBean = getDDBean(); 058 webAppBean = new WebAppDConfigBean(ddBean.getChildBean(XPATHS[0])[0], webApp); 059 } 060 061 GerWebAppDocument getWebAppDocument() { 062 return (GerWebAppDocument) getXmlObject(); 063 } 064 065 public String[] getXpaths() { 066 return XPATHS; 067 } 068 069 public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException { 070 if (XPATHS[0].equals(bean.getXpath())) { 071 return webAppBean; 072 } 073 return null; 074 } 075 076 public void fromXML(InputStream inputStream) throws XmlException, IOException { 077 super.fromXML(inputStream); 078 replaceWebAppDConfigBean(getWebAppDocument().getWebApp()); 079 } 080 081 protected SchemaTypeLoader getSchemaTypeLoader() { 082 return SCHEMA_TYPE_LOADER; 083 } 084 085 086 }