Search in sources :

Example 1 with TypedXmlWriter

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

the class PolicyModelMarshallerTest method testMarshal_Collection_Object.

/**
 * Test of marshal method, of class PolicyModelMarshaller.
 */
public void testMarshal_Collection_Object() throws PolicyException {
    Collection<PolicySourceModel> models = new LinkedList<PolicySourceModel>();
    PolicySourceModel model = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_2);
    PolicySourceModel model2 = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_5);
    models.add(model);
    models.add(model2);
    Document document = builder.newDocument();
    TypedXmlWriter storage = TXW.create(new QName("policies"), TypedXmlWriter.class, new DomSerializer(document));
    PolicyModelMarshaller instance = PolicyModelMarshaller.getXmlMarshaller(false);
    instance.marshal(models, 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) LinkedList(java.util.LinkedList)

Example 2 with TypedXmlWriter

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

the class WSDLGenerator method generateBindingOperation.

protected void generateBindingOperation(JavaMethodImpl method, Binding binding) {
    BindingOperationType operation = binding.operation().name(method.getOperationName());
    extension.addBindingOperationExtension(operation, method);
    String targetNamespace = model.getTargetNamespace();
    QName requestMessage = new QName(targetNamespace, method.getOperationName());
    List<ParameterImpl> bodyParams = new ArrayList<>();
    List<ParameterImpl> headerParams = new ArrayList<>();
    splitParameters(bodyParams, headerParams, method.getRequestParameters());
    SOAPBinding soapBinding = method.getBinding();
    operation.soapOperation().soapAction(soapBinding.getSOAPAction());
    // input
    TypedXmlWriter input = operation.input();
    extension.addBindingOperationInputExtension(input, method);
    BodyType body = input._element(Body.class);
    boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
    if (soapBinding.getUse() == Use.LITERAL) {
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().next();
                if (isRpc) {
                    StringBuilder parts = new StringBuilder();
                    int i = 0;
                    for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                        if (i++ > 0)
                            parts.append(' ');
                        parts.append(parameter.getPartName());
                    }
                    body.parts(parts.toString());
                } else {
                    body.parts(param.getPartName());
                }
            } else {
                body.parts("");
            }
            generateSOAPHeaders(input, headerParams, requestMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    } else {
        // TODO localize this
        throw new WebServiceException("encoded use is not supported");
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        // output
        bodyParams.clear();
        headerParams.clear();
        splitParameters(bodyParams, headerParams, method.getResponseParameters());
        TypedXmlWriter output = operation.output();
        extension.addBindingOperationOutputExtension(output, method);
        body = output._element(Body.class);
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            StringBuilder parts = new StringBuilder();
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().hasNext() ? bodyParams.iterator().next() : null;
                if (param != null) {
                    if (isRpc) {
                        int i = 0;
                        for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                            if (i++ > 0) {
                                parts.append(" ");
                            }
                            parts.append(parameter.getPartName());
                        }
                    } else {
                        parts = new StringBuilder(param.getPartName());
                    }
                }
            }
            body.parts(parts.toString());
            QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
            generateSOAPHeaders(output, headerParams, responseMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        Fault fault = operation.fault().name(exception.getMessageName());
        extension.addBindingOperationFaultExtension(fault, method, exception);
        SOAPFault soapFault = fault._element(SOAPFault.class).name(exception.getMessageName());
        soapFault.use(LITERAL);
    }
}
Also used : BindingOperationType(com.sun.xml.ws.wsdl.writer.document.BindingOperationType) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) SOAPBinding(com.sun.xml.ws.api.model.soap.SOAPBinding) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) Fault(com.sun.xml.ws.wsdl.writer.document.Fault) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) BodyType(com.sun.xml.ws.wsdl.writer.document.soap.BodyType) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) Body(com.sun.xml.ws.wsdl.writer.document.soap.Body)

Example 3 with TypedXmlWriter

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

the class TXWContentHandler method startElement.

public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    TypedXmlWriter txw = stack.peek()._element(uri, localName, TypedXmlWriter.class);
    stack.push(txw);
    if (atts != null) {
        for (int i = 0; i < atts.getLength(); i++) {
            String auri = atts.getURI(i);
            if ("http://www.w3.org/2000/xmlns/".equals(auri)) {
                if ("xmlns".equals(atts.getLocalName(i)))
                    txw._namespace(atts.getValue(i), "");
                else
                    txw._namespace(atts.getValue(i), atts.getLocalName(i));
            } else {
                if ("schemaLocation".equals(atts.getLocalName(i)) && "".equals(atts.getValue(i)))
                    continue;
                txw._attribute(auri, atts.getLocalName(i), atts.getValue(i));
            }
        }
    }
}
Also used : TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 4 with TypedXmlWriter

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

the class W3CAddressingMetadataWSDLGeneratorExtension method start.

@Override
public void start(WSDLGenExtnContext ctxt) {
    TypedXmlWriter root = ctxt.getRoot();
    root._namespace(W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME, W3CAddressingMetadataConstants.WSAM_PREFIX_NAME);
}
Also used : TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 5 with TypedXmlWriter

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

the class W3CAddressingWSDLGeneratorExtension method start.

@Override
public void start(WSDLGenExtnContext ctxt) {
    WSBinding binding = ctxt.getBinding();
    TypedXmlWriter root = ctxt.getRoot();
    enabled = binding.isFeatureEnabled(AddressingFeature.class);
    if (!enabled)
        return;
    AddressingFeature ftr = binding.getFeature(AddressingFeature.class);
    required = ftr.isRequired();
    root._namespace(AddressingVersion.W3C.wsdlNsUri, AddressingVersion.W3C.getWsdlPrefix());
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) AddressingFeature(jakarta.xml.ws.soap.AddressingFeature) 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