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:org.eclipse.winery.repository.client.WineryRepositoryClient.java

/**
 * {@inheritDoc}/*  w w w.  j a  v  a2  s.c  o  m*/
 *
 * Does NOT check for global QName uniqueness, only in the scope of all
 * artifact templates
 */
@Override
public void createArtifactTemplate(QName qname, QName artifactType) throws QNameAlreadyExistsException {
    WebResource artifactTemplates = this.primaryWebResource.path("artifacttemplates");
    MultivaluedMap<String, String> map = new MultivaluedMapImpl();
    map.putSingle("namespace", qname.getNamespaceURI());
    map.putSingle("name", qname.getLocalPart());
    map.putSingle("type", artifactType.toString());
    ClientResponse response = artifactTemplates.type(MediaType.APPLICATION_FORM_URLENCODED)
            .accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, map);
    if (response.getClientResponseStatus() != ClientResponse.Status.CREATED) {
        // TODO: pass ClientResponse.Status somehow
        // TODO: more fine grained checking for error message. Not all
        // failures are that the QName already exists
        LOGGER.debug(String.format("Error %d when creating id %s from URI %s", response.getStatus(),
                qname.toString(), this.primaryWebResource.getURI().toString()));
        throw new QNameAlreadyExistsException();
    }
    // no further return is made
}

From source file:com.evolveum.midpoint.prism.lex.json.AbstractJsonLexicalProcessor.java

private void processDefaultNamespaces(XNode xnode, String parentDefault, JsonParsingContext ctx) {
    if (xnode instanceof MapXNode) {
        MapXNode map = (MapXNode) xnode;
        final String currentDefault = ctx.defaultNamespaces.getOrDefault(map, parentDefault);
        for (Entry<QName, XNode> entry : map.entrySet()) {
            QName fieldName = entry.getKey();
            XNode subnode = entry.getValue();
            if (StringUtils.isNotEmpty(currentDefault) && StringUtils.isEmpty(fieldName.getNamespaceURI())
                    && !ctx.noNamespaceEntries.containsKey(entry)) {
                map.qualifyKey(fieldName, currentDefault);
            }//from   ww  w  .ja  va  2s. co m
            processDefaultNamespaces(subnode, currentDefault, ctx);
        }
        qualifyElementNameIfNeeded(map, currentDefault, ctx);
    } else {
        qualifyElementNameIfNeeded(xnode, parentDefault, ctx);
        if (xnode instanceof ListXNode) {
            for (XNode item : (ListXNode) xnode) {
                processDefaultNamespaces(item, parentDefault, ctx);
            }
        }
    }
}

From source file:org.eclipse.winery.repository.client.WineryRepositoryClient.java

/**
 * {@inheritDoc}/* w w  w.j  a v  a 2 s.c om*/
 */
@Override
public void createComponent(QName qname, Class<? extends TOSCAComponentId> idClass)
        throws QNameAlreadyExistsException {
    WebResource resource = this.primaryWebResource.path(Util.getRootPathFragment(idClass));
    MultivaluedMap<String, String> map = new MultivaluedMapImpl();
    map.putSingle("namespace", qname.getNamespaceURI());
    map.putSingle("name", qname.getLocalPart());
    ClientResponse response = resource.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN)
            .post(ClientResponse.class, map);
    if (response.getClientResponseStatus() != ClientResponse.Status.CREATED) {
        // TODO: pass ClientResponse.Status somehow
        // TODO: more fine grained checking for error message. Not all failures are that the QName already exists
        LOGGER.debug(String.format("Error %d when creating id %s from URI %s", response.getStatus(),
                qname.toString(), this.primaryWebResource.getURI().toString()));
        throw new QNameAlreadyExistsException();
    }
    // no further return is made
}

From source file:com.evolveum.midpoint.prism.lex.json.AbstractJsonLexicalProcessor.java

