Search in sources :

Example 11 with TypedXmlWriter

use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.

the class PolicyModelMarshallerTest method testMarshal_PolicySourceModel_Object.

/**
 * Test of marshal method, of class PolicyModelMarshaller.
 */
public void testMarshal_PolicySourceModel_Object() throws PolicyException {
    PolicySourceModel model = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_2);
    Document document = builder.newDocument();
    TypedXmlWriter storage = TXW.create(new QName("root"), TypedXmlWriter.class, new DomSerializer(document));
    PolicyModelMarshaller instance = PolicyModelMarshaller.getXmlMarshaller(false);
    instance.marshal(model, storage);
    storage.commit();
    Element element = document.getDocumentElement();
    Node policyElement = element.getFirstChild();
    assertEquals(policyElement.getLocalName(), "Policy");
}
Also used : DomSerializer(com.sun.xml.txw2.output.DomSerializer) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 12 with TypedXmlWriter

use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.

the class PolicyModelMarshallerTest method testMarshalPrefixWrite.

public void testMarshalPrefixWrite() throws PolicyException {
    PolicySourceModel model = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_5, "id", null);
    ModelNode root = model.getRootNode();
    ModelNode all = root.createChildAllNode();
    AssertionData assertion = AssertionData.createAssertionData(new QName("http://schemas.foo.com/", "Assertion"));
    all.createChildAssertionNode(assertion);
    Document document = builder.newDocument();
    TypedXmlWriter storage = TXW.create(new QName("root"), TypedXmlWriter.class, new DomSerializer(document));
    PolicyModelMarshaller instance = PolicyModelMarshaller.getXmlMarshaller(false);
    instance.marshal(model, storage);
    storage.commit();
    Element element = document.getDocumentElement();
    Node policyElement = element.getFirstChild();
    assertEquals(NamespaceVersion.v1_5.getDefaultNamespacePrefix(), policyElement.getPrefix());
    NamedNodeMap map = policyElement.getAttributes();
    Node id = map.getNamedItemNS(PolicyConstants.WSU_ID.getNamespaceURI(), PolicyConstants.WSU_ID.getLocalPart());
    assertEquals(PolicyConstants.WSU_NAMESPACE_PREFIX, id.getPrefix());
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) DomSerializer(com.sun.xml.txw2.output.DomSerializer) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 13 with TypedXmlWriter

use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.

the class XmlPolicyModelMarshaller method marshal.

/**
 * Marshal a policy onto the given TypedXmlWriter.
 *
 * @param model A policy source model.
 * @param writer A typed XML writer.
 * @throws PolicyException If marshalling failed.
 */
private void marshal(final PolicySourceModel model, final TypedXmlWriter writer) throws PolicyException {
    final TypedXmlWriter policy = writer._element(model.getNamespaceVersion().asQName(XmlToken.Policy), TypedXmlWriter.class);
    marshalDefaultPrefixes(model, policy);
    marshalPolicyAttributes(model, policy);
    marshal(model.getNamespaceVersion(), model.getRootNode(), policy);
}
Also used : TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 14 with TypedXmlWriter

use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.

the class XmlPolicyModelMarshaller method marshal.

/**
 * Marshal given ModelNode and child elements on given TypedXmlWriter.
 *
 * @param nsVersion The WS-Policy version.
 * @param rootNode The ModelNode that is marshalled.
 * @param writer The TypedXmlWriter onto which the content of the rootNode is marshalled.
 */
private void marshal(final NamespaceVersion nsVersion, final ModelNode rootNode, final TypedXmlWriter writer) {
    for (ModelNode node : rootNode) {
        final AssertionData data = node.getNodeData();
        if (marshallInvisible || data == null || !data.isPrivateAttributeSet()) {
            TypedXmlWriter child = null;
            if (data == null) {
                child = writer._element(nsVersion.asQName(node.getType().getXmlToken()), TypedXmlWriter.class);
            } else {
                child = writer._element(data.getName(), TypedXmlWriter.class);
                final String value = data.getValue();
                if (value != null) {
                    child._pcdata(value);
                }
                if (data.isOptionalAttributeSet()) {
                    child._attribute(nsVersion.asQName(XmlToken.Optional), Boolean.TRUE);
                }
                if (data.isIgnorableAttributeSet()) {
                    child._attribute(nsVersion.asQName(XmlToken.Ignorable), Boolean.TRUE);
                }
                for (Entry<QName, String> entry : data.getAttributesSet()) {
                    child._attribute(entry.getKey(), entry.getValue());
                }
            }
            marshal(nsVersion, node, child);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 15 with TypedXmlWriter

use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.

the class XmlPolicyModelMarshaller method marshal.

/**
 * Marshal a policy onto the given StaxSerializer.
 *
 * @param model A policy source model.
 * @param writer A Stax serializer.
 * @throws PolicyException If marshalling failed.
 */
private void marshal(final PolicySourceModel model, final StaxSerializer writer) throws PolicyException {
    final TypedXmlWriter policy = TXW.create(model.getNamespaceVersion().asQName(XmlToken.Policy), TypedXmlWriter.class, writer);
    marshalDefaultPrefixes(model, policy);
    marshalPolicyAttributes(model, policy);
    marshal(model.getNamespaceVersion(), model.getRootNode(), policy);
    policy.commit();
}
Also used : TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Aggregations

TypedXmlWriter (com.sun.xml.txw2.TypedXmlWriter)14 QName (javax.xml.namespace.QName)7 WebServiceException (jakarta.xml.ws.WebServiceException)4 DomSerializer (com.sun.xml.txw2.output.DomSerializer)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 WSBinding (com.sun.xml.ws.api.WSBinding)2 SOAPBinding (com.sun.xml.ws.api.model.soap.SOAPBinding)2 CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)2 ParameterImpl (com.sun.xml.ws.model.ParameterImpl)2 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)2 PolicyException (com.sun.xml.ws.policy.PolicyException)2 BindingOperationType (com.sun.xml.ws.wsdl.writer.document.BindingOperationType)2 Fault (com.sun.xml.ws.wsdl.writer.document.Fault)2 Body (com.sun.xml.ws.wsdl.writer.document.soap.Body)2 SOAPFault (com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 XmlCDATA (com.sun.xml.txw2.annotation.XmlCDATA)1