All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.xml.ws.api.message.Headers Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0, which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package com.sun.xml.ws.api.message;

import com.sun.istack.NotNull;
import com.sun.xml.ws.api.SOAPVersion;
import com.sun.xml.ws.api.pipe.Pipe;
import com.sun.xml.ws.message.DOMHeader;
import com.sun.xml.ws.message.StringHeader;
import com.sun.xml.ws.message.jaxb.JAXBHeader;
import com.sun.xml.ws.message.saaj.SAAJHeader;
import com.sun.xml.ws.message.stream.StreamHeader11;
import com.sun.xml.ws.message.stream.StreamHeader12;
import com.sun.xml.ws.spi.db.BindingContext;
import com.sun.xml.ws.spi.db.BindingContextFactory;
import com.sun.xml.ws.spi.db.XMLBridge;

import org.w3c.dom.Element;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import jakarta.xml.soap.SOAPHeaderElement;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

/**
 * Factory methods for various {@link Header} implementations.
 *
 * 

* This class provides various methods to create different * flavors of {@link Header} classes that store data * in different formats. * *

* This is a part of the JAX-WS RI internal API so that * {@link Pipe} implementations can reuse the implementations * done inside the JAX-WS without having a strong dependency * to the actual class. * *

* If you find some of the useful convenience methods missing * from this class, please talk to us. * * * @author Kohsuke Kawaguchi */ public abstract class Headers { private Headers() {} /** * Creates a {@link Header} backed a by a JAXB bean. */ public static Header create(JAXBContext context, Object o) { return new JAXBHeader(BindingContextFactory.create(context),o); } public static Header create(BindingContext context, Object o) { return new JAXBHeader(context,o); } public static Header create(XMLBridge bridge, Object jaxbObject) { return new JAXBHeader(bridge, jaxbObject); } /** * Creates a new {@link Header} backed by a SAAJ object. */ public static Header create(SOAPHeaderElement header) { return new SAAJHeader(header); } /** * Creates a new {@link Header} backed by an {@link Element}. */ public static Header create( Element node ) { return new DOMHeader<>(node); } /** * Creates a new {@link Header} that reads from {@link XMLStreamReader}. * *

* Note that the header implementation will read the entire data * into memory anyway, so this might not be as efficient as you might hope. */ public static Header create( SOAPVersion soapVersion, XMLStreamReader reader ) throws XMLStreamException { switch(soapVersion) { case SOAP_11: return new StreamHeader11(reader); case SOAP_12: return new StreamHeader12(reader); default: throw new AssertionError(); } } /** * Creates a new {@link Header} that that has a single text value in it * (IOW, of the form <foo>text</foo>.) * * @param name QName of the header element * @param value text value of the header */ public static Header create(QName name, String value) { return new StringHeader(name, value); } /** * Creates a new {@link Header} that that has a single text value in it * (IOW, of the form <foo>text</foo>.) * * @param name QName of the header element * @param value text value of the header */ public static Header createMustUnderstand(@NotNull SOAPVersion soapVersion, @NotNull QName name,@NotNull String value) { return new StringHeader(name, value,soapVersion,true); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy