KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > plugin > DConfigBeanSupport


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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.deployment.plugin;
19
20 import javax.enterprise.deploy.model.DDBean JavaDoc;
21 import javax.enterprise.deploy.model.XpathEvent JavaDoc;
22 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
23 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc;
24 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
25
26 import org.apache.xmlbeans.XmlObject;
27
28 /**
29  *
30  *
31  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
32  */

33 public abstract class DConfigBeanSupport extends XmlBeanSupport implements DConfigBean JavaDoc {
34     private DDBean JavaDoc ddBean;
35
36     public DConfigBeanSupport(DDBean JavaDoc ddBean, XmlObject xmlObject) {
37         super(xmlObject);
38         this.ddBean = ddBean;
39     }
40
41     protected void setParent(DDBean JavaDoc ddBean, XmlObject xmlObject) {
42         this.ddBean = ddBean;
43         setXmlObject(xmlObject);
44     }
45
46     public DDBean JavaDoc getDDBean() {
47         return ddBean;
48     }
49
50     public DConfigBean JavaDoc getDConfigBean(DDBean JavaDoc bean) throws ConfigurationException JavaDoc {
51         throw new ConfigurationException JavaDoc("No DConfigBean matching DDBean "+bean);
52     }
53
54     public String JavaDoc[] getXpaths() {
55         return null;
56     }
57
58     public void removeDConfigBean(DConfigBean JavaDoc bean) throws BeanNotFoundException JavaDoc {
59         throw new BeanNotFoundException JavaDoc("No children");
60     }
61
62     public void notifyDDChange(XpathEvent JavaDoc event) {
63     }
64
65     protected String JavaDoc[] getXPathsWithPrefix(String JavaDoc prefix, String JavaDoc[][] xpathSegments) {
66         String JavaDoc[] result = new String JavaDoc[xpathSegments.length];
67         for (int i = 0; i < xpathSegments.length; i++) {
68             String JavaDoc[] xpathSegmentArray = xpathSegments[i];
69             StringBuffer JavaDoc xpath = new StringBuffer JavaDoc();
70             for (int j = 0; j < xpathSegmentArray.length; j++) {
71                 String JavaDoc segment = xpathSegmentArray[j];
72                 if (prefix != null) {
73                     xpath.append(prefix).append(":");
74                 }
75                 xpath.append(segment);
76                 if (j < xpathSegmentArray.length -1) {
77                     xpath.append("/");
78                 }
79             }
80             result[i] = xpath.toString();
81         }
82         return result;
83     }
84
85     protected String JavaDoc[] getXPathsFromNamespace(String JavaDoc uri, String JavaDoc[][] xpathSegments) {
86         String JavaDoc[] attributeNames = ddBean.getRoot().getAttributeNames();
87         for (int i = 0; i < attributeNames.length; i++) {
88             String JavaDoc attributeName = attributeNames[i];
89             if (attributeName.startsWith("xmlns")) {
90                 if (ddBean.getRoot().getAttributeValue(attributeName).equals(uri)) {
91                     if (attributeName.equals("xmlns")) {
92                         return getXPathsWithPrefix(null , xpathSegments);
93                     }
94                     return getXPathsWithPrefix(attributeName.substring(6), xpathSegments);
95                 }
96             }
97         }
98         //we can't determine the namespace from looking at attributes, since the namespace is not an attribute.
99
//try assuming that the ddbeans strip namespaces from their xpath handing.
100
return getXPathsWithPrefix(null , xpathSegments);
101     }
102
103     /**
104      * Each entry in the first array is an XPath.
105      * Each entry in the enclosed array is a component of that XPath (slashes omitted).
106      * so {{"foo","bar"},{"baz","foo"}} would represent "foo/bar" and "baz/foo"
107      */

108     protected String JavaDoc[] getXPathsForJ2ee_1_4(String JavaDoc[][] xpathSegments) {
109         return getXPathsFromNamespace("http://java.sun.com/xml/ns/j2ee", xpathSegments);
110     }
111 }
112
Popular Tags