Example usage for javax.xml.namespace QName getNamespaceURI

List of usage examples for javax.xml.namespace QName getNamespaceURI

Introduction

In this page you can find the example usage for javax.xml.namespace QName getNamespaceURI.

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

From source file:Main.java

/**
 * Creates a new Element having the specified qualified name. The element
 * must be {@link Document#adoptNode(Node) adopted} when inserted into
 * another Document.//www  .java  2s. c  o  m
 * 
 * @param qName
 *            A QName object.
 * @return An Element node (with a Document owner but no parent).
 */
public static Element createElement(QName qName) {
    Document doc = null;
    try {
        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
    StringBuilder nodeName = new StringBuilder();
    if (qName.getPrefix().isEmpty()) {
        nodeName.append(qName.getLocalPart());
    } else {
        nodeName.append(qName.getPrefix()).append(':').append(qName.getLocalPart());
    }
    Element elem = doc.createElementNS(qName.getNamespaceURI(), nodeName.toString());
    return elem;
}

From source file:io.cloudslang.content.xml.utils.XmlUtils.java

/**
 * Returns the Namespaces context from an xml.
 *
 * @param xmlString   xml as string/*from w w  w.j  a v a  2s  .  c  o m*/
 * @param xmlFilePath path to xml file
 * @return the Namespaces context from an xml.
 * @throws IOException        file reading exception
 * @throws XMLStreamException parsing exception
 */
public static NamespaceContext getNamespaceContext(String xmlString, String xmlFilePath) throws Exception {
    InputStream inputXML = getStream(xmlString, xmlFilePath);
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(inputXML);
    Map<String, String> namespaces = new HashMap<>();
    while (reader.hasNext()) {
        int evt = reader.next();
        if (evt == XMLStreamConstants.START_ELEMENT) {
            QName qName = reader.getName();
            if (qName != null) {
                if (qName.getPrefix() != null && qName.getPrefix().compareTo("") != 0)
                    namespaces.put(qName.getPrefix(), qName.getNamespaceURI());
            }
        }
    }
    return new SimpleNamespaceContext(namespaces);
}

From source file:com.evolveum.midpoint.repo.sql.util.RUtil.java

public static String qnameToString(QName qname) {
    StringBuilder sb = new StringBuilder();
    if (qname != null) {
        sb.append(qname.getNamespaceURI());
    }/*from w w  w .  j a va  2 s . c o  m*/
    sb.append(QNAME_DELIMITER);
    if (qname != null) {
        sb.append(qname.getLocalPart());
    }

    return sb.toString();
}

From source file:com.evolveum.midpoint.model.client.ModelClientUtil.java

public static Element createTextElement(QName qname, String value, Document doc) {
    Element element = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
    element.setTextContent(value);/*from  www.jav a 2  s.  co  m*/
    return element;
}

From source file:jp.go.nict.langrid.bpel.ProcessAnalyzer.java

/**
 * /* w w  w  .  j  av a2  s .co  m*/
 * 
 */
public static void resolve(BPEL bpel, Map<URI, WSDL> wsdls)
        throws ProcessAnalysisException, URISyntaxException {
    // EndpointReference?
    for (WSDL w : wsdls.values()) {
        for (Service s : w.getServices().values()) {
            for (Port p : s.getPorts().values()) {
                EndpointReference epr = new EndpointReference();
                epr.setServiceName(new QName(w.getTargetNamespace().toString(), s.getName()));
                epr.setServicePortName(p.getName());
                epr.setAddress(p.getAddress());

                QName binding = p.getBinding();
                WSDL bw = wsdls.get(new URI(binding.getNamespaceURI()));
                assert bw != null;
                QName bindingType = bw.getBindingTypes().get(binding.getLocalPart());
                WSDL btw = wsdls.get(new URI(bindingType.getNamespaceURI()));
                assert btw != null;
                Map<String, EndpointReference> map = btw.getPortTypeToEndpointReference();
                if (map == null) {
                    map = new HashMap<String, EndpointReference>();
                    btw.setPortTypeToEndpointReference(map);
                }
                map.put(p.getName(), epr);
            }
        }
    }
    Map<QName, EndpointReference> portTypeQNameToEndpointReference = new HashMap<QName, EndpointReference>();
    Map<QName, PartnerLinkType> qnameToPartnerLinkType = new HashMap<QName, PartnerLinkType>();
    Map<QName, QName> bindingNameToServiceName = new HashMap<QName, QName>();
    for (WSDL w : wsdls.values()) {
        String tns = w.getTargetNamespace().toString();
        for (Map.Entry<String, EndpointReference> e : w.getPortTypeToEndpointReference().entrySet()) {
            portTypeQNameToEndpointReference.put(new QName(tns, e.getKey()), e.getValue());
        }
        for (Map.Entry<String, PartnerLinkType> e : w.getPlinks().entrySet()) {
            qnameToPartnerLinkType.put(new QName(tns, e.getKey()), e.getValue());
        }
        for (Service s : w.getServices().values()) {
            for (Port p : s.getPorts().values()) {
                bindingNameToServiceName.put(p.getBinding(), new QName(tns, s.getName()));
            }
        }
    }
    Map<QName, QName> portTypeNameToServiceName = new HashMap<QName, QName>();
    for (WSDL w : wsdls.values()) {
        String tns = w.getTargetNamespace().toString();
        for (Map.Entry<String, QName> e : w.getBindingTypes().entrySet()) {
            portTypeNameToServiceName.put(e.getValue(),
                    bindingNameToServiceName.get(new QName(tns, e.getKey())));
        }
    }

    // PartnerLink -> ServiceName
    // PartnerLink -> EndpointReference
    // ?
    for (PartnerLink p : bpel.getPartnerLinks()) {
        // PartnerLink -> wsdl?plink:partnerLinkType
        QName pltName = p.getPartnerLinkType();
        PartnerLinkType plt = qnameToPartnerLinkType.get(pltName);
        if (plt == null) {
            throw new ProcessAnalysisException("couldn't find partner link type for: " + pltName);
        }

        // myRole?
        String myRole = p.getMyRole();
        if (myRole != null) {
            Role role = plt.getRoles().get(myRole);
            if (role == null) {
                throw new ProcessAnalysisException("The my role \"" + myRole + "\" for partner link name \""
                        + plt.getName() + "\" is not found.");
            }

            QName portTypeName = role.getPortTypeName();
            QName serviceName = portTypeNameToServiceName.get(portTypeName);
            if (serviceName != null) {
                p.setService(serviceName.getLocalPart());
            } else {
                // ???????
                p.setService(bpel.getProcessName());
            }
        }

        // partnerRole?
        String partnerRole = p.getPartnerRole();
        if (partnerRole != null) {
            Role role = plt.getRoles().get(partnerRole);
            if (role == null) {
                throw new ProcessAnalysisException("The partner role \"" + partnerRole
                        + "\" for partner link name \"" + plt.getName() + "\" is not found.");
            }

            QName portTypeName = role.getPortTypeName();
            EndpointReference epr = portTypeQNameToEndpointReference.get(portTypeName);
            if (epr == null) {
                throw new ProcessAnalysisException(
                        "The EndpointReference for port type \"" + portTypeName + "\" is not found.");
            }
            p.setEndpointReference(epr);
        }
    }
}

From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.AttachmentUtils.java

public static AttachmentEncoding getAttachmentEncoding(WsdlOperation operation, String partName,
        boolean isResponse) {
    // make sure we have access
    if (operation == null || operation.getBindingOperation() == null
            || operation.getBindingOperation().getOperation() == null) {
        return AttachmentEncoding.NONE;
    }//from w  w  w .  j  a  v a  2s.  c  o  m

    javax.wsdl.Part part = null;

    if (isResponse) {
        Output output = operation.getBindingOperation().getOperation().getOutput();
        if (output == null || output.getMessage() == null) {
            return AttachmentEncoding.NONE;
        } else {
            part = output.getMessage().getPart(partName);
        }
    } else {
        Input input = operation.getBindingOperation().getOperation().getInput();
        if (input == null || input.getMessage() == null) {
            return AttachmentEncoding.NONE;
        } else {
            part = input.getMessage().getPart(partName);
        }
    }

    if (part != null) {
        QName typeName = part.getTypeName();
        if (typeName.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {
            if (typeName.getLocalPart().equals("base64Binary")) {
                return AttachmentEncoding.BASE64;
            } else if (typeName.getLocalPart().equals("hexBinary")) {
                return AttachmentEncoding.HEX;
            }
        }
    }

    return AttachmentEncoding.NONE;
}

From source file:Main.java

/**
 * @param doc//from   w ww  .ja va  2  s  .  com
 *            The Document that is the factory for the new Element.
 * @param qname
 *            The QName of the new Element.
 * @return An empty Element whose owner is the given Document.
 */
private static Element createEmptyElement(final Document doc, final QName qname) {
    final String prefix = qname.getPrefix();
    String name = qname.getLocalPart();

    //
    // NOTE: The DOM API requires that elements with qualified names 
    //       be created with prefix:localName as the tag name. We 
    //       CANNOT just use the localName and expect the API to fill 
    //       in a prefix, nor can we use setPrefix after creation. For 
    //       parsing to work correctly, the second argument to the 
    //       createElementNS method MUST be a qualified name.
    //
    if (prefix != null && prefix.length() > 0)
        name = prefix + ':' + name;

    final String uri = qname.getNamespaceURI();

    return doc.createElementNS(uri, name);
}

From source file:com.evolveum.midpoint.schema.constants.ObjectTypes.java

public static ObjectTypes getObjectTypeFromTypeQName(QName typeQName) {
    if (typeQName == null) {
        return null;
    }//from w  w w .  j  a v  a2 s  .c  o  m
    // HACK WARNING! FIXME
    // UGLY HORRIBLE TERRIBLE AWFUL HACK FOLLOWS
    // The JAXB fails to correctly process QNames in default namespace (no prefix)
    // e.g it will not understand this: type="RoleType", even if defatult namespace
    // is set, it will parse it as null namespace.
    // Therefore substitute null namespace with common namespace
    if (typeQName.getNamespaceURI() == null || typeQName.getNamespaceURI().isEmpty()) {
        typeQName = new QName(SchemaConstants.NS_C, typeQName.getLocalPart());
    }
    // END OF UGLY HACK

    for (ObjectTypes type : values()) {
        if (QNameUtil.match(type.getTypeQName(), typeQName)) {
            return type;
        }
    }
    throw new IllegalArgumentException("Unsupported object type qname " + typeQName);
}

From source file:com.evolveum.midpoint.testing.wstest.AbstractWebserviceTest.java

protected static Element createTextElement(QName qname, String value, Document doc) {
    Element element = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
    element.setTextContent(value);/*from w w  w . ja v  a  2s  . c  o  m*/
    return element;
}

From source file:com.evolveum.liferay.usercreatehook.ws.ModelPortWrapper.java

private static Element createTextElement(QName qname, String value, Document doc) {
    Element element = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
    element.setTextContent(value);//from w  ww . ja  v a2 s . c  o m
    return element;
}