Package com.sun.xml.internal.stream.buffer.stax

Examples of com.sun.xml.internal.stream.buffer.stax.StreamWriterBufferCreator


        throw new WebServiceException("Unknwon EndpointReference: " + epr.getClass());
    }

    //TODO: bit of redundency on writes of w3c epr, should modularize it
    private static W3CEndpointReference toW3CEpr(MemberSubmissionEndpointReference msEpr) {
        StreamWriterBufferCreator writer = new StreamWriterBufferCreator();
        w3cMetadataWritten = false;
        try {
            writer.writeStartDocument();
            writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
                    "EndpointReference", AddressingVersion.W3C.nsUri);
            writer.writeNamespace(AddressingVersion.W3C.getPrefix(),
                    AddressingVersion.W3C.nsUri);
            //write wsa:Address
            writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
                    W3CAddressingConstants.WSA_ADDRESS_NAME, AddressingVersion.W3C.nsUri);
            writer.writeCharacters(msEpr.addr.uri);
            writer.writeEndElement();
            //TODO: write extension attributes on wsa:Address
            if ((msEpr.referenceProperties != null && msEpr.referenceProperties.elements.size() > 0) ||
                    (msEpr.referenceParameters != null && msEpr.referenceParameters.elements.size() > 0)) {

                writer.writeStartElement(AddressingVersion.W3C.getPrefix(), "ReferenceParameters", AddressingVersion.W3C.nsUri);

                //write ReferenceProperties
                if (msEpr.referenceProperties != null) {
                    for (Element e : msEpr.referenceProperties.elements) {
                        DOMUtil.serializeNode(e, writer);
                    }
                }
                //write referenceParameters
                if (msEpr.referenceParameters != null) {
                    for (Element e : msEpr.referenceParameters.elements) {
                        DOMUtil.serializeNode(e, writer);
                    }
                }
                writer.writeEndElement();
            }
            // Supress writing ServiceName and EndpointName in W3CEPR,
            // Until the ns for those metadata elements is resolved.
            /*
            //Write Interface info
            if (msEpr.portTypeName != null) {
                writeW3CMetadata(writer);
                writer.writeStartElement(AddressingVersion.W3C.getWsdlPrefix(),
                        W3CAddressingConstants.WSAW_INTERFACENAME_NAME,
                        AddressingVersion.W3C.wsdlNsUri);
                writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.wsdlNsUri);
                String portTypePrefix = fixNull(msEpr.portTypeName.name.getPrefix());
                writer.writeNamespace(portTypePrefix, msEpr.portTypeName.name.getNamespaceURI());
                if (portTypePrefix.equals(""))
                    writer.writeCharacters(msEpr.portTypeName.name.getLocalPart());
                else
                    writer.writeCharacters(portTypePrefix + ":" + msEpr.portTypeName.name.getLocalPart());
                writer.writeEndElement();
            }
            if (msEpr.serviceName != null) {
                writeW3CMetadata(writer);
                //Write service and Port info
                writer.writeStartElement(AddressingVersion.W3C.getWsdlPrefix(),
                        W3CAddressingConstants.WSAW_SERVICENAME_NAME,
                        AddressingVersion.W3C.wsdlNsUri);
                writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.wsdlNsUri);

                String servicePrefix = fixNull(msEpr.serviceName.name.getPrefix());
                if (msEpr.serviceName.portName != null)
                    writer.writeAttribute(W3CAddressingConstants.WSAW_ENDPOINTNAME_NAME,
                            msEpr.serviceName.portName);

                writer.writeNamespace(servicePrefix, msEpr.serviceName.name.getNamespaceURI());
                if (servicePrefix.length() > 0)
                    writer.writeCharacters(servicePrefix + ":" + msEpr.serviceName.name.getLocalPart());
                else
                    writer.writeCharacters(msEpr.serviceName.name.getLocalPart());
                writer.writeEndElement();
            }
            */
            //TODO: revisit this
            Element wsdlElement = null;
            //Check for wsdl in extension elements
            if ((msEpr.elements != null) && (msEpr.elements.size() > 0)) {
                for (Element e : msEpr.elements) {
                    if(e.getNamespaceURI().equals(MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI()) &&
                            e.getLocalName().equals(MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart())) {
                        NodeList nl = e.getElementsByTagNameNS(WSDLConstants.NS_WSDL,
                                WSDLConstants.QNAME_DEFINITIONS.getLocalPart());
                        if(nl != null)
                            wsdlElement = (Element) nl.item(0);
                    }
                }
            }
            //write WSDL
            if (wsdlElement != null) {
                DOMUtil.serializeNode(wsdlElement, writer);
            }

            if (w3cMetadataWritten)
                writer.writeEndElement();
            //TODO revisit this
            //write extension elements
            if ((msEpr.elements != null) && (msEpr.elements.size() > 0)) {
                for (Element e : msEpr.elements) {
                    if (e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
                            e.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
                        // Don't write it as this is written already in Metadata
                    }
                    DOMUtil.serializeNode(e, writer);
                }
            }

            //TODO:write extension attributes

            //</EndpointReference>
            writer.writeEndElement();
            writer.writeEndDocument();
            writer.flush();
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);
        }
        return new W3CEndpointReference(new XMLStreamBufferSource(writer.getXMLStreamBuffer()));
    }