@SuppressWarnings("unused") // TODO
private String serializeNsIfNeeded(QName subNodeName, String globalNamespace, JsonGenerator generator)
        throws IOException {
    if (subNodeName == null) {
        return globalNamespace;
    }//w  w  w.  j a  va  2 s.c  o  m
    String subNodeNs = subNodeName.getNamespaceURI();
    if (StringUtils.isNotBlank(subNodeNs)) {
        if (!subNodeNs.equals(globalNamespace)) {
            globalNamespace = subNodeNs;
            generator.writeStringField(PROP_NAMESPACE, globalNamespace);

        }
    }
    return globalNamespace;
}

From source file:org.apache.servicemix.jbi.cluster.engine.ClusterEngine.java

/**
 * Process a JMS message//  w w  w  .j  av a  2s . c  om
 *
 * @param requestor the item to use
 * @throws JMSException if an error occur
 */
protected void process(JmsRequestor requestor) throws JMSException {
    javax.jms.Message message = requestor.getMessage();
    int type = message.getIntProperty(JBI_MESSAGE);
    switch (type) {
    case JBI_MESSAGE_DONE: {
        String corrId = message.getStringProperty(PROPERTY_CORR_ID);
        if (corrId == null) {
            throw new IllegalStateException("Incoming JMS message has no correlationId");
        }
        Exchange exchange = exchanges.remove(corrId);
        if (exchange == null) {
            throw new IllegalStateException("Exchange not found for id " + corrId);
        }
        done(exchange);
        break;
    }
    case JBI_MESSAGE_ERROR: {
        String corrId = message.getStringProperty(PROPERTY_CORR_ID);
        if (corrId == null) {
            throw new IllegalStateException("Incoming JMS message has no correlationId");
        }
        Exchange exchange = exchanges.remove(corrId);
        if (exchange == null) {
            throw new IllegalStateException("Exchange not found for id " + corrId);
        }
        fail(exchange, (Exception) ((ObjectMessage) message).getObject());
        break;
    }
    case JBI_MESSAGE_IN: {
        String mep = message.getStringProperty(JBI_MEP);
        if (mep == null) {
            throw new IllegalStateException(
                    "Exchange MEP not found for JMS message " + message.getJMSMessageID());
        }
        Exchange exchange = getChannel().createExchange(Pattern.fromWsdlUri(mep));
        exchange.setProperty(PROPERTY_ROLLBACK_ON_ERRORS + "." + name,
                message.getBooleanProperty(PROPERTY_ROLLBACK_ON_ERRORS));
        if (message.propertyExists(JBI_INTERFACE)) {
            exchange.setProperty(MessageExchangeImpl.INTERFACE_NAME_PROP,
                    QName.valueOf(message.getStringProperty(JBI_INTERFACE)));
        }
        if (message.propertyExists(JBI_OPERATION)) {
            exchange.setOperation(QName.valueOf(message.getStringProperty(JBI_OPERATION)));
        }
        if (message.propertyExists(JBI_SERVICE)) {
            exchange.setProperty(MessageExchangeImpl.SERVICE_NAME_PROP,
                    QName.valueOf(message.getStringProperty(JBI_SERVICE)));
        }
        if (message.propertyExists(JBI_ENDPOINT)) {
            QName q = QName.valueOf(message.getStringProperty(JBI_ENDPOINT));
            String e = q.getLocalPart();
            q = QName.valueOf(q.getNamespaceURI());
            ServiceEndpoint se = getEndpoint(q, e);
            // TODO: check that endpoint exists
            exchange.setProperty(MessageExchangeImpl.SERVICE_ENDPOINT_PROP, se);
        }
        // Re-process JBI addressing
        DeliveryChannelImpl.createTarget(getChannel().getNMR(), exchange);
        // TODO: read exchange properties
        Message msg = (Message) ((ObjectMessage) message).getObject();
        exchange.setIn(msg);
        exchanges.put(exchange.getId(), exchange);
        if (pendingExchanges.incrementAndGet() >= maxPendingExchanges) {
            if (pauseConsumption.compareAndSet(false, true)) {
                invalidateSelector();
            }
        }
        exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId());
        requestor.suspend(exchange.getId());
        if (requestor.getTransaction() != null) {
            exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, requestor.getTransaction());
        }
        send(exchange);
        break;
    }
    case JBI_MESSAGE_OUT: {
        String corrId = message.getStringProperty(PROPERTY_CORR_ID);
        if (corrId == null) {
            throw new IllegalStateException("Incoming JMS message has no correlationId");
        }
        Exchange exchange = exchanges.get(corrId);
        if (exchange == null) {
            throw new IllegalStateException("Exchange not found for id " + corrId);
        }
        Message msg = (Message) ((ObjectMessage) message).getObject();
        exchange.setOut(msg);
        exchanges.put(exchange.getId(), exchange);
        exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId());
        requestor.suspend(exchange.getId());
        if (requestor.getTransaction() != null) {
            exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, requestor.getTransaction());
        }
        send(exchange);
        break;
    }
    case JBI_MESSAGE_FAULT: {
        String corrId = message.getStringProperty(PROPERTY_CORR_ID);
        if (corrId == null) {
            throw new IllegalStateException("Incoming JMS message has no correlationId");
        }
        Exchange exchange = exchanges.get(corrId);
        if (exchange == null) {
            throw new IllegalStateException("Exchange not found for id " + corrId);
        }
        Message msg = (Message) ((ObjectMessage) message).getObject();
        exchange.setFault(msg);
        exchanges.put(exchange.getId(), exchange);
        exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId());
        requestor.suspend(exchange.getId());
        if (requestor.getTransaction() != null) {
            exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, requestor.getTransaction());
        }
        send(exchange);
        break;
    }
    default: {
        throw new IllegalStateException("Received unknown message type: " + type);
    }
    }
}

