Fri, 23 Aug 2013 09:57:21 +0100
8022885: Update JAX-WS RI integration to 2.2.9-b14140
8013016: Rebase 8009009 against the latest jdk8/jaxws
Reviewed-by: alanb, chegar
ohair@286 | 1 | /* |
mkos@397 | 2 | * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.stream.buffer.stax; |
ohair@286 | 27 | |
ohair@286 | 28 | import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer; |
ohair@286 | 29 | import com.sun.xml.internal.org.jvnet.staxex.Base64Data; |
ohair@286 | 30 | import com.sun.xml.internal.org.jvnet.staxex.NamespaceContextEx; |
ohair@286 | 31 | import com.sun.xml.internal.org.jvnet.staxex.XMLStreamWriterEx; |
ohair@286 | 32 | |
ohair@286 | 33 | import javax.activation.DataHandler; |
ohair@286 | 34 | import javax.xml.namespace.NamespaceContext; |
ohair@286 | 35 | import javax.xml.stream.XMLStreamException; |
ohair@286 | 36 | import javax.xml.stream.XMLStreamWriter; |
ohair@286 | 37 | import java.io.OutputStream; |
ohair@286 | 38 | |
ohair@286 | 39 | /** |
ohair@286 | 40 | * {@link XMLStreamWriter} that fills {@link MutableXMLStreamBuffer}. |
ohair@286 | 41 | * <p> |
ohair@286 | 42 | * TODO: need to retain all attributes/namespaces and then store all namespaces |
ohair@286 | 43 | * before the attributes. Currently it is necessary for the caller to ensure |
ohair@286 | 44 | * all namespaces are written before attributes and the caller must not intermix |
ohair@286 | 45 | * calls to the writeNamespace and writeAttribute methods. |
ohair@286 | 46 | * |
ohair@286 | 47 | */ |
ohair@286 | 48 | public class StreamWriterBufferCreator extends StreamBufferCreator implements XMLStreamWriterEx { |
ohair@286 | 49 | private final NamespaceContexHelper namespaceContext = new NamespaceContexHelper(); |
ohair@286 | 50 | |
ohair@286 | 51 | /** |
ohair@286 | 52 | * Nesting depth of the element. |
ohair@286 | 53 | * This field is ultimately used to keep track of the # of trees we created in |
ohair@286 | 54 | * the buffer. |
ohair@286 | 55 | */ |
ohair@286 | 56 | private int depth=0; |
ohair@286 | 57 | |
ohair@286 | 58 | public StreamWriterBufferCreator() { |
ohair@286 | 59 | setXMLStreamBuffer(new MutableXMLStreamBuffer()); |
ohair@286 | 60 | } |
ohair@286 | 61 | |
ohair@286 | 62 | public StreamWriterBufferCreator(MutableXMLStreamBuffer buffer) { |
ohair@286 | 63 | setXMLStreamBuffer(buffer); |
ohair@286 | 64 | } |
ohair@286 | 65 | |
ohair@286 | 66 | // XMLStreamWriter |
ohair@286 | 67 | |
ohair@286 | 68 | public Object getProperty(String str) throws IllegalArgumentException { |
ohair@286 | 69 | return null; //return null for all the property names instead of |
ohair@286 | 70 | //throwing unsupported operation exception. |
ohair@286 | 71 | } |
ohair@286 | 72 | |
ohair@286 | 73 | public void close() throws XMLStreamException { |
ohair@286 | 74 | } |
ohair@286 | 75 | |
ohair@286 | 76 | public void flush() throws XMLStreamException { |
ohair@286 | 77 | } |
ohair@286 | 78 | |
ohair@286 | 79 | public NamespaceContextEx getNamespaceContext() { |
ohair@286 | 80 | return namespaceContext; |
ohair@286 | 81 | } |
ohair@286 | 82 | |
ohair@286 | 83 | public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException { |
ohair@286 | 84 | /* |
ohair@286 | 85 | * It is really unclear from the JavaDoc how to implement this method. |
ohair@286 | 86 | */ |
ohair@286 | 87 | throw new UnsupportedOperationException(); |
ohair@286 | 88 | } |
ohair@286 | 89 | |
ohair@286 | 90 | public void setDefaultNamespace(String namespaceURI) throws XMLStreamException { |
ohair@286 | 91 | setPrefix("", namespaceURI); |
ohair@286 | 92 | } |
ohair@286 | 93 | |
ohair@286 | 94 | public void setPrefix(String prefix, String namespaceURI) throws XMLStreamException { |
ohair@286 | 95 | namespaceContext.declareNamespace(prefix, namespaceURI); |
ohair@286 | 96 | } |
ohair@286 | 97 | |
ohair@286 | 98 | public String getPrefix(String namespaceURI) throws XMLStreamException { |
ohair@286 | 99 | return namespaceContext.getPrefix(namespaceURI); |
ohair@286 | 100 | } |
ohair@286 | 101 | |
ohair@286 | 102 | |
ohair@286 | 103 | public void writeStartDocument() throws XMLStreamException { |
ohair@286 | 104 | writeStartDocument("", ""); |
ohair@286 | 105 | } |
ohair@286 | 106 | |
ohair@286 | 107 | public void writeStartDocument(String version) throws XMLStreamException { |
ohair@286 | 108 | writeStartDocument("", ""); |
ohair@286 | 109 | } |
ohair@286 | 110 | |
ohair@286 | 111 | public void writeStartDocument(String encoding, String version) throws XMLStreamException { |
ohair@286 | 112 | namespaceContext.resetContexts(); |
ohair@286 | 113 | |
ohair@286 | 114 | storeStructure(T_DOCUMENT); |
ohair@286 | 115 | } |
ohair@286 | 116 | |
ohair@286 | 117 | public void writeEndDocument() throws XMLStreamException { |
ohair@286 | 118 | storeStructure(T_END); |
ohair@286 | 119 | } |
ohair@286 | 120 | |
ohair@286 | 121 | public void writeStartElement(String localName) throws XMLStreamException { |
ohair@286 | 122 | namespaceContext.pushContext(); |
ohair@286 | 123 | depth++; |
ohair@286 | 124 | |
ohair@286 | 125 | final String defaultNamespaceURI = namespaceContext.getNamespaceURI(""); |
ohair@286 | 126 | |
ohair@286 | 127 | if (defaultNamespaceURI == null) |
ohair@286 | 128 | storeQualifiedName(T_ELEMENT_LN, null, null, localName); |
ohair@286 | 129 | else |
ohair@286 | 130 | storeQualifiedName(T_ELEMENT_LN, null, defaultNamespaceURI, localName); |
ohair@286 | 131 | } |
ohair@286 | 132 | |
ohair@286 | 133 | public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException { |
ohair@286 | 134 | namespaceContext.pushContext(); |
ohair@286 | 135 | depth++; |
ohair@286 | 136 | |
ohair@286 | 137 | final String prefix = namespaceContext.getPrefix(namespaceURI); |
ohair@286 | 138 | if (prefix == null) { |
ohair@286 | 139 | throw new XMLStreamException(); |
ohair@286 | 140 | } |
ohair@286 | 141 | |
ohair@286 | 142 | namespaceContext.pushContext(); |
ohair@286 | 143 | storeQualifiedName(T_ELEMENT_LN, prefix, namespaceURI, localName); |
ohair@286 | 144 | } |
ohair@286 | 145 | |
ohair@286 | 146 | public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { |
ohair@286 | 147 | namespaceContext.pushContext(); |
ohair@286 | 148 | depth++; |
ohair@286 | 149 | |
ohair@286 | 150 | storeQualifiedName(T_ELEMENT_LN, prefix, namespaceURI, localName); |
ohair@286 | 151 | } |
ohair@286 | 152 | |
ohair@286 | 153 | public void writeEmptyElement(String localName) throws XMLStreamException { |
ohair@286 | 154 | writeStartElement(localName); |
ohair@286 | 155 | writeEndElement(); |
ohair@286 | 156 | } |
ohair@286 | 157 | |
ohair@286 | 158 | public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException { |
ohair@286 | 159 | writeStartElement(namespaceURI, localName); |
ohair@286 | 160 | writeEndElement(); |
ohair@286 | 161 | } |
ohair@286 | 162 | |
ohair@286 | 163 | public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { |
ohair@286 | 164 | writeStartElement(prefix, localName, namespaceURI); |
ohair@286 | 165 | writeEndElement(); |
ohair@286 | 166 | } |
ohair@286 | 167 | |
ohair@286 | 168 | public void writeEndElement() throws XMLStreamException { |
ohair@286 | 169 | namespaceContext.popContext(); |
ohair@286 | 170 | |
ohair@286 | 171 | storeStructure(T_END); |
ohair@286 | 172 | if(--depth==0) |
ohair@286 | 173 | increaseTreeCount(); |
ohair@286 | 174 | } |
ohair@286 | 175 | |
ohair@286 | 176 | public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException { |
ohair@286 | 177 | storeNamespaceAttribute(null, namespaceURI); |
ohair@286 | 178 | } |
ohair@286 | 179 | |
ohair@286 | 180 | public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { |
ohair@286 | 181 | if ("xmlns".equals(prefix)) |
ohair@286 | 182 | prefix = null; |
ohair@286 | 183 | storeNamespaceAttribute(prefix, namespaceURI); |
ohair@286 | 184 | } |
ohair@286 | 185 | |
ohair@286 | 186 | |
ohair@286 | 187 | public void writeAttribute(String localName, String value) throws XMLStreamException { |
ohair@286 | 188 | storeAttribute(null, null, localName, "CDATA", value); |
ohair@286 | 189 | } |
ohair@286 | 190 | |
ohair@286 | 191 | public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException { |
ohair@286 | 192 | final String prefix = namespaceContext.getPrefix(namespaceURI); |
ohair@286 | 193 | if (prefix == null) { |
ohair@286 | 194 | // TODO |
ohair@286 | 195 | throw new XMLStreamException(); |
ohair@286 | 196 | } |
ohair@286 | 197 | |
ohair@286 | 198 | writeAttribute(prefix, namespaceURI, localName, value); |
ohair@286 | 199 | } |
ohair@286 | 200 | |
ohair@286 | 201 | public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException { |
ohair@286 | 202 | storeAttribute(prefix, namespaceURI, localName, "CDATA", value); |
ohair@286 | 203 | } |
ohair@286 | 204 | |
ohair@286 | 205 | public void writeCData(String data) throws XMLStreamException { |
ohair@286 | 206 | storeStructure(T_TEXT_AS_STRING); |
ohair@286 | 207 | storeContentString(data); |
ohair@286 | 208 | } |
ohair@286 | 209 | |
ohair@286 | 210 | public void writeCharacters(String charData) throws XMLStreamException { |
ohair@286 | 211 | storeStructure(T_TEXT_AS_STRING); |
ohair@286 | 212 | storeContentString(charData); |
ohair@286 | 213 | } |
ohair@286 | 214 | |
ohair@286 | 215 | public void writeCharacters(char[] buf, int start, int len) throws XMLStreamException { |
ohair@286 | 216 | storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, buf, start, len); |
ohair@286 | 217 | } |
ohair@286 | 218 | |
ohair@286 | 219 | public void writeComment(String str) throws XMLStreamException { |
ohair@286 | 220 | storeStructure(T_COMMENT_AS_STRING); |
ohair@286 | 221 | storeContentString(str); |
ohair@286 | 222 | } |
ohair@286 | 223 | |
ohair@286 | 224 | public void writeDTD(String str) throws XMLStreamException { |
ohair@286 | 225 | // not support. just ignore. |
ohair@286 | 226 | } |
ohair@286 | 227 | |
ohair@286 | 228 | public void writeEntityRef(String str) throws XMLStreamException { |
ohair@286 | 229 | storeStructure(T_UNEXPANDED_ENTITY_REFERENCE); |
ohair@286 | 230 | storeContentString(str); |
ohair@286 | 231 | } |
ohair@286 | 232 | |
ohair@286 | 233 | public void writeProcessingInstruction(String target) throws XMLStreamException { |
ohair@286 | 234 | writeProcessingInstruction(target, ""); |
ohair@286 | 235 | } |
ohair@286 | 236 | |
ohair@286 | 237 | public void writeProcessingInstruction(String target, String data) throws XMLStreamException { |
ohair@286 | 238 | storeProcessingInstruction(target, data); |
ohair@286 | 239 | } |
ohair@286 | 240 | |
ohair@286 | 241 | // XMLStreamWriterEx |
ohair@286 | 242 | |
ohair@286 | 243 | public void writePCDATA(CharSequence charSequence) throws XMLStreamException { |
ohair@286 | 244 | if (charSequence instanceof Base64Data) { |
ohair@286 | 245 | storeStructure(T_TEXT_AS_OBJECT); |
ohair@286 | 246 | storeContentObject(((Base64Data)charSequence).clone()); |
ohair@286 | 247 | } else { |
ohair@286 | 248 | writeCharacters(charSequence.toString()); |
ohair@286 | 249 | } |
ohair@286 | 250 | } |
ohair@286 | 251 | |
ohair@286 | 252 | public void writeBinary(byte[] bytes, int offset, int length, String endpointURL) throws XMLStreamException { |
ohair@286 | 253 | Base64Data d = new Base64Data(); |
ohair@286 | 254 | byte b[] = new byte[length]; |
ohair@286 | 255 | System.arraycopy(bytes, offset, b, 0, length); |
ohair@286 | 256 | d.set(b, length, null, true); |
ohair@286 | 257 | storeStructure(T_TEXT_AS_OBJECT); |
ohair@286 | 258 | storeContentObject(d); |
ohair@286 | 259 | } |
ohair@286 | 260 | |
ohair@286 | 261 | public void writeBinary(DataHandler dataHandler) throws XMLStreamException { |
ohair@286 | 262 | Base64Data d = new Base64Data(); |
ohair@286 | 263 | d.set(dataHandler); |
ohair@286 | 264 | storeStructure(T_TEXT_AS_OBJECT); |
ohair@286 | 265 | storeContentObject(d); |
ohair@286 | 266 | } |
ohair@286 | 267 | |
ohair@286 | 268 | public OutputStream writeBinary(String endpointURL) throws XMLStreamException { |
ohair@286 | 269 | // TODO |
ohair@286 | 270 | throw new UnsupportedOperationException(); |
ohair@286 | 271 | } |
ohair@286 | 272 | } |