com.sun.xml.internal.txw2.TypedXmlWriter Java Examples

The following examples show how to use com.sun.xml.internal.txw2.TypedXmlWriter. 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: W3CAddressingWSDLGeneratorExtension.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addOperationInputExtension(TypedXmlWriter input, JavaMethod method) {
    if (!enabled)
        return;

    Action a = method.getSEIMethod().getAnnotation(Action.class);
    if (a != null && !a.input().equals("")) {
        addAttribute(input, a.input());
    } else {

        String soapAction = method.getBinding().getSOAPAction();
        // in SOAP 1.2 soapAction is optional ...
        if (soapAction == null || soapAction.equals("")) {
            //hack: generate default action for interop with .Net3.0 when soapAction is non-empty
            String defaultAction = getDefaultAction(method);
            addAttribute(input, defaultAction);
        }
    }
}
 
Example #2
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method should only be invoked by interface methods that deal with WSDL binding because they
 * may use the QName of the WSDL binding element as PolicySubject instead of a WSDL object.
 *
 * @param xmlWriter A TypedXmlWriter.
 * @param clazz The policy subject.
 * @param scopeType The WSDL scope.
 * @param bindingName The WSDL binding name.
 */
private void selectAndProcessSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final QName bindingName) {
    LOGGER.entering(xmlWriter, clazz, scopeType, bindingName);
    if (bindingName == null) {
        selectAndProcessSubject(xmlWriter, clazz, scopeType, (String) null);
    } else {
        if (subjects != null) {
            for (PolicySubject subject : subjects) {
                if (bindingName.equals(subject.getSubject())) {
                    writePolicyOrReferenceIt(subject, xmlWriter);
                }
            }
        }
        selectAndProcessSubject(xmlWriter, clazz, scopeType, bindingName.getLocalPart());
    }
    LOGGER.exiting();
}
 
Example #3
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds a PolicyReference element that points to the policy of the element,
 * if the policy does not have any id or name. Writes policy inside the element otherwise.
 *
 * @param subject
 *      PolicySubject to be referenced or marshalled
 * @param writer
 *      A TXW on to which we shall add the PolicyReference
 */
private void writePolicyOrReferenceIt(final PolicySubject subject, final TypedXmlWriter writer) {
    final Policy policy;
    try {
        policy = subject.getEffectivePolicy(merger);
    } catch (PolicyException e) {
        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e));
    }
    if (policy != null) {
        if (null == policy.getIdOrName()) {
            final PolicyModelGenerator generator = ModelGenerator.getGenerator();
            try {
                final PolicySourceModel policyInfoset = generator.translate(policy);
                marshaller.marshal(policyInfoset, writer);
            } catch (PolicyException pe) {
                throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1002_UNABLE_TO_MARSHALL_POLICY_OR_POLICY_REFERENCE(), pe));
            }
        } else {
            final TypedXmlWriter policyReference = writer._element(policy.getNamespaceVersion().asQName(XmlToken.PolicyReference), TypedXmlWriter.class);
            policyReference._attribute(XmlToken.Uri.toString(), '#' + policy.getIdOrName());
        }
    }
}
 
Example #4
Source File: W3CAddressingWSDLGeneratorExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addOperationInputExtension(TypedXmlWriter input, JavaMethod method) {
    if (!enabled)
        return;

    Action a = method.getSEIMethod().getAnnotation(Action.class);
    if (a != null && !a.input().equals("")) {
        addAttribute(input, a.input());
    } else {

        String soapAction = method.getBinding().getSOAPAction();
        // in SOAP 1.2 soapAction is optional ...
        if (soapAction == null || soapAction.equals("")) {
            //hack: generate default action for interop with .Net3.0 when soapAction is non-empty
            String defaultAction = getDefaultAction(method);
            addAttribute(input, defaultAction);
        }
    }
}
 
Example #5
Source File: PolicyWSDLGeneratorExtension.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method should only be invoked by interface methods that deal with WSDL binding because they
 * may use the QName of the WSDL binding element as PolicySubject instead of a WSDL object.
 *
 * @param xmlWriter A TypedXmlWriter.
 * @param clazz The policy subject.
 * @param scopeType The WSDL scope.
 * @param bindingName The WSDL binding name.
 */
private void selectAndProcessSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final QName bindingName) {
    LOGGER.entering(xmlWriter, clazz, scopeType, bindingName);
    if (bindingName == null) {
        selectAndProcessSubject(xmlWriter, clazz, scopeType, (String) null);
    } else {
        if (subjects != null) {
            for (PolicySubject subject : subjects) {
                if (bindingName.equals(subject.getSubject())) {
                    writePolicyOrReferenceIt(subject, xmlWriter);
                }
            }
        }
        selectAndProcessSubject(xmlWriter, clazz, scopeType, bindingName.getLocalPart());
    }
    LOGGER.exiting();
}
 
