Java Code Examples for javax.xml.namespace.QName#getPrefix()

The following examples show how to use javax.xml.namespace.QName#getPrefix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
 
Example 2
Source File: XmlPolicyModelUnmarshaller.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
 
Example 3
Source File: XmlPolicyModelUnmarshaller.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
 
Example 4
Source File: TypeInfo.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public TypeInfo(QName tagName, Type type, Annotation... annotations) {
        if(tagName==null || type==null || annotations==null) {
            String nullArgs = "";

            if(tagName == null)     nullArgs = "tagName";
            if(type == null)        nullArgs += (nullArgs.length() > 0 ? ", type" : "type");
            if(annotations == null) nullArgs += (nullArgs.length() > 0 ? ", annotations" : "annotations");

//            Messages.ARGUMENT_CANT_BE_NULL.format(nullArgs);

            throw new IllegalArgumentException( "Argument(s) \"" + nullArgs + "\" can''t be null.)");
        }

        this.tagName = new QName(tagName.getNamespaceURI().intern(), tagName.getLocalPart().intern(), tagName.getPrefix());
        this.type = type;
        if (type instanceof Class && ((Class<?>)type).isPrimitive()) nillable = false;
        this.annotations = annotations;
    }
 
Example 5
Source File: XmlPolicyModelUnmarshaller.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
 
