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

changeset 397
b99d7e355d4b
parent 368
0989ad8c0860
child 637
9c07ef4934dd
equal deleted inserted replaced
393:6cdc6ed98780 397:b99d7e355d4b
173 * Gets the attachments of this message 173 * Gets the attachments of this message
174 * (attachments live outside a message.) 174 * (attachments live outside a message.)
175 */ 175 */
176 @Override 176 @Override
177 public @NotNull AttachmentSet getAttachments() { 177 public @NotNull AttachmentSet getAttachments() {
178 parse(); 178 if (attachmentSet == null) attachmentSet = new SAAJAttachmentSet(sm);
179 return attachmentSet; 179 return attachmentSet;
180 } 180 }
181 181
182 /** 182 /**
183 * Optimization hint for the derived class to check 183 * Optimization hint for the derived class to check
184 * if we may have some attachments. 184 * if we may have some attachments.
185 */ 185 */
186 @Override 186 @Override
187 protected boolean hasAttachments() { 187 protected boolean hasAttachments() {
188 parse(); 188 return !getAttachments().isEmpty();
189 return attachmentSet!=null;
190 } 189 }
191 190
192 public @Nullable String getPayloadLocalPart() { 191 public @Nullable String getPayloadLocalPart() {
193 access(); 192 soapBodyFirstChild();
194 return payloadLocalName; 193 return payloadLocalName;
195 } 194 }
196 195
197 public String getPayloadNamespaceURI() { 196 public String getPayloadNamespaceURI() {
198 access(); 197 soapBodyFirstChild();
199 return payloadNamespace; 198 return payloadNamespace;
200 } 199 }
201 200
202 public boolean hasPayload() { 201 public boolean hasPayload() {
203 access(); 202 return soapBodyFirstChild() != null;
204 return payloadNamespace != null;
205 } 203 }
206 204
207 private void addAttributes(Element e, NamedNodeMap attrs) { 205 private void addAttributes(Element e, NamedNodeMap attrs) {
208 if(attrs == null) 206 if(attrs == null)
209 return; 207 return;
325 return bridge.unmarshal(payload,hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null); 323 return bridge.unmarshal(payload,hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null);
326 return null; 324 return null;
327 } 325 }
328 326
329 public XMLStreamReader readPayload() throws XMLStreamException { 327 public XMLStreamReader readPayload() throws XMLStreamException {
330 access(); 328 return soapBodyFirstChildReader();
331 if (payload != null) {
332 DOMStreamReader dss = new DOMStreamReader();
333 dss.setCurrentNode(payload);
334 dss.nextTag();
335 assert dss.getEventType() == XMLStreamReader.START_ELEMENT;
336 return dss;
337 }
338 return null;
339 } 329 }
340 330
341 public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException { 331 public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
342 access(); 332 access();
343 try { 333 try {
520 } 510 }
521 } 511 }
522 private static final AttributesImpl EMPTY_ATTS = new AttributesImpl(); 512 private static final AttributesImpl EMPTY_ATTS = new AttributesImpl();
523 private static final LocatorImpl NULL_LOCATOR = new LocatorImpl(); 513 private static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
524 514
525 private static class SAAJAttachment implements AttachmentEx { 515 protected static class SAAJAttachment implements AttachmentEx {
526 516
527 final AttachmentPart ap; 517 final AttachmentPart ap;
528 518
529 String contentIdNoAngleBracket; 519 String contentIdNoAngleBracket;
530 520
649 * {@link AttachmentSet} for SAAJ. 639 * {@link AttachmentSet} for SAAJ.
650 * 640 *
651 * SAAJ wants '<' and '>' for the content ID, but {@link AttachmentSet} 641 * SAAJ wants '<' and '>' for the content ID, but {@link AttachmentSet}
652 * doesn't. S this class also does the conversion between them. 642 * doesn't. S this class also does the conversion between them.
653 */ 643 */
654 private static class SAAJAttachmentSet implements AttachmentSet { 644 protected static class SAAJAttachmentSet implements AttachmentSet {
655 645
656 private Map<String, Attachment> attMap; 646 private Map<String, Attachment> attMap;
657 private Iterator attIter; 647 private Iterator attIter;
658 648
659 public SAAJAttachmentSet(SOAPMessage sm) { 649 public SAAJAttachmentSet(SOAPMessage sm) {
713 } 703 }
714 704
715 public SOAPVersion getSOAPVersion() { 705 public SOAPVersion getSOAPVersion() {
716 return soapVersion; 706 return soapVersion;
717 } 707 }
708
709 private XMLStreamReader soapBodyFirstChildReader;
710
711 /**
712 * This allow the subclass to retain the XMLStreamReader.
713 */
714 protected XMLStreamReader getXMLStreamReader(SOAPElement soapElement) {
715 return null;
716 }
717
718 protected XMLStreamReader createXMLStreamReader(SOAPElement soapElement) {
719 DOMStreamReader dss = new DOMStreamReader();
720 dss.setCurrentNode(soapElement);
721 return dss;
722 }
723
724 protected XMLStreamReader soapBodyFirstChildReader() {
725 if (soapBodyFirstChildReader != null) return soapBodyFirstChildReader;
726 soapBodyFirstChild();
727 if (soapBodyFirstChild != null) {
728 soapBodyFirstChildReader = getXMLStreamReader(soapBodyFirstChild);
729 if (soapBodyFirstChildReader == null) soapBodyFirstChildReader =
730 createXMLStreamReader(soapBodyFirstChild);
731 if (soapBodyFirstChildReader.getEventType() == XMLStreamReader.START_DOCUMENT) {
732 try {
733 while(soapBodyFirstChildReader.getEventType() != XMLStreamReader.START_ELEMENT)
734 soapBodyFirstChildReader.next();
735 } catch (XMLStreamException e) {
736 throw new RuntimeException(e);
737 }
738 }
739 return soapBodyFirstChildReader;
740 } else {
741 payloadLocalName = null;
742 payloadNamespace = null;
743 return null;
744 }
745 }
746
747 private SOAPElement soapBodyFirstChild;
748
749 SOAPElement soapBodyFirstChild() {
750 if (soapBodyFirstChild != null) return soapBodyFirstChild;
751 try {
752 boolean foundElement = false;
753 for (Node n = sm.getSOAPBody().getFirstChild(); n != null && !foundElement; n = n.getNextSibling()) {
754 if (n.getNodeType() == Node.ELEMENT_NODE) {
755 foundElement = true;
756 if (n instanceof SOAPElement) {
757 soapBodyFirstChild = (SOAPElement) n;
758 payloadLocalName = soapBodyFirstChild.getLocalName();
759 payloadNamespace = soapBodyFirstChild.getNamespaceURI();
760 return soapBodyFirstChild;
761 }
762 }
763 }
764 if(foundElement) for(Iterator i = sm.getSOAPBody().getChildElements(); i.hasNext();){
765 Object o = i.next();
766 if (o instanceof SOAPElement) {
767 soapBodyFirstChild = (SOAPElement)o;
768 payloadLocalName = soapBodyFirstChild.getLocalName();
769 payloadNamespace = soapBodyFirstChild.getNamespaceURI();
770 return soapBodyFirstChild;
771 }
772 }
773 } catch (SOAPException e) {
774 throw new RuntimeException(e);
775 }
776 return soapBodyFirstChild;
777 }
718 } 778 }

mercurial