From source file:microsoft.exchange.webservices.data.core.EwsXmlReader.java

public boolean readToDescendant(String localName, String namespaceURI) throws XMLStreamException {

    if (!this.isStartElement()) {
        return false;
    }/*from ww  w  . ja va  2  s.com*/
    XMLEvent startEvent = this.presentEvent;
    XMLEvent event = this.presentEvent;
    do {
        if (event.isStartElement()) {
            QName qEName = event.asStartElement().getName();
            if (qEName.getLocalPart().equals(localName) && qEName.getNamespaceURI().equals(namespaceURI)) {
                return true;
            }
        }
        event = this.xmlReader.nextEvent();
    } while (!checkEndElement(startEvent, event));

    return false;
}

From source file:com.evolveum.midpoint.prism.schema.DomToSchemaPostProcessor.java

private boolean isMyNamespace(QName qname) {
    return getNamespace().equals(qname.getNamespaceURI());
}

From source file:com.example.soaplegacy.WsdlValidator.java

private void validateDocLiteral(BindingOperation bindingOperation, Part[] parts, XmlObject msgXml,
        List<XmlError> errors, boolean isResponse, boolean strict) throws Exception {

    Part part = null;//from w  w  w .  ja  va  2 s  .c om
    // start by finding body part
    for (int c = 0; c < parts.length; c++) {
        // content part?
        if ((isResponse && !WsdlUtils.isAttachmentOutputPart(parts[c], bindingOperation))
                || (!isResponse && !WsdlUtils.isAttachmentInputPart(parts[c], bindingOperation))) {
            // already found?
            if (part != null) {
                if (strict) {
                    errors.add(XmlError.forMessage("DocLiteral message must contain 1 body part definition"));
                }
                return;
            }
            part = parts[c];
        }
    }

    QName elementName = part.getElementName();
    if (elementName != null) {
        // just check for correct message element, other elements are avoided
        // (should create an error)
        XmlObject[] paths = msgXml
                .selectPath("declare namespace env='" + wsdlContext.getSoapVersion().getEnvelopeNamespace()
                        + "';" + "declare namespace ns='" + elementName.getNamespaceURI() + "';"
                        + "$this/env:Envelope/env:Body/ns:" + elementName.getLocalPart());

        if (paths.length == 1) {
            SchemaGlobalElement elm = wsdlContext.getSchemaTypeLoader().findElement(elementName);
            if (elm != null) {
                validateMessageBody(errors, elm.getType(), paths[0]);

                // ensure no other elements in body
                NodeList children = XmlUtils.getChildElements((Element) paths[0].getDomNode().getParentNode());
                for (int d = 0; d < children.getLength(); d++) {
                    QName childName = XmlUtils.getQName(children.item(d));
                    if (!elementName.equals(childName)) {
                        XmlCursor cur = paths[0].newCursor();
                        cur.toParent();
                        cur.toChild(childName);
                        errors.add(XmlError.forCursor("Invalid element [" + childName + "] in SOAP Body", cur));
                        cur.dispose();
                    }
                }
            } else {
                errors.add(XmlError.forMessage("Missing part type [" + elementName + "] in associated schema"));
            }
        } else {
            errors.add(XmlError.forMessage("Missing message part with name [" + elementName + "]"));
        }
    } else if (part.getTypeName() != null) {
        QName typeName = part.getTypeName();

        XmlObject[] paths = msgXml.selectPath("declare namespace env='"
                + wsdlContext.getSoapVersion().getEnvelopeNamespace() + "';" + "declare namespace ns='"
                + typeName.getNamespaceURI() + "';" + "$this/env:Envelope/env:Body/ns:" + part.getName());

        if (paths.length == 1) {
            SchemaType type = wsdlContext.getSchemaTypeLoader().findType(typeName);
            if (type != null) {
                validateMessageBody(errors, type, paths[0]);
                // XmlObject obj = paths[0].copy().changeType( type );
                // obj.validate( new XmlOptions().setErrorListener( errors ));
            } else
                errors.add(XmlError.forMessage("Missing part type in associated schema"));
        } else
            errors.add(XmlError.forMessage(
                    "Missing message part with name:type [" + part.getName() + ":" + typeName + "]"));
    }
}