Example #6
Source File: XmlPolicyModelMarshaller.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #7
Source File: XmlPolicyModelMarshaller.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void marshal(final PolicySourceModel model, final Object storage) throws PolicyException {
    if (storage instanceof StaxSerializer) {
        marshal(model, (StaxSerializer) storage);
    } else if (storage instanceof TypedXmlWriter) {
        marshal(model, (TypedXmlWriter) storage);
    } else if (storage instanceof XMLStreamWriter) {
        marshal(model, (XMLStreamWriter) storage);
    } else {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0022_STORAGE_TYPE_NOT_SUPPORTED(storage.getClass().getName())));
    }
}
 
Example #8
Source File: XmlPolicyModelMarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #9
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addOperationFaultExtension(final TypedXmlWriter fault, final JavaMethod method, final CheckedException exception) {
    LOGGER.entering();
    final String messageName = (null == exception) ? null : exception.getMessageName();
    selectAndProcessSubject(fault, WSDLFault.class, ScopeType.FAULT_MESSAGE, messageName);
    LOGGER.exiting();
}
 
Example #10
Source File: XmlPolicyModelMarshaller.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marshal the Policy root element attributes onto the TypedXmlWriter.
 *
 * @param model The policy source model.
 * @param writer The typed XML writer.
 */
private static void marshalPolicyAttributes(final PolicySourceModel model, final TypedXmlWriter writer) {
    final String policyId = model.getPolicyId();
    if (policyId != null) {
        writer._attribute(PolicyConstants.WSU_ID, policyId);
    }

    final String policyName = model.getPolicyName();
    if (policyName != null) {
        writer._attribute(model.getNamespaceVersion().asQName(XmlToken.Name), policyName);
    }
}
 
Example #11
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addPortExtension(final TypedXmlWriter port) {
    LOGGER.entering();
    final String portName = (null == seiModel) ? null : seiModel.getPortName().getLocalPart();
    selectAndProcessSubject(port, WSDLPort.class, ScopeType.ENDPOINT, portName);
    LOGGER.exiting();
}
 
Example #12
Source File: WSDLGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void generateSOAPHeaders(TypedXmlWriter writer, List<ParameterImpl> parameters, QName message) {

        for (ParameterImpl headerParam : parameters) {
            Header header = writer._element(Header.class);
            header.message(message);
            header.part(headerParam.getPartName());
            header.use(LITERAL);
        }
    }
 
Example #13
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void selectAndProcessBindingSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final QName bindingName) {
    LOGGER.entering(xmlWriter, clazz, scopeType, bindingName);
    if ((subjects != null) && (bindingName != null)) {
        for (PolicySubject subject : subjects) {
            if (subject.getSubject() instanceof WsdlBindingSubject) {
                final WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) subject.getSubject();
                if (bindingName.equals(wsdlSubject.getName())) {
                    writePolicyOrReferenceIt(subject, xmlWriter);
                }
            }
        }
    }
    selectAndProcessSubject(xmlWriter, clazz, scopeType, bindingName);
    LOGGER.exiting();
}
 
Example #14
Source File: W3CAddressingWSDLGeneratorExtension.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addBindingExtension(TypedXmlWriter binding) {
    if (!enabled)
        return;
    binding._element(AddressingVersion.W3C.wsdlExtensionTag, UsingAddressing.class);
    /*
    Do not generate wsdl:required=true
    if(required) {
        ua.required(true);
    }
    */
}
 
Example #15
Source File: W3CAddressingWSDLGeneratorExtension.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addBindingExtension(TypedXmlWriter binding) {
    if (!enabled)
        return;
    binding._element(AddressingVersion.W3C.wsdlExtensionTag, UsingAddressing.class);
    /*
    Do not generate wsdl:required=true
    if(required) {
        ua.required(true);
    }
    */
}
 
Example #16
Source File: XmlPolicyModelMarshaller.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marshal the Policy root element attributes onto the TypedXmlWriter.
 *
 * @param model The policy source model.
 * @param writer The typed XML writer.
 */
private static void marshalPolicyAttributes(final PolicySourceModel model, final TypedXmlWriter writer) {
    final String policyId = model.getPolicyId();
    if (policyId != null) {
        writer._attribute(PolicyConstants.WSU_ID, policyId);
    }

    final String policyName = model.getPolicyName();
    if (policyName != null) {
        writer._attribute(model.getNamespaceVersion().asQName(XmlToken.Name), policyName);
    }
}
 
Example #17
Source File: W3CAddressingWSDLGeneratorExtension.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@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());
}
 
Example #18
Source File: WSDLGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void generateSOAPHeaders(TypedXmlWriter writer, List<ParameterImpl> parameters, QName message) {

        for (ParameterImpl headerParam : parameters) {
            Header header = writer._element(Header.class);
            header.message(message);
            header.part(headerParam.getPartName());
            header.use(LITERAL);
        }
    }
 
Example #19
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addOperationFaultExtension(final TypedXmlWriter fault, final JavaMethod method, final CheckedException exception) {
    LOGGER.entering();
    final String messageName = (null == exception) ? null : exception.getMessageName();
    selectAndProcessSubject(fault, WSDLFault.class, ScopeType.FAULT_MESSAGE, messageName);
    LOGGER.exiting();
}
 
