src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/SOAPPartImpl.java

Fri, 14 Feb 2014 11:13:45 +0100

author
mkos
date
Fri, 14 Feb 2014 11:13:45 +0100
changeset 515
6cd506508147
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 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.messaging.saaj.soap;
ohair@286 27
ohair@286 28 import java.io.*;
ohair@286 29 import java.util.Iterator;
ohair@286 30 import java.util.logging.Logger;
ohair@286 31 import java.util.logging.Level;
ohair@286 32
ohair@286 33 import javax.activation.DataHandler;
ohair@286 34 import javax.activation.DataSource;
ohair@286 35 import javax.xml.soap.*;
ohair@286 36 import javax.xml.transform.Source;
ohair@286 37 import javax.xml.transform.stream.StreamSource;
ohair@286 38
ohair@286 39 import org.w3c.dom.*;
ohair@286 40
ohair@286 41 import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;
ohair@286 42
ohair@286 43 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
ohair@286 44 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl;
ohair@286 45 import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
ohair@286 46 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
ohair@286 47 import com.sun.xml.internal.messaging.saaj.util.*;
ohair@286 48
ohair@286 49 import javax.xml.transform.dom.DOMSource;
ohair@286 50 import javax.xml.transform.sax.SAXSource;
ohair@286 51
ohair@286 52 /**
ohair@286 53 * SOAPPartImpl is the first attachment. This contains the XML/SOAP document.
ohair@286 54 *
ohair@286 55 * @author Anil Vijendran (anil@sun.com)
ohair@286 56 */
ohair@286 57 public abstract class SOAPPartImpl extends SOAPPart implements SOAPDocument {
ohair@286 58 protected static final Logger log =
ohair@286 59 Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
ohair@286 60 "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
ohair@286 61
ohair@286 62 protected MimeHeaders headers;
ohair@286 63 protected Envelope envelope;
ohair@286 64 protected Source source;
ohair@286 65 protected SOAPDocumentImpl document;
ohair@286 66
ohair@286 67 //flag to indicate if a setContent happened.
ohair@286 68 private boolean sourceWasSet = false;
ohair@286 69
ohair@286 70 // Records whether the input source had an xml decl or not.
ohair@286 71 protected boolean omitXmlDecl = true;
ohair@286 72
ohair@286 73 // Records the charset encoding of the input stream source if provided.
ohair@286 74 protected String sourceCharsetEncoding = null;
ohair@286 75
ohair@286 76 /**
ohair@286 77 * Reference to containing message (may be null)
ohair@286 78 */
ohair@286 79 protected MessageImpl message;
ohair@286 80
ohair@286 81 static final boolean lazyContentLength;
ohair@286 82 static {
ohair@286 83 lazyContentLength = SAAJUtil.getSystemBoolean("saaj.lazy.contentlength");
ohair@286 84 }
ohair@286 85
ohair@286 86 protected SOAPPartImpl() {
ohair@286 87 this(null);
ohair@286 88 }
ohair@286 89
ohair@286 90 protected SOAPPartImpl(MessageImpl message) {
ohair@286 91 document = new SOAPDocumentImpl(this);
ohair@286 92 headers = new MimeHeaders();
ohair@286 93 this.message = message;
ohair@286 94 headers.setHeader("Content-Type", getContentType());
ohair@286 95 }
ohair@286 96
ohair@286 97 protected abstract String getContentType();
ohair@286 98 protected abstract Envelope createEnvelopeFromSource()
ohair@286 99 throws SOAPException;
ohair@286 100 protected abstract Envelope createEmptyEnvelope(String prefix)
ohair@286 101 throws SOAPException;
ohair@286 102 protected abstract SOAPPartImpl duplicateType();
ohair@286 103
ohair@286 104 protected String getContentTypeString() {
ohair@286 105 return getContentType();
ohair@286 106 }
ohair@286 107
ohair@286 108 public boolean isFastInfoset() {
ohair@286 109 return (message != null) ? message.isFastInfoset() : false;
ohair@286 110 }
ohair@286 111
ohair@286 112 public SOAPEnvelope getEnvelope() throws SOAPException {
ohair@286 113
ohair@286 114 // If there is no SOAP envelope already created, then create
ohair@286 115 // one from a source if one exists. If there is a newer source
ohair@286 116 // then use that source.
ohair@286 117
ohair@286 118 if (sourceWasSet)
ohair@286 119 sourceWasSet = false;
ohair@286 120
ohair@286 121 lookForEnvelope();
ohair@286 122 if (envelope != null) {
ohair@286 123 if (source != null) { // there's a newer source, use it
ohair@286 124 document.removeChild(envelope);
ohair@286 125 envelope = createEnvelopeFromSource();
ohair@286 126 }
ohair@286 127 } else if (source != null) {
ohair@286 128 envelope = createEnvelopeFromSource();
ohair@286 129 } else {
ohair@286 130 envelope = createEmptyEnvelope(null);
ohair@286 131 document.insertBefore(envelope, null);
ohair@286 132 }
ohair@286 133 return envelope;
ohair@286 134 }
ohair@286 135
ohair@286 136 protected void lookForEnvelope() throws SOAPException {
ohair@286 137 Element envelopeChildElement = document.doGetDocumentElement();
ohair@286 138 if (envelopeChildElement == null || envelopeChildElement instanceof Envelope) {
ohair@286 139 envelope = (EnvelopeImpl) envelopeChildElement;
ohair@286 140 } else if (!(envelopeChildElement instanceof ElementImpl)) {
ohair@286 141 log.severe("SAAJ0512.soap.incorrect.factory.used");
ohair@286 142 throw new SOAPExceptionImpl("Unable to create envelope: incorrect factory used during tree construction");
ohair@286 143 } else {
ohair@286 144 ElementImpl soapElement = (ElementImpl) envelopeChildElement;
ohair@286 145 if (soapElement.getLocalName().equalsIgnoreCase("Envelope")) {
ohair@286 146 String prefix = soapElement.getPrefix();
ohair@286 147 String uri = (prefix == null) ? soapElement.getNamespaceURI() : soapElement.getNamespaceURI(prefix);
ohair@286 148 if(!uri.equals(NameImpl.SOAP11_NAMESPACE) && !uri.equals(NameImpl.SOAP12_NAMESPACE)) {
ohair@286 149 log.severe("SAAJ0513.soap.unknown.ns");
ohair@286 150 throw new SOAPVersionMismatchException("Unable to create envelope from given source because the namespace was not recognized");
ohair@286 151 }
ohair@286 152 } else {
ohair@286 153 log.severe("SAAJ0514.soap.root.elem.not.named.envelope");
ohair@286 154 throw new SOAPExceptionImpl(
ohair@286 155 "Unable to create envelope from given source because the root element is not named \"Envelope\"");
ohair@286 156 }
ohair@286 157 }
ohair@286 158 }
ohair@286 159
ohair@286 160 public void removeAllMimeHeaders() {
ohair@286 161 headers.removeAllHeaders();
ohair@286 162 }
ohair@286 163
ohair@286 164 public void removeMimeHeader(String header) {
ohair@286 165 headers.removeHeader(header);
ohair@286 166 }
ohair@286 167
ohair@286 168 public String[] getMimeHeader(String name) {
ohair@286 169 return headers.getHeader(name);
ohair@286 170 }
ohair@286 171
ohair@286 172 public void setMimeHeader(String name, String value) {
ohair@286 173 headers.setHeader(name, value);
ohair@286 174 }
ohair@286 175
ohair@286 176 public void addMimeHeader(String name, String value) {
ohair@286 177 headers.addHeader(name, value);
ohair@286 178 }
ohair@286 179
ohair@286 180 public Iterator getAllMimeHeaders() {
ohair@286 181 return headers.getAllHeaders();
ohair@286 182 }
ohair@286 183
ohair@286 184 public Iterator getMatchingMimeHeaders(String[] names) {
ohair@286 185 return headers.getMatchingHeaders(names);
ohair@286 186 }
ohair@286 187
ohair@286 188 public Iterator getNonMatchingMimeHeaders(String[] names) {
ohair@286 189 return headers.getNonMatchingHeaders(names);
ohair@286 190 }
ohair@286 191
ohair@286 192 public Source getContent() throws SOAPException {
ohair@286 193 if (source != null) {
ohair@286 194 InputStream bis = null;
ohair@286 195 if (source instanceof JAXMStreamSource) {
ohair@286 196 StreamSource streamSource = (StreamSource)source;
ohair@286 197 bis = streamSource.getInputStream();
ohair@286 198 } else if (FastInfosetReflection.isFastInfosetSource(source)) {
ohair@286 199 // FastInfosetSource inherits from SAXSource
ohair@286 200 SAXSource saxSource = (SAXSource)source;
ohair@286 201 bis = saxSource.getInputSource().getByteStream();
ohair@286 202 }
ohair@286 203
ohair@286 204 if (bis != null) {
ohair@286 205 try {
ohair@286 206 bis.reset();
ohair@286 207 } catch (IOException e) {
ohair@286 208 /* This exception will never be thrown.
ohair@286 209 *
ohair@286 210 * The setContent method will modify the source
ohair@286 211 * if StreamSource to JAXMStreamSource, that uses
ohair@286 212 * a ByteInputStream, and for a FastInfosetSource will
ohair@286 213 * replace the InputStream with a ByteInputStream.
ohair@286 214 */
ohair@286 215 }
ohair@286 216 }
ohair@286 217 return source;
ohair@286 218 }
ohair@286 219
ohair@286 220 return ((Envelope) getEnvelope()).getContent();
ohair@286 221 }
ohair@286 222
ohair@286 223 public void setContent(Source source) throws SOAPException {
ohair@286 224 try {
ohair@286 225 if (source instanceof StreamSource) {
ohair@286 226 InputStream is = ((StreamSource) source).getInputStream();
ohair@286 227 Reader rdr = ((StreamSource) source).getReader();
ohair@286 228
ohair@286 229 if (is != null) {
ohair@286 230 this.source = new JAXMStreamSource(is);
ohair@286 231 } else if (rdr != null) {
ohair@286 232 this.source = new JAXMStreamSource(rdr);
ohair@286 233 } else {
ohair@286 234 log.severe("SAAJ0544.soap.no.valid.reader.for.src");
ohair@286 235 throw new SOAPExceptionImpl("Source does not have a valid Reader or InputStream");
ohair@286 236 }
ohair@286 237 }
ohair@286 238 else if (FastInfosetReflection.isFastInfosetSource(source)) {
ohair@286 239 // InputStream is = source.getInputStream()
ohair@286 240 InputStream is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
ohair@286 241
ohair@286 242 /*
ohair@286 243 * Underlying stream must be ByteInputStream for getContentAsStream(). We pay the
ohair@286 244 * cost of copying the underlying bytes here to avoid multiple copies every time
ohair@286 245 * getBytes() is called on a ByteInputStream.
ohair@286 246 */
ohair@286 247 if (!(is instanceof ByteInputStream)) {
ohair@286 248 ByteOutputStream bout = new ByteOutputStream();
ohair@286 249 bout.write(is);
ohair@286 250
ohair@286 251 // source.setInputStream(new ByteInputStream(...))
ohair@286 252 FastInfosetReflection.FastInfosetSource_setInputStream(
ohair@286 253 source, bout.newInputStream());
ohair@286 254 }
ohair@286 255 this.source = source;
ohair@286 256 }
ohair@286 257 else {
ohair@286 258 this.source = source;
ohair@286 259 }
ohair@286 260 sourceWasSet = true;
ohair@286 261 }
ohair@286 262 catch (Exception ex) {
ohair@286 263 ex.printStackTrace();
ohair@286 264
ohair@286 265 log.severe("SAAJ0545.soap.cannot.set.src.for.part");
ohair@286 266 throw new SOAPExceptionImpl(
ohair@286 267 "Error setting the source for SOAPPart: " + ex.getMessage());
ohair@286 268 }
ohair@286 269 }
ohair@286 270
ohair@286 271 public InputStream getContentAsStream() throws IOException {
ohair@286 272 if (source != null) {
ohair@286 273 InputStream is = null;
ohair@286 274
ohair@286 275 // Allow message to be transcode if so requested
ohair@286 276 if (source instanceof StreamSource && !isFastInfoset()) {
ohair@286 277 is = ((StreamSource) source).getInputStream();
ohair@286 278 }
ohair@286 279 else if (FastInfosetReflection.isFastInfosetSource(source) &&
ohair@286 280 isFastInfoset())
ohair@286 281 {
ohair@286 282 try {
ohair@286 283 // InputStream is = source.getInputStream()
ohair@286 284 is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
ohair@286 285 }
ohair@286 286 catch (Exception e) {
ohair@286 287 throw new IOException(e.toString());
ohair@286 288 }
ohair@286 289 }
ohair@286 290
ohair@286 291 if (is != null) {
ohair@286 292 if (lazyContentLength) {
ohair@286 293 return is;
ohair@286 294 }
ohair@286 295 if (!(is instanceof ByteInputStream)) {
ohair@286 296 log.severe("SAAJ0546.soap.stream.incorrect.type");
ohair@286 297 throw new IOException("Internal error: stream not of the right type");
ohair@286 298 }
ohair@286 299 return (ByteInputStream) is;
ohair@286 300 }
ohair@286 301 // need to do something here for reader...
ohair@286 302 // for now we'll see if we can fallback...
ohair@286 303 }
ohair@286 304
ohair@286 305 ByteOutputStream b = new ByteOutputStream();
ohair@286 306
ohair@286 307 Envelope env = null;
ohair@286 308
ohair@286 309 try {
ohair@286 310 env = (Envelope) getEnvelope();
ohair@286 311 env.output(b, isFastInfoset());
ohair@286 312 }
ohair@286 313 catch (SOAPException soapException) {
ohair@286 314 log.severe("SAAJ0547.soap.cannot.externalize");
ohair@286 315 throw new SOAPIOException(
ohair@286 316 "SOAP exception while trying to externalize: ",
ohair@286 317 soapException);
ohair@286 318 }
ohair@286 319
ohair@286 320 return b.newInputStream();
ohair@286 321 }
ohair@286 322
ohair@286 323 MimeBodyPart getMimePart() throws SOAPException {
ohair@286 324 try {
ohair@286 325 MimeBodyPart headerEnvelope = new MimeBodyPart();
ohair@286 326
ohair@286 327 headerEnvelope.setDataHandler(getDataHandler());
ohair@286 328 AttachmentPartImpl.copyMimeHeaders(headers, headerEnvelope);
ohair@286 329
ohair@286 330 return headerEnvelope;
ohair@286 331 } catch (SOAPException ex) {
ohair@286 332 throw ex;
ohair@286 333 } catch (Exception ex) {
ohair@286 334 log.severe("SAAJ0548.soap.cannot.externalize.hdr");
ohair@286 335 throw new SOAPExceptionImpl("Unable to externalize header", ex);
ohair@286 336 }
ohair@286 337 }
ohair@286 338
ohair@286 339 MimeHeaders getMimeHeaders() {
ohair@286 340 return headers;
ohair@286 341 }
ohair@286 342
ohair@286 343 DataHandler getDataHandler() {
ohair@286 344 DataSource ds = new DataSource() {
ohair@286 345 public OutputStream getOutputStream() throws IOException {
ohair@286 346 throw new IOException("Illegal Operation");
ohair@286 347 }
ohair@286 348
ohair@286 349 public String getContentType() {
ohair@286 350 return getContentTypeString();
ohair@286 351 }
ohair@286 352
ohair@286 353 public String getName() {
ohair@286 354 return getContentId();
ohair@286 355 }
ohair@286 356
ohair@286 357 public InputStream getInputStream() throws IOException {
ohair@286 358 return getContentAsStream();
ohair@286 359 }
ohair@286 360 };
ohair@286 361 return new DataHandler(ds);
ohair@286 362 }
ohair@286 363
ohair@286 364 public SOAPDocumentImpl getDocument() {
ohair@286 365 handleNewSource();
ohair@286 366 return document;
ohair@286 367 }
ohair@286 368
ohair@286 369 public SOAPPartImpl getSOAPPart() {
ohair@286 370 return this;
ohair@286 371 }
ohair@286 372
ohair@286 373 public DocumentType getDoctype() {
ohair@286 374 return document.getDoctype();
ohair@286 375 }
ohair@286 376
ohair@286 377 // Forward all of these calls to the document to ensure that they work the
ohair@286 378 // same way whether they are called from here or directly from the document.
ohair@286 379 // If the document needs any help from this SOAPPart then
ohair@286 380 // Make it use a call-back as in doGetDocumentElement() below
ohair@286 381 public DOMImplementation getImplementation() {
ohair@286 382 return document.getImplementation();
ohair@286 383 }
ohair@286 384
ohair@286 385 public Element getDocumentElement() {
ohair@286 386 // If there is no SOAP envelope already created, then create
ohair@286 387 // one from a source if one exists. If there is a newer source
ohair@286 388 // then use that source.
ohair@286 389 try {
ohair@286 390 getEnvelope();
ohair@286 391 } catch (SOAPException e) {
ohair@286 392 }
ohair@286 393 return document.getDocumentElement();
ohair@286 394 }
ohair@286 395
ohair@286 396 protected void doGetDocumentElement() {
ohair@286 397 handleNewSource();
ohair@286 398 try {
ohair@286 399 lookForEnvelope();
ohair@286 400 } catch (SOAPException e) {
ohair@286 401 }
ohair@286 402 }
ohair@286 403
ohair@286 404 public Element createElement(String tagName) throws DOMException {
ohair@286 405 return document.createElement(tagName);
ohair@286 406 }
ohair@286 407
ohair@286 408 public DocumentFragment createDocumentFragment() {
ohair@286 409 return document.createDocumentFragment();
ohair@286 410 }
ohair@286 411
ohair@286 412 public org.w3c.dom.Text createTextNode(String data) {
ohair@286 413 return document.createTextNode(data);
ohair@286 414 }
ohair@286 415
ohair@286 416 public Comment createComment(String data) {
ohair@286 417 return document.createComment(data);
ohair@286 418 }
ohair@286 419
ohair@286 420 public CDATASection createCDATASection(String data) throws DOMException {
ohair@286 421 return document.createCDATASection(data);
ohair@286 422 }
ohair@286 423
ohair@286 424 public ProcessingInstruction createProcessingInstruction(
ohair@286 425 String target,
ohair@286 426 String data)
ohair@286 427 throws DOMException {
ohair@286 428 return document.createProcessingInstruction(target, data);
ohair@286 429 }
ohair@286 430
ohair@286 431 public Attr createAttribute(String name) throws DOMException {
ohair@286 432 return document.createAttribute(name);
ohair@286 433 }
ohair@286 434
ohair@286 435 public EntityReference createEntityReference(String name)
ohair@286 436 throws DOMException {
ohair@286 437 return document.createEntityReference(name);
ohair@286 438 }
ohair@286 439
ohair@286 440 public NodeList getElementsByTagName(String tagname) {
ohair@286 441 handleNewSource();
ohair@286 442 return document.getElementsByTagName(tagname);
ohair@286 443 }
ohair@286 444
ohair@286 445 public org.w3c.dom.Node importNode(
ohair@286 446 org.w3c.dom.Node importedNode,
ohair@286 447 boolean deep)
ohair@286 448 throws DOMException {
ohair@286 449 handleNewSource();
ohair@286 450 return document.importNode(importedNode, deep);
ohair@286 451 }
ohair@286 452
ohair@286 453 public Element createElementNS(String namespaceURI, String qualifiedName)
ohair@286 454 throws DOMException {
ohair@286 455 return document.createElementNS(namespaceURI, qualifiedName);
ohair@286 456 }
ohair@286 457
ohair@286 458 public Attr createAttributeNS(String namespaceURI, String qualifiedName)
ohair@286 459 throws DOMException {
ohair@286 460 return document.createAttributeNS(namespaceURI, qualifiedName);
ohair@286 461 }
ohair@286 462
ohair@286 463 public NodeList getElementsByTagNameNS(
ohair@286 464 String namespaceURI,
ohair@286 465 String localName) {
ohair@286 466 handleNewSource();
ohair@286 467 return document.getElementsByTagNameNS(namespaceURI, localName);
ohair@286 468 }
ohair@286 469
ohair@286 470 public Element getElementById(String elementId) {
ohair@286 471 handleNewSource();
ohair@286 472 return document.getElementById(elementId);
ohair@286 473 }
ohair@286 474 public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
ohair@286 475 throws DOMException {
ohair@286 476 handleNewSource();
ohair@286 477 return document.appendChild(newChild);
ohair@286 478 }
ohair@286 479
ohair@286 480 public org.w3c.dom.Node cloneNode(boolean deep) {
ohair@286 481 handleNewSource();
ohair@286 482 return document.cloneNode(deep);
ohair@286 483 }
ohair@286 484
ohair@286 485 protected SOAPPartImpl doCloneNode() {
ohair@286 486 handleNewSource();
ohair@286 487 SOAPPartImpl newSoapPart = duplicateType();
ohair@286 488
ohair@286 489 newSoapPart.headers = MimeHeadersUtil.copy(this.headers);
ohair@286 490 newSoapPart.source = this.source;
ohair@286 491 return newSoapPart;
ohair@286 492 }
ohair@286 493
ohair@286 494 public NamedNodeMap getAttributes() {
ohair@286 495 return document.getAttributes();
ohair@286 496 }
ohair@286 497
ohair@286 498 public NodeList getChildNodes() {
ohair@286 499 handleNewSource();
ohair@286 500 return document.getChildNodes();
ohair@286 501 }
ohair@286 502
ohair@286 503 public org.w3c.dom.Node getFirstChild() {
ohair@286 504 handleNewSource();
ohair@286 505 return document.getFirstChild();
ohair@286 506 }
ohair@286 507
ohair@286 508 public org.w3c.dom.Node getLastChild() {
ohair@286 509 handleNewSource();
ohair@286 510 return document.getLastChild();
ohair@286 511 }
ohair@286 512
ohair@286 513 public String getLocalName() {
ohair@286 514 return document.getLocalName();
ohair@286 515 }
ohair@286 516
ohair@286 517 public String getNamespaceURI() {
ohair@286 518 return document.getNamespaceURI();
ohair@286 519 }
ohair@286 520
ohair@286 521 public org.w3c.dom.Node getNextSibling() {
ohair@286 522 handleNewSource();
ohair@286 523 return document.getNextSibling();
ohair@286 524 }
ohair@286 525
ohair@286 526 public String getNodeName() {
ohair@286 527 return document.getNodeName();
ohair@286 528 }
ohair@286 529
ohair@286 530 public short getNodeType() {
ohair@286 531 return document.getNodeType();
ohair@286 532 }
ohair@286 533
ohair@286 534 public String getNodeValue() throws DOMException {
ohair@286 535 return document.getNodeValue();
ohair@286 536 }
ohair@286 537
ohair@286 538 public Document getOwnerDocument() {
ohair@286 539 return document.getOwnerDocument();
ohair@286 540 }
ohair@286 541
ohair@286 542 public org.w3c.dom.Node getParentNode() {
ohair@286 543 return document.getParentNode();
ohair@286 544 }
ohair@286 545
ohair@286 546 public String getPrefix() {
ohair@286 547 return document.getPrefix();
ohair@286 548 }
ohair@286 549
ohair@286 550 public org.w3c.dom.Node getPreviousSibling() {
ohair@286 551 return document.getPreviousSibling();
ohair@286 552 }
ohair@286 553
ohair@286 554 public boolean hasAttributes() {
ohair@286 555 return document.hasAttributes();
ohair@286 556 }
ohair@286 557
ohair@286 558 public boolean hasChildNodes() {
ohair@286 559 handleNewSource();
ohair@286 560 return document.hasChildNodes();
ohair@286 561 }
ohair@286 562
ohair@286 563 public org.w3c.dom.Node insertBefore(
ohair@286 564 org.w3c.dom.Node arg0,
ohair@286 565 org.w3c.dom.Node arg1)
ohair@286 566 throws DOMException {
ohair@286 567 handleNewSource();
ohair@286 568 return document.insertBefore(arg0, arg1);
ohair@286 569 }
ohair@286 570
ohair@286 571 public boolean isSupported(String arg0, String arg1) {
ohair@286 572 return document.isSupported(arg0, arg1);
ohair@286 573 }
ohair@286 574
ohair@286 575 public void normalize() {
ohair@286 576 handleNewSource();
ohair@286 577 document.normalize();
ohair@286 578 }
ohair@286 579
ohair@286 580 public org.w3c.dom.Node removeChild(org.w3c.dom.Node arg0)
ohair@286 581 throws DOMException {
ohair@286 582 handleNewSource();
ohair@286 583 return document.removeChild(arg0);
ohair@286 584 }
ohair@286 585
ohair@286 586 public org.w3c.dom.Node replaceChild(
ohair@286 587 org.w3c.dom.Node arg0,
ohair@286 588 org.w3c.dom.Node arg1)
ohair@286 589 throws DOMException {
ohair@286 590 handleNewSource();
ohair@286 591 return document.replaceChild(arg0, arg1);
ohair@286 592 }
ohair@286 593
ohair@286 594 public void setNodeValue(String arg0) throws DOMException {
ohair@286 595 document.setNodeValue(arg0);
ohair@286 596 }
ohair@286 597
ohair@286 598 public void setPrefix(String arg0) throws DOMException {
ohair@286 599 document.setPrefix(arg0);
ohair@286 600 }
ohair@286 601
ohair@286 602 private void handleNewSource() {
ohair@286 603 if (sourceWasSet) {
ohair@286 604 // There is a newer source use that source.
ohair@286 605 try {
ohair@286 606 getEnvelope();
ohair@286 607 } catch (SOAPException e) {
ohair@286 608 }
ohair@286 609 }
ohair@286 610 }
ohair@286 611
ohair@286 612 protected XMLDeclarationParser lookForXmlDecl() throws SOAPException {
ohair@286 613 if ((source != null) && (source instanceof StreamSource)) {
ohair@286 614
ohair@286 615 Reader reader = null;
ohair@286 616
ohair@286 617 InputStream inputStream = ((StreamSource) source).getInputStream();
ohair@286 618 if (inputStream != null) {
ohair@286 619 if (getSourceCharsetEncoding() == null) {
ohair@286 620 reader = new InputStreamReader(inputStream);
ohair@286 621 } else {
ohair@286 622 try {
ohair@286 623 reader =
ohair@286 624 new InputStreamReader(
ohair@286 625 inputStream, getSourceCharsetEncoding());
ohair@286 626 } catch (UnsupportedEncodingException uee) {
ohair@286 627 log.log(
ohair@286 628 Level.SEVERE,
ohair@286 629 "SAAJ0551.soap.unsupported.encoding",
ohair@286 630 new Object[] {getSourceCharsetEncoding()});
ohair@286 631 throw new SOAPExceptionImpl(
ohair@286 632 "Unsupported encoding " + getSourceCharsetEncoding(),
ohair@286 633 uee);
ohair@286 634 }
ohair@286 635 }
ohair@286 636 } else {
ohair@286 637 reader = ((StreamSource) source).getReader();
ohair@286 638 }
ohair@286 639 if (reader != null) {
ohair@286 640 PushbackReader pushbackReader =
ohair@286 641 new PushbackReader(reader, 4096); //some size to unread <?xml ....?>
ohair@286 642 XMLDeclarationParser ev =
ohair@286 643 new XMLDeclarationParser(pushbackReader);
ohair@286 644 try {
ohair@286 645 ev.parse();
ohair@286 646 } catch (Exception e) {
ohair@286 647 log.log(
ohair@286 648 Level.SEVERE,
ohair@286 649 "SAAJ0552.soap.xml.decl.parsing.failed");
ohair@286 650 throw new SOAPExceptionImpl(
ohair@286 651 "XML declaration parsing failed", e);
ohair@286 652 }
ohair@286 653 String xmlDecl = ev.getXmlDeclaration();
ohair@286 654 if ((xmlDecl != null) && (xmlDecl.length() > 0)) {
ohair@286 655 this.omitXmlDecl = false;
ohair@286 656 }
ohair@286 657 if (lazyContentLength) {
ohair@286 658 source = new StreamSource(pushbackReader);
ohair@286 659 }
ohair@286 660 return ev;
ohair@286 661 }
ohair@286 662 } else if ((source != null) && (source instanceof DOMSource)) {
ohair@286 663 //TODO: A Domsource maynot contain XMLDecl ?.
ohair@286 664 }
ohair@286 665 return null;
ohair@286 666 }
ohair@286 667
ohair@286 668 public void setSourceCharsetEncoding(String charset) {
ohair@286 669 this.sourceCharsetEncoding = charset;
ohair@286 670 }
ohair@286 671
ohair@286 672 public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName)
ohair@286 673 throws DOMException {
ohair@286 674 handleNewSource();
ohair@286 675 return document.renameNode(n, namespaceURI, qualifiedName);
ohair@286 676 }
ohair@286 677
ohair@286 678 public void normalizeDocument() {
ohair@286 679 document.normalizeDocument();
ohair@286 680 }
ohair@286 681
ohair@286 682 public DOMConfiguration getDomConfig() {
ohair@286 683 return document.getDomConfig();
ohair@286 684 }
ohair@286 685
ohair@286 686 public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) throws DOMException {
ohair@286 687 handleNewSource();
ohair@286 688 return document.adoptNode(source);
ohair@286 689 }
ohair@286 690
ohair@286 691 public void setDocumentURI(String documentURI) {
ohair@286 692 document.setDocumentURI(documentURI);
ohair@286 693 }
ohair@286 694
ohair@286 695 public String getDocumentURI() {
ohair@286 696 return document.getDocumentURI();
ohair@286 697 }
ohair@286 698
ohair@286 699 public void setStrictErrorChecking(boolean strictErrorChecking) {
ohair@286 700 document.setStrictErrorChecking(strictErrorChecking);
ohair@286 701 }
ohair@286 702
ohair@286 703 public String getInputEncoding() {
ohair@286 704 return document.getInputEncoding();
ohair@286 705 }
ohair@286 706
ohair@286 707 public String getXmlEncoding() {
ohair@286 708 return document.getXmlEncoding();
ohair@286 709 }
ohair@286 710
ohair@286 711 public boolean getXmlStandalone() {
ohair@286 712 return document.getXmlStandalone();
ohair@286 713 }
ohair@286 714
ohair@286 715 public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
ohair@286 716 document.setXmlStandalone(xmlStandalone);
ohair@286 717 }
ohair@286 718
ohair@286 719 public String getXmlVersion() {
ohair@286 720 return document.getXmlVersion();
ohair@286 721 }
ohair@286 722
ohair@286 723 public void setXmlVersion(String xmlVersion) throws DOMException {
ohair@286 724 document.setXmlVersion(xmlVersion);
ohair@286 725 }
ohair@286 726
ohair@286 727 public boolean getStrictErrorChecking() {
ohair@286 728 return document.getStrictErrorChecking();
ohair@286 729 }
ohair@286 730
ohair@286 731 // DOM L3 methods from org.w3c.dom.Node
ohair@286 732 public String getBaseURI() {
ohair@286 733 return document.getBaseURI();
ohair@286 734 }
ohair@286 735
ohair@286 736 public short compareDocumentPosition(org.w3c.dom.Node other)
ohair@286 737 throws DOMException {
ohair@286 738 return document.compareDocumentPosition(other);
ohair@286 739 }
ohair@286 740
ohair@286 741 public String getTextContent()
ohair@286 742 throws DOMException {
ohair@286 743 return document.getTextContent();
ohair@286 744 }
ohair@286 745
ohair@286 746 public void setTextContent(String textContent) throws DOMException {
ohair@286 747 document.setTextContent(textContent);
ohair@286 748 }
ohair@286 749
ohair@286 750 public boolean isSameNode(org.w3c.dom.Node other) {
ohair@286 751 return document.isSameNode(other);
ohair@286 752 }
ohair@286 753
ohair@286 754 public String lookupPrefix(String namespaceURI) {
ohair@286 755 return document.lookupPrefix(namespaceURI);
ohair@286 756 }
ohair@286 757
ohair@286 758 public boolean isDefaultNamespace(String namespaceURI) {
ohair@286 759 return document.isDefaultNamespace(namespaceURI);
ohair@286 760 }
ohair@286 761
ohair@286 762 public String lookupNamespaceURI(String prefix) {
ohair@286 763 return document.lookupNamespaceURI(prefix);
ohair@286 764 }
ohair@286 765
ohair@286 766 public boolean isEqualNode(org.w3c.dom.Node arg) {
ohair@286 767 return document.isEqualNode(arg);
ohair@286 768 }
ohair@286 769
ohair@286 770 public Object getFeature(String feature,
ohair@286 771 String version) {
ohair@286 772 return document.getFeature(feature,version);
ohair@286 773 }
ohair@286 774
ohair@286 775 public Object setUserData(String key,
ohair@286 776 Object data,
ohair@286 777 UserDataHandler handler) {
ohair@286 778 return document.setUserData(key, data, handler);
ohair@286 779 }
ohair@286 780
ohair@286 781 public Object getUserData(String key) {
ohair@286 782 return document.getUserData(key);
ohair@286 783 }
ohair@286 784
ohair@286 785 public void recycleNode() {
ohair@286 786 // Nothing seems to be required to be done here
ohair@286 787 }
ohair@286 788
ohair@286 789 public String getValue() {
ohair@286 790 return null;
ohair@286 791 }
ohair@286 792
ohair@286 793 public void setValue(String value) {
ohair@286 794 log.severe("SAAJ0571.soappart.setValue.not.defined");
ohair@286 795 throw new IllegalStateException("Setting value of a soap part is not defined");
ohair@286 796 }
ohair@286 797
ohair@286 798 public void setParentElement(SOAPElement parent) throws SOAPException {
ohair@286 799 log.severe("SAAJ0570.soappart.parent.element.not.defined");
ohair@286 800 throw new SOAPExceptionImpl("The parent element of a soap part is not defined");
ohair@286 801 }
ohair@286 802
ohair@286 803 public SOAPElement getParentElement() {
ohair@286 804 return null;
ohair@286 805 }
ohair@286 806
ohair@286 807 public void detachNode() {
ohair@286 808 // Nothing seems to be required to be done here
ohair@286 809 }
ohair@286 810
ohair@286 811 public String getSourceCharsetEncoding() {
ohair@286 812 return sourceCharsetEncoding;
ohair@286 813 }
ohair@286 814 }

mercurial