src/share/jaxws_classes/com/sun/xml/internal/ws/message/saaj/SAAJMessage.java

changeset 397
b99d7e355d4b
parent 368
0989ad8c0860
child 637
9c07ef4934dd
     1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/message/saaj/SAAJMessage.java	Thu Aug 08 10:10:38 2013 -0700
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/message/saaj/SAAJMessage.java	Fri Aug 23 09:57:21 2013 +0100
     1.3 @@ -175,7 +175,7 @@
     1.4       */
     1.5      @Override
     1.6      public @NotNull AttachmentSet getAttachments() {
     1.7 -        parse();
     1.8 +        if (attachmentSet == null) attachmentSet = new SAAJAttachmentSet(sm);
     1.9          return attachmentSet;
    1.10      }
    1.11  
    1.12 @@ -185,23 +185,21 @@
    1.13       */
    1.14      @Override
    1.15      protected boolean hasAttachments() {
    1.16 -        parse();
    1.17 -        return attachmentSet!=null;
    1.18 +        return !getAttachments().isEmpty();
    1.19      }
    1.20  
    1.21      public @Nullable String getPayloadLocalPart() {
    1.22 -        access();
    1.23 +        soapBodyFirstChild();
    1.24          return payloadLocalName;
    1.25      }
    1.26  
    1.27      public String getPayloadNamespaceURI() {
    1.28 -        access();
    1.29 +        soapBodyFirstChild();
    1.30          return payloadNamespace;
    1.31      }
    1.32  
    1.33      public boolean hasPayload() {
    1.34 -        access();
    1.35 -        return payloadNamespace != null;
    1.36 +        return soapBodyFirstChild() != null;
    1.37      }
    1.38  
    1.39      private void addAttributes(Element e, NamedNodeMap attrs) {
    1.40 @@ -327,15 +325,7 @@
    1.41      }
    1.42  
    1.43      public XMLStreamReader readPayload() throws XMLStreamException {
    1.44 -        access();
    1.45 -        if (payload != null) {
    1.46 -            DOMStreamReader dss = new DOMStreamReader();
    1.47 -            dss.setCurrentNode(payload);
    1.48 -            dss.nextTag();
    1.49 -            assert dss.getEventType() == XMLStreamReader.START_ELEMENT;
    1.50 -            return dss;
    1.51 -        }
    1.52 -        return null;
    1.53 +        return soapBodyFirstChildReader();
    1.54      }
    1.55  
    1.56      public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
    1.57 @@ -522,7 +512,7 @@
    1.58      private static final AttributesImpl EMPTY_ATTS = new AttributesImpl();
    1.59      private static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
    1.60  
    1.61 -    private static class SAAJAttachment implements AttachmentEx {
    1.62 +    protected static class SAAJAttachment implements AttachmentEx {
    1.63  
    1.64          final AttachmentPart ap;
    1.65  
    1.66 @@ -651,7 +641,7 @@
    1.67       * SAAJ wants '<' and '>' for the content ID, but {@link AttachmentSet}
    1.68       * doesn't. S this class also does the conversion between them.
    1.69       */
    1.70 -    private static class SAAJAttachmentSet implements AttachmentSet {
    1.71 +    protected static class SAAJAttachmentSet implements AttachmentSet {
    1.72  
    1.73          private Map<String, Attachment> attMap;
    1.74          private Iterator attIter;
    1.75 @@ -715,4 +705,74 @@
    1.76      public SOAPVersion getSOAPVersion() {
    1.77          return soapVersion;
    1.78      }
    1.79 +
    1.80 +    private XMLStreamReader soapBodyFirstChildReader;
    1.81 +
    1.82 +    /**
    1.83 +     * This allow the subclass to retain the XMLStreamReader.
    1.84 +     */
    1.85 +    protected XMLStreamReader getXMLStreamReader(SOAPElement soapElement) {
    1.86 +        return null;
    1.87 +    }
    1.88 +
    1.89 +    protected XMLStreamReader createXMLStreamReader(SOAPElement soapElement) {
    1.90 +        DOMStreamReader dss = new DOMStreamReader();
    1.91 +        dss.setCurrentNode(soapElement);
    1.92 +        return dss;
    1.93 +    }
    1.94 +
    1.95 +    protected XMLStreamReader soapBodyFirstChildReader() {
    1.96 +        if (soapBodyFirstChildReader != null) return soapBodyFirstChildReader;
    1.97 +        soapBodyFirstChild();
    1.98 +        if (soapBodyFirstChild != null) {
    1.99 +            soapBodyFirstChildReader = getXMLStreamReader(soapBodyFirstChild);
   1.100 +            if (soapBodyFirstChildReader == null) soapBodyFirstChildReader =
   1.101 +                createXMLStreamReader(soapBodyFirstChild);
   1.102 +            if (soapBodyFirstChildReader.getEventType() == XMLStreamReader.START_DOCUMENT) {
   1.103 +                try {
   1.104 +                    while(soapBodyFirstChildReader.getEventType() != XMLStreamReader.START_ELEMENT)
   1.105 +                        soapBodyFirstChildReader.next();
   1.106 +                } catch (XMLStreamException e) {
   1.107 +                    throw new RuntimeException(e);
   1.108 +                }
   1.109 +            }
   1.110 +            return soapBodyFirstChildReader;
   1.111 +        } else {
   1.112 +            payloadLocalName = null;
   1.113 +            payloadNamespace = null;
   1.114 +            return null;
   1.115 +        }
   1.116 +    }
   1.117 +
   1.118 +    private SOAPElement soapBodyFirstChild;
   1.119 +
   1.120 +    SOAPElement soapBodyFirstChild() {
   1.121 +        if (soapBodyFirstChild != null) return soapBodyFirstChild;
   1.122 +        try {
   1.123 +            boolean foundElement = false;
   1.124 +            for (Node n = sm.getSOAPBody().getFirstChild(); n != null && !foundElement; n = n.getNextSibling()) {
   1.125 +                if (n.getNodeType() == Node.ELEMENT_NODE) {
   1.126 +                    foundElement = true;
   1.127 +                    if (n instanceof SOAPElement) {
   1.128 +                        soapBodyFirstChild = (SOAPElement) n;
   1.129 +                        payloadLocalName = soapBodyFirstChild.getLocalName();
   1.130 +                        payloadNamespace = soapBodyFirstChild.getNamespaceURI();
   1.131 +                        return soapBodyFirstChild;
   1.132 +                    }
   1.133 +                }
   1.134 +            }
   1.135 +            if(foundElement) for(Iterator i = sm.getSOAPBody().getChildElements(); i.hasNext();){
   1.136 +                Object o = i.next();
   1.137 +                if (o instanceof SOAPElement) {
   1.138 +                    soapBodyFirstChild = (SOAPElement)o;
   1.139 +                    payloadLocalName = soapBodyFirstChild.getLocalName();
   1.140 +                    payloadNamespace = soapBodyFirstChild.getNamespaceURI();
   1.141 +                    return soapBodyFirstChild;
   1.142 +                }
   1.143 +            }
   1.144 +        } catch (SOAPException e) {
   1.145 +            throw new RuntimeException(e);
   1.146 +        }
   1.147 +        return soapBodyFirstChild;
   1.148 +    }
   1.149  }

mercurial