View Full Code Here


    }

    private static XMLStreamBuffer createBufferFromAddress(String address, AddressingVersion version) {
        try {
            MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
            StreamWriterBufferCreator w = new StreamWriterBufferCreator(xsb);
            w.writeStartDocument();
            w.writeStartElement(version.getPrefix(),
                "EndpointReference", version.nsUri);
            w.writeNamespace(version.getPrefix(),
                version.nsUri);
            w.writeStartElement(version.getPrefix(),
                W3CAddressingConstants.WSA_ADDRESS_NAME, version.nsUri);
            w.writeCharacters(address);
            w.writeEndElement();
            w.writeEndElement();
            w.writeEndDocument();
            w.close();
            return xsb;
        } catch (XMLStreamException e) {
            // can never happen because we are writing to XSB
            throw new AssertionError(e);
        }
View Full Code Here

            version );
    }

    private static XMLStreamBuffer createBufferFromData(AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType, List<Element> metadata, String wsdlAddress) {

        StreamWriterBufferCreator writer = new StreamWriterBufferCreator();

        try {
            writer.writeStartDocument();
            writer.writeStartElement(version.getPrefix(),"EndpointReference", version.nsUri);
            writer.writeNamespace(version.getPrefix(),version.nsUri);
            writer.writeStartElement(version.getPrefix(),"Address", version.nsUri);
            writer.writeCharacters(address);
            writer.writeEndElement();
            if(referenceParameters != null) {
                writer.writeStartElement(version.getPrefix(),"ReferenceParameters", version.nsUri);
                for (Element e : referenceParameters)
                    DOMUtil.serializeNode(e, writer);
                writer.writeEndElement();
            }

            switch(version) {
            case W3C:
                writeW3CMetaData(writer, service, port, portType, metadata, wsdlAddress);
                break;

            case MEMBER:
                writeMSMetaData(writer, service, port, portType, metadata);
                if (wsdlAddress != null) {
                    //Inline the wsdl as extensibility element
                    //Write mex:Metadata wrapper
                    writer.writeStartElement(MemberSubmissionAddressingConstants.MEX_METADATA.getPrefix(),
                            MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart(),
                            MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI());
                    writer.writeStartElement(MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getPrefix(),
                            MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getLocalPart(),
                            MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getNamespaceURI());
                    writer.writeAttribute(MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_ATTRIBUTE,
                            MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_VALUE);

                    writeWsdl(writer, service, wsdlAddress);

                    writer.writeEndElement();
                    writer.writeEndElement();
                }

                break;
            }
            writer.writeEndElement();
            writer.writeEndDocument();
            writer.flush();

            return writer.getXMLStreamBuffer();
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);
        }
    }
View Full Code Here

     */
    private <EPR extends EndpointReference> EPR createEPR(String key, Class<EPR> eprClass, String address, EPRRecipe recipe) {
        AddressingVersion adrsVer = AddressingVersion.fromSpecClass(eprClass);

        try {
            StreamWriterBufferCreator w = new StreamWriterBufferCreator();

            w.writeStartDocument();
            w.writeStartElement("wsa","EndpointReference", adrsVer.nsUri);
            w.writeNamespace("wsa",adrsVer.nsUri);

            w.writeStartElement("wsa","Address",adrsVer.nsUri);
            w.writeCharacters(address);
            w.writeEndElement();

            w.writeStartElement("wsa","ReferenceParameters",adrsVer.nsUri);
            w.writeStartElement(COOKIE_TAG.getPrefix(), COOKIE_TAG.getLocalPart(), COOKIE_TAG.getNamespaceURI());
            w.writeCharacters(key);
            w.writeEndElement();
            if(recipe!=null) {
                for (Header h : recipe.getReferenceParameters())
                    h.writeTo(w);
            }
            w.writeEndElement();

            if(recipe!=null) {
                List<Source> metadata = recipe.getMetadata();
                if(!metadata.isEmpty()) {
                    w.writeStartElement("wsa","Metadata",adrsVer.nsUri);
                    Transformer t = XmlUtil.newTransformer();
                    for (Source s : metadata)
                        try {
                            t.transform(s,
                                new SAXResult(new FragmentContentHandler(new ContentHandlerToXMLStreamWriter(w))));
                        } catch (TransformerException e) {
                            throw new IllegalArgumentException("Unable to write EPR metadata "+s,e);
                        }
                    w.writeEndElement();
                }
            }

            w.writeEndElement();
            w.writeEndDocument();

            // TODO: this can be done better by writing SAX code that produces infoset
            // and setting that as Source.
            return eprClass.cast(ProviderImpl.INSTANCE.readEndpointReference(
                new XMLStreamBufferSource(w.getXMLStreamBuffer())));
        } catch (XMLStreamException e) {
            throw new Error(e); // this must be a bug in our code
        }
    }
