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: */package org.apache.geronimo.deployment.plugin;
017:
018: import javax.enterprise.deploy.model.DDBean;
019: import javax.enterprise.deploy.model.XpathEvent;
020: import javax.enterprise.deploy.spi.DConfigBean;
021: import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
022: import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
023:
024: import org.apache.xmlbeans.XmlObject;
025:
026: /**
027: *
028: *
029: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
030: */
031: public abstract class DConfigBeanSupport extends XmlBeanSupport
032: implements DConfigBean {
033: private DDBean ddBean;
034:
035: public DConfigBeanSupport(DDBean ddBean, XmlObject xmlObject) {
036: super (xmlObject);
037: this .ddBean = ddBean;
038: }
039:
040: protected void setParent(DDBean ddBean, XmlObject xmlObject) {
041: this .ddBean = ddBean;
042: setXmlObject(xmlObject);
043: }
044:
045: public DDBean getDDBean() {
046: return ddBean;
047: }
048:
049: public DConfigBean getDConfigBean(DDBean bean)
050: throws ConfigurationException {
051: throw new ConfigurationException(
052: "No DConfigBean matching DDBean " + bean);
053: }
054:
055: public String[] getXpaths() {
056: return null;
057: }
058:
059: public void removeDConfigBean(DConfigBean bean)
060: throws BeanNotFoundException {
061: throw new BeanNotFoundException("No children");
062: }
063:
064: public void notifyDDChange(XpathEvent event) {
065: }
066:
067: protected String[] getXPathsWithPrefix(String prefix,
068: String[][] xpathSegments) {
069: String[] result = new String[xpathSegments.length];
070: for (int i = 0; i < xpathSegments.length; i++) {
071: String[] xpathSegmentArray = xpathSegments[i];
072: StringBuffer xpath = new StringBuffer();
073: for (int j = 0; j < xpathSegmentArray.length; j++) {
074: String segment = xpathSegmentArray[j];
075: if (prefix != null) {
076: xpath.append(prefix).append(":");
077: }
078: xpath.append(segment);
079: if (j < xpathSegmentArray.length - 1) {
080: xpath.append("/");
081: }
082: }
083: result[i] = xpath.toString();
084: }
085: return result;
086: }
087:
088: protected String[] getXPathsFromNamespace(String uri,
089: String[][] xpathSegments) {
090: String[] attributeNames = ddBean.getRoot().getAttributeNames();
091: for (int i = 0; i < attributeNames.length; i++) {
092: String attributeName = attributeNames[i];
093: if (attributeName.startsWith("xmlns")) {
094: if (ddBean.getRoot().getAttributeValue(attributeName)
095: .equals(uri)) {
096: if (attributeName.equals("xmlns")) {
097: return getXPathsWithPrefix(null, xpathSegments);
098: }
099: return getXPathsWithPrefix(attributeName
100: .substring(6), xpathSegments);
101: }
102: }
103: }
104: //we can't determine the namespace from looking at attributes, since the namespace is not an attribute.
105: //try assuming that the ddbeans strip namespaces from their xpath handing.
106: return getXPathsWithPrefix(null, xpathSegments);
107: }
108:
109: /**
110: * Each entry in the first array is an XPath.
111: * Each entry in the enclosed array is a component of that XPath (slashes omitted).
112: * so {{"foo","bar"},{"baz","foo"}} would represent "foo/bar" and "baz/foo"
113: */
114: protected String[] getXPathsForJ2ee_1_4(String[][] xpathSegments) {
115: return getXPathsFromNamespace(
116: "http://java.sun.com/xml/ns/j2ee", xpathSegments);
117: }
118: }
|