Example #20
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addInputMessageExtension(final TypedXmlWriter message, final JavaMethod method) {
    LOGGER.entering();
    final String messageName = (null == method) ? null : method.getRequestMessageName();
    selectAndProcessSubject(message, WSDLMessage.class, ScopeType.INPUT_MESSAGE, messageName);
    LOGGER.exiting();
}
 
Example #21
Source File: PolicyWSDLGeneratorExtension.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void start(final WSDLGenExtnContext context) {
    LOGGER.entering();
    try {
        this.seiModel = context.getModel();

        final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators();
        final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length];
        for (int i = 0; i < policyMapConfigurators.length; i++) {
            extenders[i] = PolicyMapExtender.createPolicyMapExtender();
        }
        // Read policy config file
        policyMap = PolicyResolverFactory.create().resolve(
                new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders));

        if (policyMap == null) {
            LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP());
            policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders));
        }

        final WSBinding binding = context.getBinding();
        try {
            final Collection<PolicySubject> policySubjects = new LinkedList<PolicySubject>();
            for (int i = 0; i < policyMapConfigurators.length; i++) {
                policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding));
                extenders[i].disconnect();
            }
            PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName());
        } catch (PolicyException e) {
            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e));
        }
        final TypedXmlWriter root = context.getRoot();
        root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix());
        root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix());
        root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX);

    } finally {
        LOGGER.exiting();
    }
}
 
Example #22
Source File: PolicyWSDLGeneratorExtension.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addServiceExtension(final TypedXmlWriter service) {
    LOGGER.entering();
    final String serviceName = (null == seiModel) ? null : seiModel.getServiceQName().getLocalPart();
    selectAndProcessSubject(service, WSDLService.class, ScopeType.SERVICE, serviceName);
    LOGGER.exiting();
}
 
Example #23
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addBindingOperationExtension(final TypedXmlWriter operation, final JavaMethod method) {
    LOGGER.entering();
    final QName operationName = (method == null) ? null : new QName(method.getOwner().getTargetNamespace(), method.getOperationName());
    selectAndProcessBindingSubject(operation, WSDLBoundOperation.class, ScopeType.OPERATION, operationName);
    LOGGER.exiting();
}
 
Example #24
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addBindingOperationOutputExtension(final TypedXmlWriter output, final JavaMethod method) {
    LOGGER.entering();
    final QName operationName = new QName(method.getOwner().getTargetNamespace(), method.getOperationName());
    selectAndProcessBindingSubject(output, WSDLBoundOperation.class, ScopeType.OUTPUT_MESSAGE, operationName);
    LOGGER.exiting();
}
 
Example #25
Source File: WSDLGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void generateSOAPHeaders(TypedXmlWriter writer, List<ParameterImpl> parameters, QName message) {

        for (ParameterImpl headerParam : parameters) {
            Header header = writer._element(Header.class);
            header.message(message);
            header.part(headerParam.getPartName());
            header.use(LITERAL);
        }
    }
 
Example #26
Source File: WSDLGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void generateSOAP12Headers(TypedXmlWriter writer, List<ParameterImpl> parameters, QName message) {

        for (ParameterImpl headerParam : parameters) {
            com.sun.xml.internal.ws.wsdl.writer.document.soap12.Header header = writer._element(com.sun.xml.internal.ws.wsdl.writer.document.soap12.Header.class);
            header.message(message);


            header.part(headerParam.getPartName());
            header.use(LITERAL);
        }
    }
 
Example #27
Source File: XmlPolicyModelMarshaller.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #28
Source File: PolicyWSDLGeneratorExtension.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addOperationFaultExtension(final TypedXmlWriter fault, final JavaMethod method, final CheckedException exception) {
    LOGGER.entering();
    final String messageName = (null == exception) ? null : exception.getMessageName();
    selectAndProcessSubject(fault, WSDLFault.class, ScopeType.FAULT_MESSAGE, messageName);
    LOGGER.exiting();
}
 
Example #29
Source File: W3CAddressingWSDLGeneratorExtension.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addBindingExtension(TypedXmlWriter binding) {
    if (!enabled)
        return;
    binding._element(AddressingVersion.W3C.wsdlExtensionTag, UsingAddressing.class);
    /*
    Do not generate wsdl:required=true
    if(required) {
        ua.required(true);
    }
    */
}
 
Example #30
Source File: XmlPolicyModelMarshaller.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void marshal(final PolicySourceModel model, final Object storage) throws PolicyException {
    if (storage instanceof StaxSerializer) {
        marshal(model, (StaxSerializer) storage);
    } else if (storage instanceof TypedXmlWriter) {
        marshal(model, (TypedXmlWriter) storage);
    } else if (storage instanceof XMLStreamWriter) {
        marshal(model, (XMLStreamWriter) storage);
    } else {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0022_STORAGE_TYPE_NOT_SUPPORTED(storage.getClass().getName())));
    }
}