From source file:org.bedework.util.dav.DavUtil.java

/** Do a synch report on the targeted collection.
 *
 *
 * @param cl http client/*from   ww  w  .  j a  v  a  2s.c om*/
 * @param path of collection
 * @param syncToken from last report or null
 * @param props   null for a default set
 * @return Collection of DavChild or null for not found
 * @throws Throwable
 */
public Collection<DavChild> syncReport(final BasicHttpClient cl, final String path, final String syncToken,
        final Collection<QName> props) throws Throwable {
    final StringWriter sw = new StringWriter();
    final XmlEmit xml = getXml();

    addNs(xml, WebdavTags.namespace);

    xml.startEmit(sw);

    /*
      <?xml version="1.0" encoding="utf-8" ?>
      <D:sync-collection xmlns:D="DAV:"
                 xmlns:C="urn:ietf:params:xml:ns:caldav">
        <D:sync-token/>
        <D:prop>
          <D:getetag/>
        </D:prop>
      </D:sync-collection>
     */
    xml.openTag(WebdavTags.syncCollection);
    if (syncToken == null) {
        xml.emptyTag(WebdavTags.syncToken);
    } else {
        xml.property(WebdavTags.syncToken, syncToken);
    }
    xml.property(WebdavTags.synclevel, "1");
    xml.openTag(WebdavTags.prop);
    xml.emptyTag(WebdavTags.getetag);

    if (props != null) {
        for (final QName pr : props) {
            if (pr.equals(WebdavTags.getetag)) {
                continue;
            }

            addNs(xml, pr.getNamespaceURI());
            xml.emptyTag(pr);
        }
    }

    xml.closeTag(WebdavTags.prop);
    xml.closeTag(WebdavTags.syncCollection);

    final byte[] content = sw.toString().getBytes();

    final int res = sendRequest(cl, "REPORT", path, depth0, "text/xml", // contentType,
            content.length, // contentLen,
            content);

    if (res == HttpServletResponse.SC_NOT_FOUND) {
        return null;
    }

    final int SC_MULTI_STATUS = 207; // not defined for some reason
    if (res != SC_MULTI_STATUS) {
        if (debug()) {
            debug("Got response " + res + " for path " + path);
        }

        //throw new Exception("Got response " + res + " for path " + path);
        return null;
    }

    final Document doc = parseContent(cl.getResponseBodyAsStream());

    final Element root = doc.getDocumentElement();

    /*    <!ELEMENT multistatus (response+, responsedescription?) > */

    expect(root, WebdavTags.multistatus);

    return processResponses(getChildren(root), null);
}

