01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.web.deployment;
17:
18: import java.io.IOException;
19: import java.io.InputStream;
20: import javax.enterprise.deploy.model.DDBean;
21: import javax.enterprise.deploy.model.DDBeanRoot;
22: import javax.enterprise.deploy.spi.DConfigBean;
23: import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
24:
25: import org.apache.geronimo.deployment.plugin.DConfigBeanRootSupport;
26: import org.apache.geronimo.xbeans.geronimo.web.GerWebAppDocument;
27: import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
28: import org.apache.xmlbeans.SchemaTypeLoader;
29: import org.apache.xmlbeans.XmlBeans;
30: import org.apache.xmlbeans.XmlException;
31:
32: /**
33: * @version $Rev: 495635 $ $Date: 2007-01-12 08:46:40 -0800 (Fri, 12 Jan 2007) $
34: */
35: public class WebAppDConfigRoot extends DConfigBeanRootSupport {
36: static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans
37: .typeLoaderUnion(new SchemaTypeLoader[] {
38: XmlBeans
39: .typeLoaderForClassLoader(org.apache.geronimo.xbeans.javaee.String.class
40: .getClassLoader()),
41: XmlBeans
42: .typeLoaderForClassLoader(GerWebAppDocument.class
43: .getClassLoader()) });
44:
45: private static String[] XPATHS = { "web-app" };
46:
47: private WebAppDConfigBean webAppBean;
48:
49: public WebAppDConfigRoot(DDBeanRoot ddBean) {
50: super (ddBean, GerWebAppDocument.Factory.newInstance());
51: GerWebAppType webApp = getWebAppDocument().addNewWebApp();
52: replaceWebAppDConfigBean(webApp);
53: }
54:
55: private void replaceWebAppDConfigBean(GerWebAppType webApp) {
56: DDBean ddBean = getDDBean();
57: webAppBean = new WebAppDConfigBean(ddBean
58: .getChildBean(XPATHS[0])[0], webApp);
59: }
60:
61: GerWebAppDocument getWebAppDocument() {
62: return (GerWebAppDocument) getXmlObject();
63: }
64:
65: public String[] getXpaths() {
66: return XPATHS;
67: }
68:
69: public DConfigBean getDConfigBean(DDBean bean)
70: throws ConfigurationException {
71: if (XPATHS[0].equals(bean.getXpath())) {
72: return webAppBean;
73: }
74: return null;
75: }
76:
77: public void fromXML(InputStream inputStream) throws XmlException,
78: IOException {
79: super .fromXML(inputStream);
80: replaceWebAppDConfigBean(getWebAppDocument().getWebApp());
81: }
82:
83: protected SchemaTypeLoader getSchemaTypeLoader() {
84: return SCHEMA_TYPE_LOADER;
85: }
86:
87: }
|