< prev index next >

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

Print this page




  58 import javax.activation.DataSource;
  59 import javax.xml.soap.MimeHeaders;
  60 import javax.xml.soap.SOAPElement;
  61 import javax.xml.soap.SOAPEnvelope;
  62 import javax.xml.soap.SOAPException;
  63 import javax.xml.soap.SOAPPart;
  64 import javax.xml.transform.Source;
  65 import javax.xml.transform.dom.DOMSource;
  66 import javax.xml.transform.sax.SAXSource;
  67 import javax.xml.transform.stream.StreamSource;
  68 import java.io.IOException;
  69 import java.io.InputStream;
  70 import java.io.InputStreamReader;
  71 import java.io.OutputStream;
  72 import java.io.PushbackReader;
  73 import java.io.Reader;
  74 import java.io.UnsupportedEncodingException;
  75 import java.util.Iterator;
  76 import java.util.logging.Level;
  77 import java.util.logging.Logger;

  78 
  79 /**
  80  * SOAPPartImpl is the first attachment. This contains the XML/SOAP document.
  81  *
  82  * @author Anil Vijendran (anil@sun.com)
  83  */
  84 public abstract class SOAPPartImpl extends SOAPPart implements SOAPDocument {
  85     protected static final Logger log =
  86         Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
  87                          "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
  88 
  89     protected MimeHeaders headers;
  90     protected Envelope envelope;
  91     protected Source source;
  92     protected SOAPDocumentImpl document;
  93 
  94     //flag to indicate if a setContent happened.
  95     private boolean sourceWasSet = false;
  96 
  97     // Records whether the input source had an xml decl or not.


 119         headers = new MimeHeaders();
 120         this.message = message;
 121         headers.setHeader("Content-Type", getContentType());
 122     }
 123 
 124     protected abstract String getContentType();
 125     protected abstract Envelope createEnvelopeFromSource()
 126     throws SOAPException;
 127     protected abstract Envelope createEmptyEnvelope(String prefix)
 128     throws SOAPException;
 129     protected abstract SOAPPartImpl duplicateType();
 130 
 131     protected String getContentTypeString() {
 132         return getContentType();
 133     }
 134 
 135     public boolean isFastInfoset() {
 136         return (message != null) ? message.isFastInfoset() : false;
 137     }
 138 

 139     public SOAPEnvelope getEnvelope() throws SOAPException {
 140 
 141         // If there is no SOAP envelope already created, then create
 142         // one from a source if one exists. If there is a newer source
 143         // then use that source.
 144 
 145         if (sourceWasSet)
 146               sourceWasSet = false;
 147 
 148         lookForEnvelope();
 149         if (envelope != null) {
 150             if (source != null) { // there's a newer source, use it
 151                 document.removeChild(envelope);
 152                 envelope = createEnvelopeFromSource();
 153             }
 154         } else if (source != null) {
 155             envelope = createEnvelopeFromSource();
 156         } else {
 157             envelope = createEmptyEnvelope(null);
 158             document.insertBefore(((EnvelopeImpl) envelope).getDomElement(), null);


 168         } else if (document.find(envelopeChildElement) == null) {
 169             log.severe("SAAJ0512.soap.incorrect.factory.used");
 170             throw new SOAPExceptionImpl("Unable to create envelope: incorrect factory used during tree construction");
 171         } else {
 172             ElementImpl soapElement = (ElementImpl) document.find(envelopeChildElement);
 173             if (soapElement.getLocalName().equalsIgnoreCase("Envelope")) {
 174                 String prefix = soapElement.getPrefix();
 175                 String uri = (prefix == null) ? soapElement.getNamespaceURI() : soapElement.getNamespaceURI(prefix);
 176                 if(!uri.equals(NameImpl.SOAP11_NAMESPACE) && !uri.equals(NameImpl.SOAP12_NAMESPACE)) {
 177                     log.severe("SAAJ0513.soap.unknown.ns");
 178                     throw new SOAPVersionMismatchException("Unable to create envelope from given source because the namespace was not recognized");
 179                 }
 180             } else {
 181                 log.severe("SAAJ0514.soap.root.elem.not.named.envelope");
 182                 throw new SOAPExceptionImpl(
 183                     "Unable to create envelope from given source because the root element is not named \"Envelope\"");
 184             }
 185         }
 186     }
 187 

 188     public void removeAllMimeHeaders() {
 189         headers.removeAllHeaders();
 190     }
 191 

 192     public void removeMimeHeader(String header) {
 193         headers.removeHeader(header);
 194     }
 195 

 196     public String[] getMimeHeader(String name) {
 197         return headers.getHeader(name);
 198     }
 199 

 200     public void setMimeHeader(String name, String value) {
 201         headers.setHeader(name, value);
 202     }
 203 

 204     public void addMimeHeader(String name, String value) {
 205         headers.addHeader(name, value);
 206     }
 207 
 208     public Iterator getAllMimeHeaders() {

 209         return headers.getAllHeaders();
 210     }
 211 
 212     public Iterator getMatchingMimeHeaders(String[] names) {

 213         return headers.getMatchingHeaders(names);
 214     }
 215 
 216     public Iterator getNonMatchingMimeHeaders(String[] names) {

 217         return headers.getNonMatchingHeaders(names);
 218     }
 219 

 220     public Source getContent() throws SOAPException {
 221         if (source != null) {
 222             InputStream bis = null;
 223             if (source instanceof JAXMStreamSource) {
 224                 StreamSource streamSource = (StreamSource)source;
 225                 bis = streamSource.getInputStream();
 226             } else if (FastInfosetReflection.isFastInfosetSource(source)) {
 227                 // FastInfosetSource inherits from SAXSource
 228                 SAXSource saxSource = (SAXSource)source;
 229                 bis = saxSource.getInputSource().getByteStream();
 230             }
 231 
 232             if (bis != null) {
 233                 try {
 234                     bis.reset();
 235                 } catch (IOException e) {
 236                     /* This exception will never be thrown.
 237                      *
 238                      * The setContent method will modify the source
 239                      * if StreamSource to JAXMStreamSource, that uses
 240                      * a ByteInputStream, and for a FastInfosetSource will
 241                      * replace the InputStream with a ByteInputStream.
 242                      */
 243                 }
 244             }
 245             return source;
 246         }
 247 
 248         return ((Envelope) getEnvelope()).getContent();
 249     }
 250 

 251     public void setContent(Source source) throws SOAPException {
 252         try {
 253             if (source instanceof StreamSource) {
 254                 InputStream is = ((StreamSource) source).getInputStream();
 255                 Reader rdr = ((StreamSource) source).getReader();
 256 
 257                 if (is != null) {
 258                     this.source = new JAXMStreamSource(is);
 259                 } else if (rdr != null) {
 260                     this.source = new JAXMStreamSource(rdr);
 261                 } else {
 262                     log.severe("SAAJ0544.soap.no.valid.reader.for.src");
 263                     throw new SOAPExceptionImpl("Source does not have a valid Reader or InputStream");
 264                 }
 265             }
 266             else if (FastInfosetReflection.isFastInfosetSource(source)) {
 267                 // InputStream is = source.getInputStream()
 268                 InputStream is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
 269 
 270                 /*


 359             MimeBodyPart headerEnvelope = new MimeBodyPart();
 360 
 361             headerEnvelope.setDataHandler(getDataHandler());
 362             AttachmentPartImpl.copyMimeHeaders(headers, headerEnvelope);
 363 
 364             return headerEnvelope;
 365         } catch (SOAPException ex) {
 366             throw ex;
 367         } catch (Exception ex) {
 368             log.severe("SAAJ0548.soap.cannot.externalize.hdr");
 369             throw new SOAPExceptionImpl("Unable to externalize header", ex);
 370         }
 371     }
 372 
 373     MimeHeaders getMimeHeaders() {
 374         return headers;
 375     }
 376 
 377     DataHandler getDataHandler() {
 378         DataSource ds = new DataSource() {

 379             public OutputStream getOutputStream() throws IOException {
 380                 throw new IOException("Illegal Operation");
 381             }
 382 

 383             public String getContentType() {
 384                 return getContentTypeString();
 385             }
 386 

 387             public String getName() {
 388                 return getContentId();
 389             }
 390 

 391             public InputStream getInputStream() throws IOException {
 392                 return getContentAsStream();
 393             }
 394         };
 395         return new DataHandler(ds);
 396     }
 397 

 398     public SOAPDocumentImpl getDocument() {
 399         handleNewSource();
 400         return document;
 401     }
 402 

 403     public SOAPPartImpl getSOAPPart() {
 404         return this;
 405     }
 406 

 407     public DocumentType getDoctype() {
 408         return document.getDoctype();
 409     }
 410 
 411     // Forward all of these calls to the document to ensure that they work the
 412     // same way whether they are called from here or directly from the document.
 413     // If the document needs any help from this SOAPPart then
 414     // Make it use a call-back as in doGetDocumentElement() below

 415     public DOMImplementation getImplementation() {
 416         return document.getImplementation();
 417     }
 418 

 419     public Element getDocumentElement() {
 420         // If there is no SOAP envelope already created, then create
 421         // one from a source if one exists. If there is a newer source
 422         // then use that source.
 423         try {
 424             getEnvelope();
 425         } catch (SOAPException e) {
 426         }
 427         return document.getDocumentElement();
 428     }
 429 
 430     protected void doGetDocumentElement() {
 431         handleNewSource();
 432         try {
 433             lookForEnvelope();
 434         } catch (SOAPException e) {
 435         }
 436     }
 437 

 438     public Element createElement(String tagName) throws DOMException {
 439         return document.createElement(tagName);
 440     }
 441 

 442     public DocumentFragment createDocumentFragment() {
 443         return document.createDocumentFragment();
 444     }
 445 

 446     public org.w3c.dom.Text createTextNode(String data) {
 447         return document.createTextNode(data);
 448     }
 449 

 450     public Comment createComment(String data) {
 451         return document.createComment(data);
 452     }
 453 

 454     public CDATASection createCDATASection(String data) throws DOMException {
 455         return document.createCDATASection(data);
 456     }
 457 

 458     public ProcessingInstruction createProcessingInstruction(
 459     String target,
 460     String data)
 461     throws DOMException {
 462         return document.createProcessingInstruction(target, data);
 463     }
 464 

 465     public Attr createAttribute(String name) throws DOMException {
 466         return document.createAttribute(name);
 467     }
 468 

 469     public EntityReference createEntityReference(String name)
 470     throws DOMException {
 471         return document.createEntityReference(name);
 472     }
 473 

 474     public NodeList getElementsByTagName(String tagname) {
 475         handleNewSource();
 476         return document.getElementsByTagName(tagname);
 477     }
 478 

 479     public org.w3c.dom.Node importNode(
 480         org.w3c.dom.Node importedNode,
 481         boolean deep)
 482         throws DOMException {
 483         handleNewSource();
 484         return document.importNode(importedNode, deep);
 485     }
 486 

 487     public Element createElementNS(String namespaceURI, String qualifiedName)
 488     throws DOMException {
 489         return document.createElementNS(namespaceURI, qualifiedName);
 490     }
 491 

 492     public Attr createAttributeNS(String namespaceURI, String qualifiedName)
 493     throws DOMException {
 494         return document.createAttributeNS(namespaceURI, qualifiedName);
 495     }
 496 

 497     public NodeList getElementsByTagNameNS(
 498         String namespaceURI,
 499         String localName) {
 500         handleNewSource();
 501         return document.getElementsByTagNameNS(namespaceURI, localName);
 502     }
 503 

 504     public Element getElementById(String elementId) {
 505         handleNewSource();
 506         return document.getElementById(elementId);
 507     }

 508     public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
 509         throws DOMException {
 510         handleNewSource();
 511         return document.appendChild(newChild);
 512     }
 513 

 514     public org.w3c.dom.Node cloneNode(boolean deep) {
 515         handleNewSource();
 516         return document.cloneNode(deep);
 517     }
 518 
 519     protected SOAPPartImpl doCloneNode() {
 520         handleNewSource();
 521         SOAPPartImpl newSoapPart = duplicateType();
 522 
 523         newSoapPart.headers = MimeHeadersUtil.copy(this.headers);
 524         newSoapPart.source = this.source;
 525         return newSoapPart;
 526     }
 527 

 528     public NamedNodeMap getAttributes() {
 529         return document.getDomDocument().getAttributes();
 530     }
 531 

 532     public NodeList getChildNodes() {
 533         handleNewSource();
 534         return document.getChildNodes();
 535     }
 536 

 537     public org.w3c.dom.Node getFirstChild() {
 538         handleNewSource();
 539         return document.getFirstChild();
 540     }
 541 

 542     public org.w3c.dom.Node getLastChild() {
 543         handleNewSource();
 544         return document.getLastChild();
 545     }
 546 

 547     public String getLocalName() {
 548         return document.getDomDocument().getLocalName();
 549     }
 550 

 551     public String getNamespaceURI() {
 552         return document.getDomDocument().getNamespaceURI();
 553     }
 554 

 555     public org.w3c.dom.Node getNextSibling() {
 556         handleNewSource();
 557         return document.getNextSibling();
 558     }
 559 

 560     public String getNodeName() {
 561         return document.getDomDocument().getNodeName();
 562     }
 563 

 564     public short getNodeType() {
 565         return document.getDomDocument().getNodeType();
 566     }
 567 

 568     public String getNodeValue() throws DOMException {
 569         return document.getNodeValue();
 570     }
 571 

 572     public Document getOwnerDocument() {
 573         return document.getDomDocument().getOwnerDocument();
 574     }
 575 

 576     public org.w3c.dom.Node getParentNode() {
 577         return document.getDomDocument().getParentNode();
 578     }
 579 

 580     public String getPrefix() {
 581         return document.getDomDocument().getPrefix();
 582     }
 583 

 584     public org.w3c.dom.Node getPreviousSibling() {
 585         return document.getDomDocument().getPreviousSibling();
 586     }
 587 

 588     public boolean hasAttributes() {
 589         return document.getDomDocument().hasAttributes();
 590     }
 591 

 592     public boolean hasChildNodes() {
 593         handleNewSource();
 594         return document.hasChildNodes();
 595     }
 596 

 597     public org.w3c.dom.Node insertBefore(
 598         org.w3c.dom.Node arg0,
 599         org.w3c.dom.Node arg1)
 600         throws DOMException {
 601         handleNewSource();
 602         return document.insertBefore(arg0, arg1);
 603     }
 604 

 605     public boolean isSupported(String arg0, String arg1) {
 606         return document.getDomDocument().isSupported(arg0, arg1);
 607     }
 608 

 609     public void normalize() {
 610         handleNewSource();
 611         document.normalize();
 612     }
 613 

 614     public org.w3c.dom.Node removeChild(org.w3c.dom.Node arg0)
 615         throws DOMException {
 616         handleNewSource();
 617         return document.removeChild(arg0);
 618     }
 619 

 620     public org.w3c.dom.Node replaceChild(
 621         org.w3c.dom.Node arg0,
 622         org.w3c.dom.Node arg1)
 623         throws DOMException {
 624         handleNewSource();
 625         return document.replaceChild(arg0, arg1);
 626     }
 627 

 628     public void setNodeValue(String arg0) throws DOMException {
 629         document.setNodeValue(arg0);
 630     }
 631 

 632     public void setPrefix(String arg0) throws DOMException {
 633         document.setPrefix(arg0);
 634     }
 635 
 636     private void handleNewSource() {
 637         if (sourceWasSet) {
 638          // There is a newer source use that source.
 639          try {
 640              getEnvelope();
 641          } catch (SOAPException e) {
 642          }
 643       }
 644     }
 645 
 646     protected XMLDeclarationParser lookForXmlDecl() throws SOAPException {
 647         if ((source != null) && (source instanceof StreamSource)) {
 648 
 649             Reader reader = null;
 650 
 651             InputStream inputStream = ((StreamSource) source).getInputStream();


 686                 }
 687                 String xmlDecl = ev.getXmlDeclaration();
 688                 if ((xmlDecl != null) && (xmlDecl.length() > 0)) {
 689                     this.omitXmlDecl = false;
 690                 }
 691                 if (lazyContentLength) {
 692                     source = new StreamSource(pushbackReader);
 693                 }
 694                 return ev;
 695             }
 696         } else if ((source != null) && (source instanceof DOMSource)) {
 697            //TODO: A Domsource maynot contain XMLDecl ?.
 698         }
 699         return null;
 700     }
 701 
 702     public void setSourceCharsetEncoding(String charset) {
 703         this.sourceCharsetEncoding = charset;
 704     }
 705 

 706     public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName)
 707         throws DOMException {
 708         handleNewSource();
 709         return document.renameNode(n, namespaceURI, qualifiedName);
 710     }
 711 

 712     public void normalizeDocument() {
 713         document.normalizeDocument();
 714     }
 715 

 716     public DOMConfiguration getDomConfig() {
 717         return document.getDomDocument().getDomConfig();
 718     }
 719 

 720     public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) throws DOMException {
 721         handleNewSource();
 722         return document.adoptNode(source);
 723     }
 724 

 725     public void setDocumentURI(String documentURI) {
 726         document.setDocumentURI(documentURI);
 727     }
 728 

 729     public String getDocumentURI() {
 730         return document.getDomDocument().getDocumentURI();
 731     }
 732 

 733     public void  setStrictErrorChecking(boolean strictErrorChecking) {
 734         document.setStrictErrorChecking(strictErrorChecking);
 735     }
 736 

 737     public String getInputEncoding() {
 738         return document.getDomDocument().getInputEncoding();
 739     }
 740 

 741     public String getXmlEncoding() {
 742         return document.getDomDocument().getXmlEncoding();
 743     }
 744 

 745     public boolean getXmlStandalone() {
 746         return document.getDomDocument().getXmlStandalone();
 747     }
 748 

 749     public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
 750         document.setXmlStandalone(xmlStandalone);
 751     }
 752 

 753     public String getXmlVersion() {
 754         return document.getDomDocument().getXmlVersion();
 755     }
 756 

 757     public void setXmlVersion(String xmlVersion) throws DOMException {
 758         document.setXmlVersion(xmlVersion);
 759     }
 760 

 761     public boolean  getStrictErrorChecking() {
 762         return document.getDomDocument().getStrictErrorChecking();
 763     }
 764 
 765     // DOM L3 methods from org.w3c.dom.Node

 766     public String getBaseURI() {
 767         return document.getDomDocument().getBaseURI();
 768     }
 769 

 770     public short compareDocumentPosition(org.w3c.dom.Node other)
 771                               throws DOMException {
 772         return document.compareDocumentPosition(other);
 773     }
 774 

 775     public String getTextContent()
 776                       throws DOMException {
 777         return document.getTextContent();
 778     }
 779 

 780     public void setTextContent(String textContent) throws DOMException {
 781          document.setTextContent(textContent);
 782     }
 783 

 784     public boolean isSameNode(org.w3c.dom.Node other) {
 785         return document.isSameNode(other);
 786     }
 787 

 788     public String lookupPrefix(String namespaceURI) {
 789         return document.getDomDocument().lookupPrefix(namespaceURI);
 790     }
 791 

 792     public boolean isDefaultNamespace(String namespaceURI) {
 793         return document.isDefaultNamespace(namespaceURI);
 794     }
 795 

 796     public String lookupNamespaceURI(String prefix) {
 797         return document.lookupNamespaceURI(prefix);
 798     }
 799 

 800     public boolean isEqualNode(org.w3c.dom.Node arg) {
 801         return document.getDomDocument().isEqualNode(arg);
 802     }
 803 

 804     public Object getFeature(String feature,
 805                   String version) {
 806         return  document.getFeature(feature,version);
 807     }
 808 

 809     public Object setUserData(String key,
 810                    Object data,
 811                   UserDataHandler handler) {
 812         return document.setUserData(key, data, handler);
 813     }
 814 

 815     public Object getUserData(String key) {
 816         return document.getDomDocument().getUserData(key);
 817     }
 818 

 819     public void recycleNode() {
 820         // Nothing seems to be required to be done here
 821     }
 822 

 823     public String getValue() {
 824         return null;
 825     }
 826 

 827     public void setValue(String value) {
 828         log.severe("SAAJ0571.soappart.setValue.not.defined");
 829         throw new IllegalStateException("Setting value of a soap part is not defined");
 830     }
 831 

 832     public void setParentElement(SOAPElement parent) throws SOAPException {
 833         log.severe("SAAJ0570.soappart.parent.element.not.defined");
 834         throw new SOAPExceptionImpl("The parent element of a soap part is not defined");
 835     }
 836 

 837     public SOAPElement getParentElement() {
 838         return null;
 839     }
 840 

 841     public void detachNode() {
 842         // Nothing seems to be required to be done here
 843     }
 844 
 845     public String getSourceCharsetEncoding() {
 846         return sourceCharsetEncoding;
 847     }
 848 
 849     public abstract String getSOAPNamespace();
 850 }


  58 import javax.activation.DataSource;
  59 import javax.xml.soap.MimeHeaders;
  60 import javax.xml.soap.SOAPElement;
  61 import javax.xml.soap.SOAPEnvelope;
  62 import javax.xml.soap.SOAPException;
  63 import javax.xml.soap.SOAPPart;
  64 import javax.xml.transform.Source;
  65 import javax.xml.transform.dom.DOMSource;
  66 import javax.xml.transform.sax.SAXSource;
  67 import javax.xml.transform.stream.StreamSource;
  68 import java.io.IOException;
  69 import java.io.InputStream;
  70 import java.io.InputStreamReader;
  71 import java.io.OutputStream;
  72 import java.io.PushbackReader;
  73 import java.io.Reader;
  74 import java.io.UnsupportedEncodingException;
  75 import java.util.Iterator;
  76 import java.util.logging.Level;
  77 import java.util.logging.Logger;
  78 import javax.xml.soap.MimeHeader;
  79 
  80 /**
  81  * SOAPPartImpl is the first attachment. This contains the XML/SOAP document.
  82  *
  83  * @author Anil Vijendran (anil@sun.com)
  84  */
  85 public abstract class SOAPPartImpl extends SOAPPart implements SOAPDocument {
  86     protected static final Logger log =
  87         Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
  88                          "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
  89 
  90     protected MimeHeaders headers;
  91     protected Envelope envelope;
  92     protected Source source;
  93     protected SOAPDocumentImpl document;
  94 
  95     //flag to indicate if a setContent happened.
  96     private boolean sourceWasSet = false;
  97 
  98     // Records whether the input source had an xml decl or not.


 120         headers = new MimeHeaders();
 121         this.message = message;
 122         headers.setHeader("Content-Type", getContentType());
 123     }
 124 
 125     protected abstract String getContentType();
 126     protected abstract Envelope createEnvelopeFromSource()
 127     throws SOAPException;
 128     protected abstract Envelope createEmptyEnvelope(String prefix)
 129     throws SOAPException;
 130     protected abstract SOAPPartImpl duplicateType();
 131 
 132     protected String getContentTypeString() {
 133         return getContentType();
 134     }
 135 
 136     public boolean isFastInfoset() {
 137         return (message != null) ? message.isFastInfoset() : false;
 138     }
 139 
 140     @Override
 141     public SOAPEnvelope getEnvelope() throws SOAPException {
 142 
 143         // If there is no SOAP envelope already created, then create
 144         // one from a source if one exists. If there is a newer source
 145         // then use that source.
 146 
 147         if (sourceWasSet)
 148               sourceWasSet = false;
 149 
 150         lookForEnvelope();
 151         if (envelope != null) {
 152             if (source != null) { // there's a newer source, use it
 153                 document.removeChild(envelope);
 154                 envelope = createEnvelopeFromSource();
 155             }
 156         } else if (source != null) {
 157             envelope = createEnvelopeFromSource();
 158         } else {
 159             envelope = createEmptyEnvelope(null);
 160             document.insertBefore(((EnvelopeImpl) envelope).getDomElement(), null);


 170         } else if (document.find(envelopeChildElement) == null) {
 171             log.severe("SAAJ0512.soap.incorrect.factory.used");
 172             throw new SOAPExceptionImpl("Unable to create envelope: incorrect factory used during tree construction");
 173         } else {
 174             ElementImpl soapElement = (ElementImpl) document.find(envelopeChildElement);
 175             if (soapElement.getLocalName().equalsIgnoreCase("Envelope")) {
 176                 String prefix = soapElement.getPrefix();
 177                 String uri = (prefix == null) ? soapElement.getNamespaceURI() : soapElement.getNamespaceURI(prefix);
 178                 if(!uri.equals(NameImpl.SOAP11_NAMESPACE) && !uri.equals(NameImpl.SOAP12_NAMESPACE)) {
 179                     log.severe("SAAJ0513.soap.unknown.ns");
 180                     throw new SOAPVersionMismatchException("Unable to create envelope from given source because the namespace was not recognized");
 181                 }
 182             } else {
 183                 log.severe("SAAJ0514.soap.root.elem.not.named.envelope");
 184                 throw new SOAPExceptionImpl(
 185                     "Unable to create envelope from given source because the root element is not named \"Envelope\"");
 186             }
 187         }
 188     }
 189 
 190     @Override
 191     public void removeAllMimeHeaders() {
 192         headers.removeAllHeaders();
 193     }
 194 
 195     @Override
 196     public void removeMimeHeader(String header) {
 197         headers.removeHeader(header);
 198     }
 199 
 200     @Override
 201     public String[] getMimeHeader(String name) {
 202         return headers.getHeader(name);
 203     }
 204 
 205     @Override
 206     public void setMimeHeader(String name, String value) {
 207         headers.setHeader(name, value);
 208     }
 209 
 210     @Override
 211     public void addMimeHeader(String name, String value) {
 212         headers.addHeader(name, value);
 213     }
 214 
 215     @Override
 216     public Iterator<MimeHeader> getAllMimeHeaders() {
 217         return headers.getAllHeaders();
 218     }
 219 
 220     @Override
 221     public Iterator<MimeHeader> getMatchingMimeHeaders(String[] names) {
 222         return headers.getMatchingHeaders(names);
 223     }
 224 
 225     @Override
 226     public Iterator<MimeHeader> getNonMatchingMimeHeaders(String[] names) {
 227         return headers.getNonMatchingHeaders(names);
 228     }
 229 
 230     @Override
 231     public Source getContent() throws SOAPException {
 232         if (source != null) {
 233             InputStream bis = null;
 234             if (source instanceof JAXMStreamSource) {
 235                 StreamSource streamSource = (StreamSource)source;
 236                 bis = streamSource.getInputStream();
 237             } else if (FastInfosetReflection.isFastInfosetSource(source)) {
 238                 // FastInfosetSource inherits from SAXSource
 239                 SAXSource saxSource = (SAXSource)source;
 240                 bis = saxSource.getInputSource().getByteStream();
 241             }
 242 
 243             if (bis != null) {
 244                 try {
 245                     bis.reset();
 246                 } catch (IOException e) {
 247                     /* This exception will never be thrown.
 248                      *
 249                      * The setContent method will modify the source
 250                      * if StreamSource to JAXMStreamSource, that uses
 251                      * a ByteInputStream, and for a FastInfosetSource will
 252                      * replace the InputStream with a ByteInputStream.
 253                      */
 254                 }
 255             }
 256             return source;
 257         }
 258 
 259         return ((Envelope) getEnvelope()).getContent();
 260     }
 261 
 262     @Override
 263     public void setContent(Source source) throws SOAPException {
 264         try {
 265             if (source instanceof StreamSource) {
 266                 InputStream is = ((StreamSource) source).getInputStream();
 267                 Reader rdr = ((StreamSource) source).getReader();
 268 
 269                 if (is != null) {
 270                     this.source = new JAXMStreamSource(is);
 271                 } else if (rdr != null) {
 272                     this.source = new JAXMStreamSource(rdr);
 273                 } else {
 274                     log.severe("SAAJ0544.soap.no.valid.reader.for.src");
 275                     throw new SOAPExceptionImpl("Source does not have a valid Reader or InputStream");
 276                 }
 277             }
 278             else if (FastInfosetReflection.isFastInfosetSource(source)) {
 279                 // InputStream is = source.getInputStream()
 280                 InputStream is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
 281 
 282                 /*


 371             MimeBodyPart headerEnvelope = new MimeBodyPart();
 372 
 373             headerEnvelope.setDataHandler(getDataHandler());
 374             AttachmentPartImpl.copyMimeHeaders(headers, headerEnvelope);
 375 
 376             return headerEnvelope;
 377         } catch (SOAPException ex) {
 378             throw ex;
 379         } catch (Exception ex) {
 380             log.severe("SAAJ0548.soap.cannot.externalize.hdr");
 381             throw new SOAPExceptionImpl("Unable to externalize header", ex);
 382         }
 383     }
 384 
 385     MimeHeaders getMimeHeaders() {
 386         return headers;
 387     }
 388 
 389     DataHandler getDataHandler() {
 390         DataSource ds = new DataSource() {
 391             @Override
 392             public OutputStream getOutputStream() throws IOException {
 393                 throw new IOException("Illegal Operation");
 394             }
 395 
 396             @Override
 397             public String getContentType() {
 398                 return getContentTypeString();
 399             }
 400 
 401             @Override
 402             public String getName() {
 403                 return getContentId();
 404             }
 405 
 406             @Override
 407             public InputStream getInputStream() throws IOException {
 408                 return getContentAsStream();
 409             }
 410         };
 411         return new DataHandler(ds);
 412     }
 413 
 414     @Override
 415     public SOAPDocumentImpl getDocument() {
 416         handleNewSource();
 417         return document;
 418     }
 419 
 420     @Override
 421     public SOAPPartImpl getSOAPPart() {
 422         return this;
 423     }
 424 
 425     @Override
 426     public DocumentType getDoctype() {
 427         return document.getDoctype();
 428     }
 429 
 430     // Forward all of these calls to the document to ensure that they work the
 431     // same way whether they are called from here or directly from the document.
 432     // If the document needs any help from this SOAPPart then
 433     // Make it use a call-back as in doGetDocumentElement() below
 434     @Override
 435     public DOMImplementation getImplementation() {
 436         return document.getImplementation();
 437     }
 438 
 439     @Override
 440     public Element getDocumentElement() {
 441         // If there is no SOAP envelope already created, then create
 442         // one from a source if one exists. If there is a newer source
 443         // then use that source.
 444         try {
 445             getEnvelope();
 446         } catch (SOAPException e) {
 447         }
 448         return document.getDocumentElement();
 449     }
 450 
 451     protected void doGetDocumentElement() {
 452         handleNewSource();
 453         try {
 454             lookForEnvelope();
 455         } catch (SOAPException e) {
 456         }
 457     }
 458 
 459     @Override
 460     public Element createElement(String tagName) throws DOMException {
 461         return document.createElement(tagName);
 462     }
 463 
 464     @Override
 465     public DocumentFragment createDocumentFragment() {
 466         return document.createDocumentFragment();
 467     }
 468 
 469     @Override
 470     public org.w3c.dom.Text createTextNode(String data) {
 471         return document.createTextNode(data);
 472     }
 473 
 474     @Override
 475     public Comment createComment(String data) {
 476         return document.createComment(data);
 477     }
 478 
 479     @Override
 480     public CDATASection createCDATASection(String data) throws DOMException {
 481         return document.createCDATASection(data);
 482     }
 483 
 484     @Override
 485     public ProcessingInstruction createProcessingInstruction(
 486     String target,
 487     String data)
 488     throws DOMException {
 489         return document.createProcessingInstruction(target, data);
 490     }
 491 
 492     @Override
 493     public Attr createAttribute(String name) throws DOMException {
 494         return document.createAttribute(name);
 495     }
 496 
 497     @Override
 498     public EntityReference createEntityReference(String name)
 499     throws DOMException {
 500         return document.createEntityReference(name);
 501     }
 502 
 503     @Override
 504     public NodeList getElementsByTagName(String tagname) {
 505         handleNewSource();
 506         return document.getElementsByTagName(tagname);
 507     }
 508 
 509     @Override
 510     public org.w3c.dom.Node importNode(
 511         org.w3c.dom.Node importedNode,
 512         boolean deep)
 513         throws DOMException {
 514         handleNewSource();
 515         return document.importNode(importedNode, deep);
 516     }
 517 
 518     @Override
 519     public Element createElementNS(String namespaceURI, String qualifiedName)
 520     throws DOMException {
 521         return document.createElementNS(namespaceURI, qualifiedName);
 522     }
 523 
 524     @Override
 525     public Attr createAttributeNS(String namespaceURI, String qualifiedName)
 526     throws DOMException {
 527         return document.createAttributeNS(namespaceURI, qualifiedName);
 528     }
 529 
 530     @Override
 531     public NodeList getElementsByTagNameNS(
 532         String namespaceURI,
 533         String localName) {
 534         handleNewSource();
 535         return document.getElementsByTagNameNS(namespaceURI, localName);
 536     }
 537 
 538     @Override
 539     public Element getElementById(String elementId) {
 540         handleNewSource();
 541         return document.getElementById(elementId);
 542     }
 543     @Override
 544     public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
 545         throws DOMException {
 546         handleNewSource();
 547         return document.appendChild(newChild);
 548     }
 549 
 550     @Override
 551     public org.w3c.dom.Node cloneNode(boolean deep) {
 552         handleNewSource();
 553         return document.cloneNode(deep);
 554     }
 555 
 556     protected SOAPPartImpl doCloneNode() {
 557         handleNewSource();
 558         SOAPPartImpl newSoapPart = duplicateType();
 559 
 560         newSoapPart.headers = MimeHeadersUtil.copy(this.headers);
 561         newSoapPart.source = this.source;
 562         return newSoapPart;
 563     }
 564 
 565     @Override
 566     public NamedNodeMap getAttributes() {
 567         return document.getDomDocument().getAttributes();
 568     }
 569 
 570     @Override
 571     public NodeList getChildNodes() {
 572         handleNewSource();
 573         return document.getChildNodes();
 574     }
 575 
 576     @Override
 577     public org.w3c.dom.Node getFirstChild() {
 578         handleNewSource();
 579         return document.getFirstChild();
 580     }
 581 
 582     @Override
 583     public org.w3c.dom.Node getLastChild() {
 584         handleNewSource();
 585         return document.getLastChild();
 586     }
 587 
 588     @Override
 589     public String getLocalName() {
 590         return document.getDomDocument().getLocalName();
 591     }
 592 
 593     @Override
 594     public String getNamespaceURI() {
 595         return document.getDomDocument().getNamespaceURI();
 596     }
 597 
 598     @Override
 599     public org.w3c.dom.Node getNextSibling() {
 600         handleNewSource();
 601         return document.getNextSibling();
 602     }
 603 
 604     @Override
 605     public String getNodeName() {
 606         return document.getDomDocument().getNodeName();
 607     }
 608 
 609     @Override
 610     public short getNodeType() {
 611         return document.getDomDocument().getNodeType();
 612     }
 613 
 614     @Override
 615     public String getNodeValue() throws DOMException {
 616         return document.getNodeValue();
 617     }
 618 
 619     @Override
 620     public Document getOwnerDocument() {
 621         return document.getDomDocument().getOwnerDocument();
 622     }
 623 
 624     @Override
 625     public org.w3c.dom.Node getParentNode() {
 626         return document.getDomDocument().getParentNode();
 627     }
 628 
 629     @Override
 630     public String getPrefix() {
 631         return document.getDomDocument().getPrefix();
 632     }
 633 
 634     @Override
 635     public org.w3c.dom.Node getPreviousSibling() {
 636         return document.getDomDocument().getPreviousSibling();
 637     }
 638 
 639     @Override
 640     public boolean hasAttributes() {
 641         return document.getDomDocument().hasAttributes();
 642     }
 643 
 644     @Override
 645     public boolean hasChildNodes() {
 646         handleNewSource();
 647         return document.hasChildNodes();
 648     }
 649 
 650     @Override
 651     public org.w3c.dom.Node insertBefore(
 652         org.w3c.dom.Node arg0,
 653         org.w3c.dom.Node arg1)
 654         throws DOMException {
 655         handleNewSource();
 656         return document.insertBefore(arg0, arg1);
 657     }
 658 
 659     @Override
 660     public boolean isSupported(String arg0, String arg1) {
 661         return document.getDomDocument().isSupported(arg0, arg1);
 662     }
 663 
 664     @Override
 665     public void normalize() {
 666         handleNewSource();
 667         document.normalize();
 668     }
 669 
 670     @Override
 671     public org.w3c.dom.Node removeChild(org.w3c.dom.Node arg0)
 672         throws DOMException {
 673         handleNewSource();
 674         return document.removeChild(arg0);
 675     }
 676 
 677     @Override
 678     public org.w3c.dom.Node replaceChild(
 679         org.w3c.dom.Node arg0,
 680         org.w3c.dom.Node arg1)
 681         throws DOMException {
 682         handleNewSource();
 683         return document.replaceChild(arg0, arg1);
 684     }
 685 
 686     @Override
 687     public void setNodeValue(String arg0) throws DOMException {
 688         document.setNodeValue(arg0);
 689     }
 690 
 691     @Override
 692     public void setPrefix(String arg0) throws DOMException {
 693         document.setPrefix(arg0);
 694     }
 695 
 696     private void handleNewSource() {
 697         if (sourceWasSet) {
 698          // There is a newer source use that source.
 699          try {
 700              getEnvelope();
 701          } catch (SOAPException e) {
 702          }
 703       }
 704     }
 705 
 706     protected XMLDeclarationParser lookForXmlDecl() throws SOAPException {
 707         if ((source != null) && (source instanceof StreamSource)) {
 708 
 709             Reader reader = null;
 710 
 711             InputStream inputStream = ((StreamSource) source).getInputStream();


 746                 }
 747                 String xmlDecl = ev.getXmlDeclaration();
 748                 if ((xmlDecl != null) && (xmlDecl.length() > 0)) {
 749                     this.omitXmlDecl = false;
 750                 }
 751                 if (lazyContentLength) {
 752                     source = new StreamSource(pushbackReader);
 753                 }
 754                 return ev;
 755             }
 756         } else if ((source != null) && (source instanceof DOMSource)) {
 757            //TODO: A Domsource maynot contain XMLDecl ?.
 758         }
 759         return null;
 760     }
 761 
 762     public void setSourceCharsetEncoding(String charset) {
 763         this.sourceCharsetEncoding = charset;
 764     }
 765 
 766     @Override
 767     public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName)
 768         throws DOMException {
 769         handleNewSource();
 770         return document.renameNode(n, namespaceURI, qualifiedName);
 771     }
 772 
 773     @Override
 774     public void normalizeDocument() {
 775         document.normalizeDocument();
 776     }
 777 
 778     @Override
 779     public DOMConfiguration getDomConfig() {
 780         return document.getDomDocument().getDomConfig();
 781     }
 782 
 783     @Override
 784     public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) throws DOMException {
 785         handleNewSource();
 786         return document.adoptNode(source);
 787     }
 788 
 789     @Override
 790     public void setDocumentURI(String documentURI) {
 791         document.setDocumentURI(documentURI);
 792     }
 793 
 794     @Override
 795     public String getDocumentURI() {
 796         return document.getDomDocument().getDocumentURI();
 797     }
 798 
 799     @Override
 800     public void  setStrictErrorChecking(boolean strictErrorChecking) {
 801         document.setStrictErrorChecking(strictErrorChecking);
 802     }
 803 
 804     @Override
 805     public String getInputEncoding() {
 806         return document.getDomDocument().getInputEncoding();
 807     }
 808 
 809     @Override
 810     public String getXmlEncoding() {
 811         return document.getDomDocument().getXmlEncoding();
 812     }
 813 
 814     @Override
 815     public boolean getXmlStandalone() {
 816         return document.getDomDocument().getXmlStandalone();
 817     }
 818 
 819     @Override
 820     public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
 821         document.setXmlStandalone(xmlStandalone);
 822     }
 823 
 824     @Override
 825     public String getXmlVersion() {
 826         return document.getDomDocument().getXmlVersion();
 827     }
 828 
 829     @Override
 830     public void setXmlVersion(String xmlVersion) throws DOMException {
 831         document.setXmlVersion(xmlVersion);
 832     }
 833 
 834     @Override
 835     public boolean  getStrictErrorChecking() {
 836         return document.getDomDocument().getStrictErrorChecking();
 837     }
 838 
 839     // DOM L3 methods from org.w3c.dom.Node
 840     @Override
 841     public String getBaseURI() {
 842         return document.getDomDocument().getBaseURI();
 843     }
 844 
 845     @Override
 846     public short compareDocumentPosition(org.w3c.dom.Node other)
 847                               throws DOMException {
 848         return document.compareDocumentPosition(other);
 849     }
 850 
 851     @Override
 852     public String getTextContent()
 853                       throws DOMException {
 854         return document.getTextContent();
 855     }
 856 
 857     @Override
 858     public void setTextContent(String textContent) throws DOMException {
 859          document.setTextContent(textContent);
 860     }
 861 
 862     @Override
 863     public boolean isSameNode(org.w3c.dom.Node other) {
 864         return document.isSameNode(other);
 865     }
 866 
 867     @Override
 868     public String lookupPrefix(String namespaceURI) {
 869         return document.getDomDocument().lookupPrefix(namespaceURI);
 870     }
 871 
 872     @Override
 873     public boolean isDefaultNamespace(String namespaceURI) {
 874         return document.isDefaultNamespace(namespaceURI);
 875     }
 876 
 877     @Override
 878     public String lookupNamespaceURI(String prefix) {
 879         return document.lookupNamespaceURI(prefix);
 880     }
 881 
 882     @Override
 883     public boolean isEqualNode(org.w3c.dom.Node arg) {
 884         return document.getDomDocument().isEqualNode(arg);
 885     }
 886 
 887     @Override
 888     public Object getFeature(String feature,
 889                   String version) {
 890         return  document.getFeature(feature,version);
 891     }
 892 
 893     @Override
 894     public Object setUserData(String key,
 895                    Object data,
 896                   UserDataHandler handler) {
 897         return document.setUserData(key, data, handler);
 898     }
 899 
 900     @Override
 901     public Object getUserData(String key) {
 902         return document.getDomDocument().getUserData(key);
 903     }
 904 
 905     @Override
 906     public void recycleNode() {
 907         // Nothing seems to be required to be done here
 908     }
 909 
 910     @Override
 911     public String getValue() {
 912         return null;
 913     }
 914 
 915     @Override
 916     public void setValue(String value) {
 917         log.severe("SAAJ0571.soappart.setValue.not.defined");
 918         throw new IllegalStateException("Setting value of a soap part is not defined");
 919     }
 920 
 921     @Override
 922     public void setParentElement(SOAPElement parent) throws SOAPException {
 923         log.severe("SAAJ0570.soappart.parent.element.not.defined");
 924         throw new SOAPExceptionImpl("The parent element of a soap part is not defined");
 925     }
 926 
 927     @Override
 928     public SOAPElement getParentElement() {
 929         return null;
 930     }
 931 
 932     @Override
 933     public void detachNode() {
 934         // Nothing seems to be required to be done here
 935     }
 936 
 937     public String getSourceCharsetEncoding() {
 938         return sourceCharsetEncoding;
 939     }
 940 
 941     public abstract String getSOAPNamespace();
 942 }
< prev index next >