Example 6
Source File: StAXStream2SAX.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void handleEndElement() throws XMLStreamException {
    QName qName = staxStreamReader.getName();

    try {
        //construct prefix:localName from qName
        String qname = "";
        if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
            qname = qName.getPrefix() + ":";
        }
        qname += qName.getLocalPart();

        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        int nsCount = staxStreamReader.getNamespaceCount();
        for (int i = nsCount - 1; i >= 0; i--) {
            String prefix = staxStreamReader.getNamespacePrefix(i);
            if (prefix == null) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example 7
Source File: StAXEventConnector.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the attributes associated with the given START_ELEMENT StAXevent.
 *
 * @return the StAX attributes converted to an org.xml.sax.Attributes
 */
private Attributes getAttributes(StartElement event) {
    attrs.clear();

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (Iterator i = event.getAttributes(); i.hasNext();) {
        Attribute staxAttr = (Attribute)i.next();

        QName name = staxAttr.getName();
        String uri = fixNull(name.getNamespaceURI());
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
        String qName;
        if (prefix == null || prefix.length() == 0)
            qName = localName;
        else
            qName = prefix + ':' + localName;
        String type = staxAttr.getDTDType();
        String value = staxAttr.getValue();

        attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
}
 
Example 8
Source File: StAXStream2SAX.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void handleEndElement() throws XMLStreamException {
    QName qName = staxStreamReader.getName();

    try {
        //construct prefix:localName from qName
        String qname = "";
        if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
            qname = qName.getPrefix() + ":";
        }
        qname += qName.getLocalPart();

        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        int nsCount = staxStreamReader.getNamespaceCount();
        for (int i = nsCount - 1; i >= 0; i--) {
            String prefix = staxStreamReader.getNamespacePrefix(i);
            if (prefix == null) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example 9
Source File: SerializerVocabulary.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void addToNameTable(QName n, LocalNameQualifiedNamesMap m) {
    int namespaceURIIndex = -1;
    int prefixIndex = -1;
    if (n.getNamespaceURI().length() > 0) {
        namespaceURIIndex = namespaceName.obtainIndex(n.getNamespaceURI());
        if (namespaceURIIndex == KeyIntMap.NOT_PRESENT) {
            namespaceURIIndex = namespaceName.get(n.getNamespaceURI());
        }

        if (n.getPrefix().length() > 0) {
            prefixIndex = prefix.obtainIndex(n.getPrefix());
            if (prefixIndex == KeyIntMap.NOT_PRESENT) {
                prefixIndex = prefix.get(n.getPrefix());
            }
        }
    }

    int localNameIndex = localName.obtainIndex(n.getLocalPart());
    if (localNameIndex == KeyIntMap.NOT_PRESENT) {
        localNameIndex = localName.get(n.getLocalPart());
    }

    QualifiedName name = new QualifiedName(n.getPrefix(), n.getNamespaceURI(), n.getLocalPart(),
            m.getNextIndex(),
            prefixIndex, namespaceURIIndex, localNameIndex);

    LocalNameQualifiedNamesMap.Entry entry = null;
    if (_useLocalNameAsKey) {
        entry = m.obtainEntry(n.getLocalPart());
    } else {
        String qName = (prefixIndex == -1)
            ? n.getLocalPart()
            : n.getPrefix() + ":" + n.getLocalPart();
        entry = m.obtainEntry(qName);
    }

    entry.addQualifiedName(name);
}
 
Example 10
Source File: ElementImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static String getQualifiedName(QName name) {
    String prefix = name.getPrefix();
    String localName = name.getLocalPart();
    String qualifiedName = null;

        if (prefix != null && prefix.length() > 0) {
            qualifiedName = prefix + ":" + localName;
        } else {
            qualifiedName = localName;
        }
     return qualifiedName;
}
 
Example 11
Source File: Fault1_2Impl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void appendFaultSubcode(QName subcode) throws SOAPException {
    if (subcode == null) {
        return;
    }
    if (subcode.getNamespaceURI() == null ||
        "".equals(subcode.getNamespaceURI())) {

        log.severe("SAAJ0432.ver1_2.subcode.not.ns.qualified");
        throw new SOAPExceptionImpl("A Subcode must be namespace-qualified");
    }
    if (innermostSubCodeElement == null) {
        if (faultCodeElement == null)
            findFaultCodeElement();
        innermostSubCodeElement = faultCodeElement;
    }
    String prefix = null;
    if (subcode.getPrefix() == null || "".equals(subcode.getPrefix())) {
        prefix =
            ((ElementImpl) innermostSubCodeElement).getNamespacePrefix(
                subcode.getNamespaceURI());
    } else
        prefix = subcode.getPrefix();
    if (prefix == null || "".equals(prefix)) {
        prefix = "ns1";
    }
    innermostSubCodeElement =
        innermostSubCodeElement.addChildElement(subcodeName);
    SOAPElement subcodeValueElement =
        innermostSubCodeElement.addChildElement(valueName);
    ((ElementImpl) subcodeValueElement).ensureNamespaceIsDeclared(
        prefix,
        subcode.getNamespaceURI());
    subcodeValueElement.addTextNode(prefix + ":" + subcode.getLocalPart());
}
 
Example 12
Source File: XmlStreamWriter.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
/**
 * Write start element to stream.
 *
 * @param name Element name
 *
 * @throws XMLStreamException If an error occurs when writing to {@link OutputStream}
 */
protected void start(QName name) throws XMLStreamException {
    String prefix = name.getPrefix();
    String ns = this.writer.getNamespaceContext().getNamespaceURI(prefix);
    boolean alreadySet = ns != null && !ns.isEmpty();
    if (alreadySet && !ns.equals(name.getNamespaceURI())) {
        throw prefixAlreadyBound(prefix, ns);
    }
    this.writer.writeStartElement(prefix, name.getLocalPart(), name.getNamespaceURI());
    if (!alreadySet) {
        this.writer.writeNamespace(prefix, name.getNamespaceURI());
    }
}
 
Example 13
Source File: NameImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static Name convertToName(QName qname) {
    return new NameImpl(qname.getLocalPart(),
                        qname.getPrefix(),
                        qname.getNamespaceURI());
}
 
Example 14
Source File: WSEndpointReference.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void writeW3CMetaData(StreamWriterBufferCreator writer,
                                     QName service,
                                     QName port,
                                     QName portType, List<Element> metadata,
                                     String wsdlAddress, String wsdlTargetNamespace) throws XMLStreamException {


    //.NET treate empty metaData element as bad request.
    if (isEmty(service) && isEmty(port) && isEmty(portType) && metadata == null/* && wsdlAddress == null*/) {
        return;
    }

    writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
            AddressingVersion.W3C.eprType.wsdlMetadata.getLocalPart(), AddressingVersion.W3C.nsUri);
    writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
            AddressingVersion.W3C.wsdlNsUri);
    //write wsdliLication as defined in WS-Addressing 1.0 Metadata spec
    if(wsdlAddress != null) {
        writeWsdliLocation(writer, service, wsdlAddress, wsdlTargetNamespace);
    }

    //Write Interface info
    if (portType != null) {
        writer.writeStartElement(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
                AddressingVersion.W3C.eprType.portTypeName,
                W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
        writer.writeNamespace(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
            W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
        String portTypePrefix = portType.getPrefix();
        if (portTypePrefix == null || portTypePrefix.equals("")) {
            //TODO check prefix again
            portTypePrefix = "wsns";
        }
        writer.writeNamespace(portTypePrefix, portType.getNamespaceURI());
        writer.writeCharacters(portTypePrefix + ":" + portType.getLocalPart());
        writer.writeEndElement();
    }
    if (service != null) {
        //Write service and Port info
        if (!(service.getNamespaceURI().equals("") || service.getLocalPart().equals(""))) {
            writer.writeStartElement(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
                    AddressingVersion.W3C.eprType.serviceName,
                    W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
            writer.writeNamespace(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
                W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
            String servicePrefix = service.getPrefix();
            if (servicePrefix == null || servicePrefix.equals("")) {
                //TODO check prefix again
                servicePrefix = "wsns";
            }
            writer.writeNamespace(servicePrefix, service.getNamespaceURI());
            if (port != null) {
                writer.writeAttribute(AddressingVersion.W3C.eprType.portName, port.getLocalPart());
            }
            writer.writeCharacters(servicePrefix + ":" + service.getLocalPart());
            writer.writeEndElement();
        }
    }
    /*
    //Inline the wsdl
    if (wsdlAddress != null) {
        writeWsdl(writer, service, wsdlAddress);
    }
    */
    //Add the extra metadata Elements
    if (metadata != null) {
        for (Element e : metadata) {
            DOMUtil.serializeNode(e, writer);
        }
    }
    writer.writeEndElement();

}
 
Example 15
Source File: AbstractStaxHandler.java    From ts-reaktive with MIT License 4 votes vote down vote up
protected boolean isNamespaceDeclaration(QName qName) {
    String prefix = qName.getPrefix();
    String localPart = qName.getLocalPart();
    return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.length() == 0) ||
            (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && localPart.length() != 0);
}
 
Example 16
Source File: NameImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static Name convertToName(QName qname) {
    return new NameImpl(qname.getLocalPart(),
                        qname.getPrefix(),
                        qname.getNamespaceURI());
}
 
Example 17
Source File: KerberosToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getSamlToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:KerberosToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
        pPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
                             .getNamespaceURI());

    if (isRequireKeyIdentifierReference()) {
        // <sp:RequireKeyIdentifierReference />
        writer.writeStartElement(prefix, SPConstants.REQUIRE_KEY_IDENTIFIER_REFERENCE, namespaceURI);
        writer.writeEndElement();
    }

    if (isV5ApReqToken11()) {
        // <sp:WssKerberosV5ApReqToken11 />
        writer.writeStartElement(prefix, SPConstants.KERBEROS_V5_AP_REQ_TOKEN_11, namespaceURI);
        writer.writeEndElement();
    } else if (isGssV5ApReqToken11()) {
        // <sp:WssGssKerberosV5ApReqToken11 />
        writer.writeStartElement(prefix, SPConstants.KERBEROS_GSS_V5_AP_REQ_TOKEN_11, namespaceURI);
        writer.writeEndElement();
    }
    
    if (isDerivedKeys()) {
        // <sp:RequireDerivedKeys />
        writer.writeStartElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
        writer.writeEndElement();
    }

    // </wsp:Policy>
    writer.writeEndElement();


    writer.writeEndElement();
    // </sp:KerberosToken>

}
 
Example 18
Source File: StAX2SAXReader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void adapt() throws XMLStreamException, SAXException {
    QName qname;
    String prefix, localPart;
    AttributesImpl attrs = new AttributesImpl();
    char[] buffer;
    int nsc;
    int nat;

    _handler.startDocument();

    try {

        while (_reader.hasNext()) {
            int event = _reader.next();


            switch(event) {
            case  XMLStreamConstants.START_ELEMENT: {
                // Report namespace events first
                nsc = _reader.getNamespaceCount();
                for (int i = 0; i < nsc; i++) {
                    _handler.startPrefixMapping(_reader.getNamespacePrefix(i),
                        _reader.getNamespaceURI(i));
                }

                // Collect list of attributes
                attrs.clear();
                nat = _reader.getAttributeCount();
                for (int i = 0; i < nat; i++) {
                    QName q = _reader.getAttributeName(i);
                    String qName = _reader.getAttributePrefix(i);
                    if (qName == null || qName == "") {
                        qName = q.getLocalPart();
                    } else {
                        qName = qName + ":" +  q.getLocalPart();
                    }
                    attrs.addAttribute(_reader.getAttributeNamespace(i),
                                       q.getLocalPart(),
                                       qName,
                                       _reader.getAttributeType(i),
                                       _reader.getAttributeValue(i));
                }

                // Report start element
                qname = _reader.getName();
                prefix = qname.getPrefix();
                localPart = qname.getLocalPart();

                _handler.startElement(_reader.getNamespaceURI(),
                                      localPart,
                                      (prefix.length() > 0) ?
                                          (prefix + ":" + localPart) : localPart,
                                      attrs);
                break;
            }
            case  XMLStreamConstants.END_ELEMENT: {
                // Report end element
                qname = _reader.getName();
                prefix = qname.getPrefix();
                localPart = qname.getLocalPart();

                _handler.endElement(_reader.getNamespaceURI(),
                                    localPart,
                                    (prefix.length() > 0) ?
                                        (prefix + ":" + localPart) : localPart);

                // Report end namespace events
                nsc = _reader.getNamespaceCount();
                for (int i = 0; i < nsc; i++) {
                    _handler.endPrefixMapping(_reader.getNamespacePrefix(i));
                }
                break;
            }
            case XMLStreamConstants.CHARACTERS:
                _handler.characters(_reader.getTextCharacters(), _reader.getTextStart(), _reader.getTextLength());
                break;
            case XMLStreamConstants.COMMENT:
                _lexicalHandler.comment(_reader.getTextCharacters(), _reader.getTextStart(), _reader.getTextLength());
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                _handler.processingInstruction(_reader.getPITarget(), _reader.getPIData());
                break;
            case XMLStreamConstants.END_DOCUMENT:
                break;
            default:
                throw new RuntimeException(CommonResourceBundle.getInstance().getString("message.StAX2SAXReader", new Object[]{Integer.valueOf(event)}));
            } // switch
        }
    }
    catch (XMLStreamException e) {
        _handler.endDocument();     // flush whatever we have
        throw e;
    }

    _handler.endDocument();
}
 
Example 19
Source File: WSEndpointReference.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void writeW3CMetaData(StreamWriterBufferCreator writer,
                                     QName service,
                                     QName port,
                                     QName portType, List<Element> metadata,
                                     String wsdlAddress, String wsdlTargetNamespace) throws XMLStreamException {


    //.NET treate empty metaData element as bad request.
    if (isEmty(service) && isEmty(port) && isEmty(portType) && metadata == null/* && wsdlAddress == null*/) {
        return;
    }

    writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
            AddressingVersion.W3C.eprType.wsdlMetadata.getLocalPart(), AddressingVersion.W3C.nsUri);
    writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
            AddressingVersion.W3C.wsdlNsUri);
    //write wsdliLication as defined in WS-Addressing 1.0 Metadata spec
    if(wsdlAddress != null) {
        writeWsdliLocation(writer, service, wsdlAddress, wsdlTargetNamespace);
    }

    //Write Interface info
    if (portType != null) {
        writer.writeStartElement(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
                AddressingVersion.W3C.eprType.portTypeName,
                W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
        writer.writeNamespace(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
            W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
        String portTypePrefix = portType.getPrefix();
        if (portTypePrefix == null || portTypePrefix.equals("")) {
            //TODO check prefix again
            portTypePrefix = "wsns";
        }
        writer.writeNamespace(portTypePrefix, portType.getNamespaceURI());
        writer.writeCharacters(portTypePrefix + ":" + portType.getLocalPart());
        writer.writeEndElement();
    }
    if (service != null) {
        //Write service and Port info
        if (!(service.getNamespaceURI().equals("") || service.getLocalPart().equals(""))) {
            writer.writeStartElement(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
                    AddressingVersion.W3C.eprType.serviceName,
                    W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
            writer.writeNamespace(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
                W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
            String servicePrefix = service.getPrefix();
            if (servicePrefix == null || servicePrefix.equals("")) {
                //TODO check prefix again
                servicePrefix = "wsns";
            }
            writer.writeNamespace(servicePrefix, service.getNamespaceURI());
            if (port != null) {
                writer.writeAttribute(AddressingVersion.W3C.eprType.portName, port.getLocalPart());
            }
            writer.writeCharacters(servicePrefix + ":" + service.getLocalPart());
            writer.writeEndElement();
        }
    }
    /*
    //Inline the wsdl
    if (wsdlAddress != null) {
        writeWsdl(writer, service, wsdlAddress);
    }
    */
    //Add the extra metadata Elements
    if (metadata != null) {
        for (Element e : metadata) {
            DOMUtil.serializeNode(e, writer);
        }
    }
    writer.writeEndElement();

}
 
Example 20
Source File: SpnegoContextToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getSpnegoContextToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();
    String prefix;

    String writerPrefix = writer.getPrefix(namespaceURI);

    if (writerPrefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    } else {
        prefix = writerPrefix;
    }

    // <sp:SpnegoContextToken>
    writer.writeStartElement(prefix, localname, namespaceURI);

    if (writerPrefix == null) {
        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);
    }

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    if (issuerEpr != null) {
        // <sp:Issuer>
        writer.writeStartElement(prefix, SPConstants.ISSUER, namespaceURI);

        StaxUtils.copy(issuerEpr, writer);

        writer.writeEndElement();
    }

    if (isDerivedKeys()) {

        String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

        String wspPrefix;

        String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

        if (wspWriterPrefix == null) {
            wspPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(wspPrefix, wspNamespaceURI);

        } else {
            wspPrefix = wspWriterPrefix;
        }

        // <wsp:Policy>
        writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

        if (wspWriterPrefix == null) {
            // xmlns:wsp=".."
            writer.writeNamespace(wspPrefix, wspNamespaceURI);
        }

        if (isDerivedKeys()) {
            // <sp:RequireDerivedKeys />
            writer.writeEmptyElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
        }

        // </wsp:Policy>
        writer.writeEndElement();
    }

    // </sp:SpnegoContextToken>
    writer.writeEndElement();
}