View Full Code Here

     * The MutableXMLStreamBuffer is created by consuming events on a XMLStreamWriter using
     * an instance of {@link StreamWriterBufferCreator}.
     */
    public XMLStreamWriter createFromXMLStreamWriter() {
        reset();
        return new StreamWriterBufferCreator(this);
    }
View Full Code Here

    }

    private static XMLStreamBuffer createBufferFromAddress(String address, AddressingVersion version) {
        try {
            MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
            StreamWriterBufferCreator w = new StreamWriterBufferCreator(xsb);
            w.writeStartDocument();
            w.writeStartElement(version.getPrefix(),
                "EndpointReference", version.nsUri);
            w.writeNamespace(version.getPrefix(), version.nsUri);
            w.writeStartElement(version.getPrefix(),version.eprType.address, version.nsUri);
            w.writeCharacters(address);
            w.writeEndElement();
            w.writeEndElement();
            w.writeEndDocument();
            w.close();
            return xsb;
        } catch (XMLStreamException e) {
            // can never happen because we are writing to XSB
            throw new AssertionError(e);
        }
View Full Code Here

    }

    private static XMLStreamBuffer createBufferFromData(AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType,
                                                            List<Element> metadata, String wsdlAddress, String wsdlTargetNamespace, @Nullable List<Element> elements, @Nullable Map<QName, String> attributes) {

        StreamWriterBufferCreator writer = new StreamWriterBufferCreator();

        try {
            writer.writeStartDocument();
            writer.writeStartElement(version.getPrefix(),"EndpointReference", version.nsUri);
            writer.writeNamespace(version.getPrefix(),version.nsUri);

                writePartialEPRInfoset(writer, version, address, referenceParameters, service, port, portType,
                        metadata,wsdlAddress, wsdlTargetNamespace, attributes);

                //write extensibility elements in the EPR element
                if (elements != null) {
                    for (Element e : elements)
                        DOMUtil.serializeNode(e, writer);
                }

                writer.writeEndElement();
                writer.writeEndDocument();
                writer.flush();

                return writer.getXMLStreamBuffer();
            } catch (XMLStreamException e) {
                throw new WebServiceException(e);
            }
        }
View Full Code Here

        }

        private static XMLStreamBuffer createBufferFromData(AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType,
                                                            List<Element> metadata, String wsdlAddress, String wsdlTargetNamespace, @Nullable Collection<EPRExtension> extns, @Nullable Map<QName, String> attributes) {

            StreamWriterBufferCreator writer = new StreamWriterBufferCreator();

            try {
                writer.writeStartDocument();
                writer.writeStartElement(version.getPrefix(),"EndpointReference", version.nsUri);
                writer.writeNamespace(version.getPrefix(),version.nsUri);

                writePartialEPRInfoset(writer, version, address, referenceParameters, service, port, portType,
                        metadata,wsdlAddress, wsdlTargetNamespace, attributes);

                //write extensibility elements in the EPR element
                if (extns != null) {
                    for (EPRExtension e : extns) {
                        XMLStreamReaderToXMLStreamWriter c = new XMLStreamReaderToXMLStreamWriter();
                        XMLStreamReader r = e.readAsXMLStreamReader();
                        c.bridge(r, writer);
                        XMLStreamReaderFactory.recycle(r);
                    }
                }

                writer.writeEndElement();
                writer.writeEndDocument();
                writer.flush();

                return writer.getXMLStreamBuffer();
            } catch (XMLStreamException e) {
                throw new WebServiceException(e);
            }
        }
