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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

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

mercurial