Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.api.message; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.istack.internal.NotNull; |
aoqi@0 | 29 | import com.sun.xml.internal.bind.api.Bridge; |
aoqi@0 | 30 | import com.sun.xml.internal.bind.api.JAXBRIContext; |
aoqi@0 | 31 | import com.sun.xml.internal.bind.v2.runtime.MarshallerImpl; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.api.SOAPVersion; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.api.pipe.Pipe; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.message.DOMHeader; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.message.StringHeader; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.message.jaxb.JAXBHeader; |
aoqi@0 | 37 | import com.sun.xml.internal.ws.message.saaj.SAAJHeader; |
aoqi@0 | 38 | import com.sun.xml.internal.ws.message.stream.StreamHeader11; |
aoqi@0 | 39 | import com.sun.xml.internal.ws.message.stream.StreamHeader12; |
aoqi@0 | 40 | import com.sun.xml.internal.ws.spi.db.BindingContext; |
aoqi@0 | 41 | import com.sun.xml.internal.ws.spi.db.BindingContextFactory; |
aoqi@0 | 42 | import com.sun.xml.internal.ws.spi.db.XMLBridge; |
aoqi@0 | 43 | |
aoqi@0 | 44 | import org.w3c.dom.Element; |
aoqi@0 | 45 | |
aoqi@0 | 46 | import javax.xml.bind.JAXBContext; |
aoqi@0 | 47 | import javax.xml.bind.JAXBElement; |
aoqi@0 | 48 | import javax.xml.bind.Marshaller; |
aoqi@0 | 49 | import javax.xml.namespace.QName; |
aoqi@0 | 50 | import javax.xml.soap.SOAPHeaderElement; |
aoqi@0 | 51 | import javax.xml.stream.XMLStreamException; |
aoqi@0 | 52 | import javax.xml.stream.XMLStreamReader; |
aoqi@0 | 53 | |
aoqi@0 | 54 | /** |
aoqi@0 | 55 | * Factory methods for various {@link Header} implementations. |
aoqi@0 | 56 | * |
aoqi@0 | 57 | * <p> |
aoqi@0 | 58 | * This class provides various methods to create different |
aoqi@0 | 59 | * flavors of {@link Header} classes that store data |
aoqi@0 | 60 | * in different formats. |
aoqi@0 | 61 | * |
aoqi@0 | 62 | * <p> |
aoqi@0 | 63 | * This is a part of the JAX-WS RI internal API so that |
aoqi@0 | 64 | * {@link Pipe} implementations can reuse the implementations |
aoqi@0 | 65 | * done inside the JAX-WS without having a strong dependency |
aoqi@0 | 66 | * to the actual class. |
aoqi@0 | 67 | * |
aoqi@0 | 68 | * <p> |
aoqi@0 | 69 | * If you find some of the useful convenience methods missing |
aoqi@0 | 70 | * from this class, please talk to us. |
aoqi@0 | 71 | * |
aoqi@0 | 72 | * |
aoqi@0 | 73 | * @author Kohsuke Kawaguchi |
aoqi@0 | 74 | */ |
aoqi@0 | 75 | public abstract class Headers { |
aoqi@0 | 76 | private Headers() {} |
aoqi@0 | 77 | |
aoqi@0 | 78 | /** |
aoqi@0 | 79 | * @deprecated |
aoqi@0 | 80 | * Use {@link #create(BindingContext, Object)} instead. |
aoqi@0 | 81 | */ |
aoqi@0 | 82 | public static Header create(SOAPVersion soapVersion, Marshaller m, Object o) { |
aoqi@0 | 83 | return new JAXBHeader(BindingContextFactory.getBindingContext(m),o); |
aoqi@0 | 84 | } |
aoqi@0 | 85 | |
aoqi@0 | 86 | /** |
aoqi@0 | 87 | * Creates a {@link Header} backed a by a JAXB bean. |
aoqi@0 | 88 | */ |
aoqi@0 | 89 | public static Header create(JAXBContext context, Object o) { |
aoqi@0 | 90 | return new JAXBHeader(BindingContextFactory.create(context),o); |
aoqi@0 | 91 | } |
aoqi@0 | 92 | |
aoqi@0 | 93 | public static Header create(BindingContext context, Object o) { |
aoqi@0 | 94 | return new JAXBHeader(context,o); |
aoqi@0 | 95 | } |
aoqi@0 | 96 | |
aoqi@0 | 97 | /** |
aoqi@0 | 98 | * Creates a {@link Header} backed a by a JAXB bean, with the given tag name. |
aoqi@0 | 99 | * |
aoqi@0 | 100 | * See {@link #create(SOAPVersion, Marshaller, Object)} for the meaning |
aoqi@0 | 101 | * of other parameters. |
aoqi@0 | 102 | * |
aoqi@0 | 103 | * @param tagName |
aoqi@0 | 104 | * The name of the newly created header. Must not be null. |
aoqi@0 | 105 | * @param o |
aoqi@0 | 106 | * The JAXB bean that represents the contents of the header. Must not be null. |
aoqi@0 | 107 | */ |
aoqi@0 | 108 | public static Header create(SOAPVersion soapVersion, Marshaller m, QName tagName, Object o) { |
aoqi@0 | 109 | return create(soapVersion,m,new JAXBElement(tagName,o.getClass(),o)); |
aoqi@0 | 110 | } |
aoqi@0 | 111 | |
aoqi@0 | 112 | /** |
aoqi@0 | 113 | * Creates a {@link Header} backed a by a JAXB bean. |
aoqi@0 | 114 | * @deprecated |
aoqi@0 | 115 | */ |
aoqi@0 | 116 | public static Header create(Bridge bridge, Object jaxbObject) { |
aoqi@0 | 117 | return new JAXBHeader(new com.sun.xml.internal.ws.db.glassfish.BridgeWrapper(null,bridge), jaxbObject); |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | public static Header create(XMLBridge bridge, Object jaxbObject) { |
aoqi@0 | 121 | return new JAXBHeader(bridge, jaxbObject); |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | /** |
aoqi@0 | 125 | * Creates a new {@link Header} backed by a SAAJ object. |
aoqi@0 | 126 | */ |
aoqi@0 | 127 | public static Header create(SOAPHeaderElement header) { |
aoqi@0 | 128 | return new SAAJHeader(header); |
aoqi@0 | 129 | } |
aoqi@0 | 130 | |
aoqi@0 | 131 | /** |
aoqi@0 | 132 | * Creates a new {@link Header} backed by an {@link Element}. |
aoqi@0 | 133 | */ |
aoqi@0 | 134 | public static Header create( Element node ) { |
aoqi@0 | 135 | return new DOMHeader<Element>(node); |
aoqi@0 | 136 | } |
aoqi@0 | 137 | |
aoqi@0 | 138 | /** |
aoqi@0 | 139 | * @deprecated |
aoqi@0 | 140 | * Use {@link #create(Element)} |
aoqi@0 | 141 | */ |
aoqi@0 | 142 | public static Header create( SOAPVersion soapVersion, Element node ) { |
aoqi@0 | 143 | return create(node); |
aoqi@0 | 144 | } |
aoqi@0 | 145 | |
aoqi@0 | 146 | /** |
aoqi@0 | 147 | * Creates a new {@link Header} that reads from {@link XMLStreamReader}. |
aoqi@0 | 148 | * |
aoqi@0 | 149 | * <p> |
aoqi@0 | 150 | * Note that the header implementation will read the entire data |
aoqi@0 | 151 | * into memory anyway, so this might not be as efficient as you might hope. |
aoqi@0 | 152 | */ |
aoqi@0 | 153 | public static Header create( SOAPVersion soapVersion, XMLStreamReader reader ) throws XMLStreamException { |
aoqi@0 | 154 | switch(soapVersion) { |
aoqi@0 | 155 | case SOAP_11: |
aoqi@0 | 156 | return new StreamHeader11(reader); |
aoqi@0 | 157 | case SOAP_12: |
aoqi@0 | 158 | return new StreamHeader12(reader); |
aoqi@0 | 159 | default: |
aoqi@0 | 160 | throw new AssertionError(); |
aoqi@0 | 161 | } |
aoqi@0 | 162 | } |
aoqi@0 | 163 | |
aoqi@0 | 164 | /** |
aoqi@0 | 165 | * Creates a new {@link Header} that that has a single text value in it |
aoqi@0 | 166 | * (IOW, of the form <foo>text</foo>.) |
aoqi@0 | 167 | * |
aoqi@0 | 168 | * @param name QName of the header element |
aoqi@0 | 169 | * @param value text value of the header |
aoqi@0 | 170 | */ |
aoqi@0 | 171 | public static Header create(QName name, String value) { |
aoqi@0 | 172 | return new StringHeader(name, value); |
aoqi@0 | 173 | } |
aoqi@0 | 174 | |
aoqi@0 | 175 | /** |
aoqi@0 | 176 | * Creates a new {@link Header} that that has a single text value in it |
aoqi@0 | 177 | * (IOW, of the form <foo>text</foo>.) |
aoqi@0 | 178 | * |
aoqi@0 | 179 | * @param name QName of the header element |
aoqi@0 | 180 | * @param value text value of the header |
aoqi@0 | 181 | */ |
aoqi@0 | 182 | public static Header createMustUnderstand(@NotNull SOAPVersion soapVersion, @NotNull QName name,@NotNull String value) { |
aoqi@0 | 183 | return new StringHeader(name, value,soapVersion,true); |
aoqi@0 | 184 | } |
aoqi@0 | 185 | } |