Package org.apache.geronimo.deployment.plugin

Source Code of org.apache.geronimo.deployment.plugin.DConfigBeanSupport

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

package org.apache.geronimo.deployment.plugin;

import javax.enterprise.deploy.model.DDBean;
import javax.enterprise.deploy.model.XpathEvent;
import javax.enterprise.deploy.spi.DConfigBean;
import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
import javax.enterprise.deploy.spi.exceptions.ConfigurationException;

import org.apache.xmlbeans.XmlObject;

/**
*
*
* @version $Rev: 355877 $ $Date: 2005-12-11 03:48:27 +0100 (Sun, 11 Dec 2005) $
*/
public abstract class DConfigBeanSupport extends XmlBeanSupport implements DConfigBean {
    private DDBean ddBean;

    public DConfigBeanSupport(DDBean ddBean, XmlObject xmlObject) {
        super(xmlObject);
        this.ddBean = ddBean;
    }

    protected void setParent(DDBean ddBean, XmlObject xmlObject) {
        this.ddBean = ddBean;
        setXmlObject(xmlObject);
    }

    public DDBean getDDBean() {
        return ddBean;
    }

    public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException {
        throw new ConfigurationException("No DConfigBean matching DDBean "+bean);
    }

    public String[] getXpaths() {
        return null;
    }

    public void removeDConfigBean(DConfigBean bean) throws BeanNotFoundException {
        throw new BeanNotFoundException("No children");
    }

    public void notifyDDChange(XpathEvent event) {
    }

    protected String[] getXPathsWithPrefix(String prefix, String[][] xpathSegments) {
        String[] result = new String[xpathSegments.length];
        for (int i = 0; i < xpathSegments.length; i++) {
            String[] xpathSegmentArray = xpathSegments[i];
            StringBuffer xpath = new StringBuffer();
            for (int j = 0; j < xpathSegmentArray.length; j++) {
                String segment = xpathSegmentArray[j];
                if (prefix != null) {
                    xpath.append(prefix).append(":");
                }
                xpath.append(segment);
                if (j < xpathSegmentArray.length -1) {
                    xpath.append("/");
                }
            }
            result[i] = xpath.toString();
        }
        return result;
    }

    protected String[] getXPathsFromNamespace(String uri, String[][] xpathSegments) {
        String[] attributeNames = ddBean.getRoot().getAttributeNames();
        for (int i = 0; i < attributeNames.length; i++) {
            String attributeName = attributeNames[i];
            if (attributeName.startsWith("xmlns")) {
                if (ddBean.getRoot().getAttributeValue(attributeName).equals(uri)) {
                    if (attributeName.equals("xmlns")) {
                        return getXPathsWithPrefix(null , xpathSegments);
                    }
                    return getXPathsWithPrefix(attributeName.substring(6), xpathSegments);
                }
            }
        }
        //we can't determine the namespace from looking at attributes, since the namespace is not an attribute.
        //try assuming that the ddbeans strip namespaces from their xpath handing.
        return getXPathsWithPrefix(null , xpathSegments);
    }

    /**
     * Each entry in the first array is an XPath.
     * Each entry in the enclosed array is a component of that XPath (slashes omitted).
     * so {{"foo","bar"},{"baz","foo"}} would represent "foo/bar" and "baz/foo"
     */
    protected String[] getXPathsForJ2ee_1_4(String[][] xpathSegments) {
        return getXPathsFromNamespace("http://java.sun.com/xml/ns/j2ee", xpathSegments);
    }
}
TOP

Related Classes of org.apache.geronimo.deployment.plugin.DConfigBeanSupport

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.