From source file:com.example.soaplegacy.WsdlValidator.java

private void validateRpcLiteral(BindingOperation bindingOperation, Part[] parts, XmlObject msgXml,
        List<XmlError> errors, boolean isResponse, boolean strict) throws Exception {
    if (parts.length == 0)
        return;//from  w w w.j a  va  2  s.  co  m

    XmlObject[] bodyParts = getRpcBodyPart(bindingOperation, msgXml, isResponse);

    if (bodyParts.length != 1) {
        errors.add(XmlError.forMessage(
                "Missing message wrapper element [" + WsdlUtils.getTargetNamespace(wsdlContext.getDefinition())
                        + "@" + bindingOperation.getName() + (isResponse ? "Response" : "")));
    } else {
        XmlObject wrapper = bodyParts[0];

        for (int i = 0; i < parts.length; i++) {
            Part part = parts[i];

            // skip attachment parts
            if (isResponse) {
                if (WsdlUtils.isAttachmentOutputPart(part, bindingOperation))
                    continue;
            } else {
                if (WsdlUtils.isAttachmentInputPart(part, bindingOperation))
                    continue;
            }

            // find part in message
            XmlObject[] children = wrapper.selectChildren(new QName(part.getName()));

            // not found?
            if (children.length != 1) {
                // try element name (loophole in basic-profile spec?)
                QName elementName = part.getElementName();
                if (elementName != null) {
                    bodyParts = msgXml.selectPath("declare namespace env='"
                            + wsdlContext.getSoapVersion().getEnvelopeNamespace() + "';"
                            + "declare namespace ns='" + wsdlContext.getDefinition().getTargetNamespace() + "';"
                            + "declare namespace ns2='" + elementName.getNamespaceURI() + "';"
                            + "$this/env:Envelope/env:Body/ns:" + bindingOperation.getName()
                            + (isResponse ? "Response" : "") + "/ns2:" + elementName.getLocalPart());

                    if (bodyParts.length == 1) {
                        SchemaGlobalElement elm = wsdlContext.getSchemaTypeLoader().findElement(elementName);
                        if (elm != null) {
                            validateMessageBody(errors, elm.getType(), bodyParts[0]);
                        } else
                            errors.add(XmlError.forMessage(
                                    "Missing part type in associated schema for [" + elementName + "]"));
                    } else
                        errors.add(XmlError.forMessage("Missing message part with name [" + elementName + "]"));
                } else {
                    errors.add(XmlError.forMessage("Missing message part [" + part.getName() + "]"));
                }
            } else {
                QName typeName = part.getTypeName();
                SchemaType type = wsdlContext.getSchemaTypeLoader().findType(typeName);
                if (type != null) {
                    validateMessageBody(errors, type, children[0]);
                } else {
                    errors.add(XmlError
                            .forMessage("Missing type in associated schema for part [" + part.getName() + "]"));
                }
            }
        }
    }
}