View Full Code Here

        throw new WebServiceException("Unknwon EndpointReference: " + epr.getClass());
    }

    //TODO: bit of redundency on writes of w3c epr, should modularize it
    private static W3CEndpointReference toW3CEpr(MemberSubmissionEndpointReference msEpr) {
        StreamWriterBufferCreator writer = new StreamWriterBufferCreator();
        w3cMetadataWritten = false;
        try {
            writer.writeStartDocument();
            writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
                    "EndpointReference", AddressingVersion.W3C.nsUri);
            writer.writeNamespace(AddressingVersion.W3C.getPrefix(),
                    AddressingVersion.W3C.nsUri);
            //write wsa:Address
            writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
                    AddressingVersion.W3C.eprType.address
                    , AddressingVersion.W3C.nsUri);
            writer.writeCharacters(msEpr.addr.uri);
            writer.writeEndElement();
            //TODO: write extension attributes on wsa:Address
            if ((msEpr.referenceProperties != null && msEpr.referenceProperties.elements.size() > 0) ||
                    (msEpr.referenceParameters != null && msEpr.referenceParameters.elements.size() > 0)) {

                writer.writeStartElement(AddressingVersion.W3C.getPrefix(), "ReferenceParameters", AddressingVersion.W3C.nsUri);

                //write ReferenceProperties
                if (msEpr.referenceProperties != null) {
                    for (Element e : msEpr.referenceProperties.elements) {
                        DOMUtil.serializeNode(e, writer);
                    }
                }
                //write referenceParameters
                if (msEpr.referenceParameters != null) {
                    for (Element e : msEpr.referenceParameters.elements) {
                        DOMUtil.serializeNode(e, writer);
                    }
                }
                writer.writeEndElement();
            }
            // Supress writing ServiceName and EndpointName in W3CEPR,
            // Until the ns for those metadata elements is resolved.
            /*
            //Write Interface info
            if (msEpr.portTypeName != null) {
                writeW3CMetadata(writer);
                writer.writeStartElement(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.eprType.portTypeName ,
                        AddressingVersion.W3C.wsdlNsUri);
                writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.wsdlNsUri);
                String portTypePrefix = fixNull(msEpr.portTypeName.name.getPrefix());
                writer.writeNamespace(portTypePrefix, msEpr.portTypeName.name.getNamespaceURI());
                if (portTypePrefix.equals(""))
                    writer.writeCharacters(msEpr.portTypeName.name.getLocalPart());
                else
                    writer.writeCharacters(portTypePrefix + ":" + msEpr.portTypeName.name.getLocalPart());
                writer.writeEndElement();
            }
            if (msEpr.serviceName != null) {
                writeW3CMetadata(writer);
                //Write service and Port info
                writer.writeStartElement(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.eprType.serviceName ,
                        AddressingVersion.W3C.wsdlNsUri);
                writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.wsdlNsUri);

                String servicePrefix = fixNull(msEpr.serviceName.name.getPrefix());
                if (msEpr.serviceName.portName != null)
                    writer.writeAttribute(AddressingVersion.W3C.eprType.portName,
                            msEpr.serviceName.portName);

                writer.writeNamespace(servicePrefix, msEpr.serviceName.name.getNamespaceURI());
                if (servicePrefix.length() > 0)
                    writer.writeCharacters(servicePrefix + ":" + msEpr.serviceName.name.getLocalPart());
                else
                    writer.writeCharacters(msEpr.serviceName.name.getLocalPart());
                writer.writeEndElement();
            }
            */
            //TODO: revisit this
            Element wsdlElement = null;
            //Check for wsdl in extension elements
            if ((msEpr.elements != null) && (msEpr.elements.size() > 0)) {
                for (Element e : msEpr.elements) {
                    if(e.getNamespaceURI().equals(MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI()) &&
                            e.getLocalName().equals(MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart())) {
                        NodeList nl = e.getElementsByTagNameNS(WSDLConstants.NS_WSDL,
                                WSDLConstants.QNAME_DEFINITIONS.getLocalPart());
                        if(nl != null)
                            wsdlElement = (Element) nl.item(0);
                    }
                }
            }
            //write WSDL
            if (wsdlElement != null) {
                DOMUtil.serializeNode(wsdlElement, writer);
            }

            if (w3cMetadataWritten)
                writer.writeEndElement();
            //TODO revisit this
            //write extension elements
            if ((msEpr.elements != null) && (msEpr.elements.size() > 0)) {
                for (Element e : msEpr.elements) {
                    if (e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
                            e.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
                        // Don't write it as this is written already in Metadata
                    }
                    DOMUtil.serializeNode(e, writer);
                }
            }

            //TODO:write extension attributes

            //</EndpointReference>
            writer.writeEndElement();
            writer.writeEndDocument();
            writer.flush();
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);
        }
        return new W3CEndpointReference(new XMLStreamBufferSource(writer.getXMLStreamBuffer()));
    }
View Full Code Here

     * The MutableXMLStreamBuffer is created by consuming events on a XMLStreamWriter using
     * an instance of {@link StreamWriterBufferCreator}.
     */
    public XMLStreamWriter createFromXMLStreamWriter() {
        reset();
        return new StreamWriterBufferCreator(this);
    }
View Full Code Here

TOP

Related Classes of com.sun.xml.internal.stream.buffer.stax.StreamWriterBufferCreator

Copyright © 2018 www.massapicom. 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.