Search in sources :

Example 6 with TypedXmlWriter

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

the class PolicyWSDLGeneratorExtension method writePolicyOrReferenceIt.

/**
 * 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());
        }
    }
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicySourceModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel) WebServiceException(jakarta.xml.ws.WebServiceException) PolicyException(com.sun.xml.ws.policy.PolicyException) PolicyModelGenerator(com.sun.xml.ws.policy.sourcemodel.PolicyModelGenerator) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 7 with TypedXmlWriter

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

the class PolicyWSDLGeneratorExtension method start.

@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<>();
            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();
    }
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) PolicySubject(com.sun.xml.ws.policy.PolicySubject) WebServiceException(jakarta.xml.ws.WebServiceException) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) PolicyMapExtender(com.sun.xml.ws.policy.PolicyMapExtender) LinkedList(java.util.LinkedList) PolicyException(com.sun.xml.ws.policy.PolicyException) PolicyMapConfigurator(com.sun.xml.ws.policy.jaxws.spi.PolicyMapConfigurator) MtomPolicyMapConfigurator(com.sun.xml.ws.encoding.policy.MtomPolicyMapConfigurator) AddressingPolicyMapConfigurator(com.sun.xml.ws.addressing.policy.AddressingPolicyMapConfigurator)

Example 8 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 XMLStreamWriter.
 *
 * @param model A policy source model.
 * @param writer An XML stream writer.
 * @throws PolicyException If marshalling failed.
 */
private void marshal(final PolicySourceModel model, final XMLStreamWriter writer) throws PolicyException {
    final StaxSerializer serializer = new StaxSerializer(writer);
    final TypedXmlWriter policy = TXW.create(model.getNamespaceVersion().asQName(XmlToken.Policy), TypedXmlWriter.class, serializer);
    marshalDefaultPrefixes(model, policy);
    marshalPolicyAttributes(model, policy);
    marshal(model.getNamespaceVersion(), model.getRootNode(), policy);
    policy.commit();
    serializer.flush();
}
Also used : StaxSerializer(com.sun.xml.txw2.output.StaxSerializer) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 9 with TypedXmlWriter

use of com.sun.xml.txw2.TypedXmlWriter in project jaxb-ri by eclipse-ee4j.

the class TXW method create.

/**
 * Creates a new {@link TypedXmlWriter} to write a new instance of a document.
 *
 * @param <T> an instance of {@link TypedXmlWriter}
 * @param rootElement
 *      The {@link TypedXmlWriter} interface that declares the content model of the root element.
 *      This interface must have {@link XmlElement} annotation on it to designate the tag name
 *      of the root element.
 * @param out
 *      The target of the writing.
 * @return
 *      always return non-null {@link TypedXmlWriter} that can be used
 *      to write the contents of the root element.
 */
public static <T extends TypedXmlWriter> T create(Class<T> rootElement, XmlSerializer out) {
    if (out instanceof TXWSerializer) {
        TXWSerializer txws = (TXWSerializer) out;
        return txws.txw._element(rootElement);
    }
    Document doc = new Document(out);
    QName n = getTagName(rootElement);
    return new ContainerElement(doc, null, n.getNamespaceURI(), n.getLocalPart())._cast(rootElement);
}
Also used : TXWSerializer(com.sun.xml.txw2.output.TXWSerializer) QName(javax.xml.namespace.QName)

Example 10 with TypedXmlWriter

use of com.sun.xml.txw2.TypedXmlWriter in project jaxb-ri by eclipse-ee4j.

the class ContainerElement method addElement.

/**
 * Writes a new element.
 */
@SuppressWarnings("unchecked")
private Object addElement(XmlElement e, Method method, Object[] args) {
    Class<?> rt = method.getReturnType();
    // the last precedence: default name
    String nsUri = "##default";
    String localName = method.getName();
    if (e != null) {
        // then the annotation on this method
        if (e.value().length() != 0)
            localName = e.value();
        nsUri = e.ns();
    }
    if (nsUri.equals("##default")) {
        // look for the annotation on the declaring class
        Class<?> c = method.getDeclaringClass();
        XmlElement ce = c.getAnnotation(XmlElement.class);
        if (ce != null) {
            nsUri = ce.ns();
        }
        if (nsUri.equals("##default"))
            // then default to the XmlNamespace
            nsUri = getNamespace(c.getPackage());
    }
    if (rt == Void.TYPE) {
        // leaf element with just a value
        boolean isCDATA = method.getAnnotation(XmlCDATA.class) != null;
        StartTag st = new StartTag(document, nsUri, localName);
        addChild(st);
        for (Object arg : args) {
            Text text;
            if (isCDATA)
                text = new Cdata(document, st, arg);
            else
                text = new Pcdata(document, st, arg);
            addChild(text);
        }
        addChild(new EndTag());
        return null;
    }
    if (TypedXmlWriter.class.isAssignableFrom(rt)) {
        // sub writer
        return _element(nsUri, localName, (Class<? extends TypedXmlWriter>) rt);
    }
    throw new IllegalSignatureException("Illegal return type: " + rt);
}
Also used : XmlElement(com.sun.xml.txw2.annotation.XmlElement) XmlCDATA(com.sun.xml.txw2.annotation.XmlCDATA)

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