Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * This file belongs to the BPELUnit utility and Eclipse plugin set. See enclosed
 * license file for more information.
 */

import javax.xml.namespace.QName;

import org.w3c.dom.Element;

public class Main {
    public static QName resolveQName(String qNameWithPrefix, Element element) {
        String nsPrefix;
        String localName;
        if (qNameWithPrefix.contains(":")) {
            String[] parts = qNameWithPrefix.split(":");
            nsPrefix = parts[0];
            localName = parts[1];
        } else {
            nsPrefix = "";
            localName = qNameWithPrefix;
        }

        return new QName(resolveNamespacePrefix(nsPrefix, element), localName);
    }

    public static String resolveNamespacePrefix(String prefix, Element element) {
        String namespace = null;

        if ("".equals(prefix)) {
            namespace = element.getAttribute("xmlns");
        } else {
            namespace = element.getAttribute("xmlns:" + prefix);
        }
        if (namespace != null && !"".equals(namespace)) {
            return namespace;
        }

        if (element.getParentNode() instanceof Element) {
            return resolveNamespacePrefix(prefix, (Element) element.getParentNode());
        } else {
            throw new RuntimeException("Cannot resolve prefix " + prefix);
        }
    }
}