KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty > deployment > WebAppDConfigRoot


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.jetty.deployment;
19
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import javax.enterprise.deploy.model.DDBean JavaDoc;
23 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
24 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
25 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
26
27 import org.apache.geronimo.deployment.plugin.DConfigBeanRootSupport;
28 import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppDocument;
29 import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppType;
30 import org.apache.xmlbeans.SchemaTypeLoader;
31 import org.apache.xmlbeans.XmlBeans;
32 import org.apache.xmlbeans.XmlException;
33
34 /**
35  * @version $Rev: 56771 $ $Date: 2004-11-06 11:58:54 -0800 (Sat, 06 Nov 2004) $
36  */

37 public class WebAppDConfigRoot extends DConfigBeanRootSupport {
38     static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{
39         XmlBeans.typeLoaderForClassLoader(org.apache.geronimo.xbeans.j2ee.String.class.getClassLoader()),
40         XmlBeans.typeLoaderForClassLoader(JettyWebAppDocument.class.getClassLoader())
41     });
42
43     private static String JavaDoc[] XPATHS = {
44         "web-app"
45     };
46
47     private WebAppDConfigBean webAppBean;
48
49     public WebAppDConfigRoot(DDBeanRoot JavaDoc ddBean) {
50         super(ddBean, JettyWebAppDocument.Factory.newInstance());
51         JettyWebAppType webApp = getWebAppDocument().addNewWebApp();
52         replaceWebAppDConfigBean(webApp);
53     }
54
55     private void replaceWebAppDConfigBean(JettyWebAppType webApp) {
56         DDBean JavaDoc ddBean = getDDBean();
57         webAppBean = new WebAppDConfigBean(ddBean.getChildBean(XPATHS[0])[0], webApp);
58     }
59
60     JettyWebAppDocument getWebAppDocument() {
61         return (JettyWebAppDocument) getXmlObject();
62     }
63
64     public String JavaDoc[] getXpaths() {
65         return XPATHS;
66     }
67
68     public DConfigBean JavaDoc getDConfigBean(DDBean JavaDoc bean) throws ConfigurationException JavaDoc {
69         if (XPATHS[0].equals(bean.getXpath())) {
70             return webAppBean;
71         }
72         return null;
73     }
74
75     public void fromXML(InputStream JavaDoc inputStream) throws XmlException, IOException JavaDoc {
76         super.fromXML(inputStream);
77         replaceWebAppDConfigBean(getWebAppDocument().getWebApp());
78     }
79
80     protected SchemaTypeLoader getSchemaTypeLoader() {
81         return SCHEMA_TYPE_LOADER;
82     }
83
84
85 }
86
Popular Tags