src/share/jaxws_classes/com/sun/xml/internal/ws/message/stream/StreamMessage.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 384
8f2986ff0235
     1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/message/stream/StreamMessage.java	Thu Apr 04 19:05:24 2013 -0700
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/message/stream/StreamMessage.java	Tue Apr 09 14:51:13 2013 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -36,6 +36,7 @@
    1.11  import com.sun.xml.internal.ws.api.message.Header;
    1.12  import com.sun.xml.internal.ws.api.message.HeaderList;
    1.13  import com.sun.xml.internal.ws.api.message.Message;
    1.14 +import com.sun.xml.internal.ws.api.message.MessageHeaders;
    1.15  import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
    1.16  import com.sun.xml.internal.ws.encoding.TagInfoset;
    1.17  import com.sun.xml.internal.ws.message.AbstractMessageImpl;
    1.18 @@ -69,7 +70,7 @@
    1.19   * TODO: we need another message class that keeps {@link XMLStreamReader} that points
    1.20   * at the start of the envelope element.
    1.21   */
    1.22 -public final class StreamMessage extends AbstractMessageImpl {
    1.23 +public class StreamMessage extends AbstractMessageImpl {
    1.24      /**
    1.25       * The reader will be positioned at
    1.26       * the first child of the SOAP body
    1.27 @@ -77,7 +78,7 @@
    1.28      private @NotNull XMLStreamReader reader;
    1.29  
    1.30      // lazily created
    1.31 -    private @Nullable HeaderList headers;
    1.32 +    private @Nullable MessageHeaders headers;
    1.33  
    1.34      /**
    1.35       * Because the StreamMessage leaves out the white spaces around payload
    1.36 @@ -123,12 +124,17 @@
    1.37          create(SOAPVersion.SOAP_12);
    1.38      }
    1.39  
    1.40 +    public StreamMessage(SOAPVersion v) {
    1.41 +        super(v);
    1.42 +        payloadLocalName = null;
    1.43 +        payloadNamespaceURI = null;
    1.44 +    }
    1.45      /**
    1.46       * Creates a {@link StreamMessage} from a {@link XMLStreamReader}
    1.47       * that points at the start element of the payload, and headers.
    1.48       *
    1.49       * <p>
    1.50 -     * This method creaets a {@link Message} from a payload.
    1.51 +     * This method creates a {@link Message} from a payload.
    1.52       *
    1.53       * @param headers
    1.54       *      if null, it means no headers. if non-null,
    1.55 @@ -137,7 +143,7 @@
    1.56       *      points at the start element/document of the payload (or the end element of the &lt;s:Body>
    1.57       *      if there's no payload)
    1.58       */
    1.59 -    public StreamMessage(@Nullable HeaderList headers, @NotNull AttachmentSet attachmentSet, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
    1.60 +    public StreamMessage(@Nullable MessageHeaders headers, @NotNull AttachmentSet attachmentSet, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
    1.61          super(soapVersion);
    1.62          this.headers = headers;
    1.63          this.attachmentSet = attachmentSet;
    1.64 @@ -177,18 +183,18 @@
    1.65       * and the complete infoset of the SOAP envelope.
    1.66       *
    1.67       * <p>
    1.68 -     * See {@link #StreamMessage(HeaderList, AttachmentSet, XMLStreamReader, SOAPVersion)} for
    1.69 +     * See {@link #StreamMessage(MessageHeaders, AttachmentSet, XMLStreamReader, SOAPVersion)} for
    1.70       * the description of the basic parameters.
    1.71       *
    1.72       * @param headerTag
    1.73       *      Null if the message didn't have a header tag.
    1.74       *
    1.75       */
    1.76 -    public StreamMessage(@NotNull TagInfoset envelopeTag, @Nullable TagInfoset headerTag, @NotNull AttachmentSet attachmentSet, @Nullable HeaderList headers, @NotNull TagInfoset bodyTag, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
    1.77 +    public StreamMessage(@NotNull TagInfoset envelopeTag, @Nullable TagInfoset headerTag, @NotNull AttachmentSet attachmentSet, @Nullable MessageHeaders headers, @NotNull TagInfoset bodyTag, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
    1.78          this(envelopeTag, headerTag, attachmentSet, headers, null, bodyTag, null, reader, soapVersion);
    1.79      }
    1.80  
    1.81 -    public StreamMessage(@NotNull TagInfoset envelopeTag, @Nullable TagInfoset headerTag, @NotNull AttachmentSet attachmentSet, @Nullable HeaderList headers, @Nullable String bodyPrologue, @NotNull TagInfoset bodyTag, @Nullable String bodyEpilogue, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
    1.82 +    public StreamMessage(@NotNull TagInfoset envelopeTag, @Nullable TagInfoset headerTag, @NotNull AttachmentSet attachmentSet, @Nullable MessageHeaders headers, @Nullable String bodyPrologue, @NotNull TagInfoset bodyTag, @Nullable String bodyEpilogue, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
    1.83          this(headers,attachmentSet,reader,soapVersion);
    1.84          if(envelopeTag == null ) {
    1.85              throw new IllegalArgumentException("EnvelopeTag TagInfoset cannot be null");
    1.86 @@ -205,12 +211,12 @@
    1.87      }
    1.88  
    1.89      public boolean hasHeaders() {
    1.90 -        return headers!=null && !headers.isEmpty();
    1.91 +        return headers!=null && headers.hasHeaders();
    1.92      }
    1.93  
    1.94 -    public HeaderList getHeaders() {
    1.95 +    public MessageHeaders getHeaders() {
    1.96          if (headers == null) {
    1.97 -            headers = new HeaderList();
    1.98 +            headers = new HeaderList(getSOAPVersion());
    1.99          }
   1.100          return headers;
   1.101      }
   1.102 @@ -384,10 +390,10 @@
   1.103          envelopeTag.writeStart(writer);
   1.104  
   1.105          //write headers
   1.106 -        HeaderList hl = getHeaders();
   1.107 -        if(hl.size() > 0){
   1.108 +        MessageHeaders hl = getHeaders();
   1.109 +        if(hl.hasHeaders()){
   1.110              headerTag.writeStart(writer);
   1.111 -            for(Header h:hl){
   1.112 +            for(Header h : hl.asList()){
   1.113                  h.writeTo(writer);
   1.114              }
   1.115              writer.writeEndElement();
   1.116 @@ -523,11 +529,10 @@
   1.117          envelopeTag.writeStart(contentHandler);
   1.118          headerTag.writeStart(contentHandler);
   1.119          if(hasHeaders()) {
   1.120 -            HeaderList headers = getHeaders();
   1.121 -            int len = headers.size();
   1.122 -            for( int i=0; i<len; i++ ) {
   1.123 +            MessageHeaders headers = getHeaders();
   1.124 +            for (Header h : headers.asList()) {
   1.125                  // shouldn't JDK be smart enough to use array-style indexing for this foreach!?
   1.126 -                headers.get(i).writeTo(contentHandler,errorHandler);
   1.127 +                h.writeTo(contentHandler,errorHandler);
   1.128              }
   1.129          }
   1.130          headerTag.writeEnd(contentHandler);
   1.131 @@ -573,4 +578,8 @@
   1.132          return bodyEpilogue;
   1.133      }
   1.134  
   1.135 +    public XMLStreamReader getReader() {
   1.136 +        assert unconsumed();
   1.137 +        return reader;
   1.138 +    }
   1.139  }

mercurial