/**
   * Creates a {@link StreamMessage} from a {@link XMLStreamReader} that points at the start element
   * of the payload, and headers.
   *
   * <p>This method creaets a {@link Message} from a payload.
   *
   * @param headers if null, it means no headers. if non-null, it will be owned by this message.
   * @param reader points at the start element/document of the payload (or the end element of the
   *     &lt;s:Body> if there's no payload)
   */
  public VerifiedStreamMessage(
      @Nullable HeaderList headers,
      @NotNull AttachmentSet attachmentSet,
      @NotNull XMLStreamReader reader,
      @NotNull SOAPVersion soapVersion,
      Map<String, String> bodyEnvNs) {
    super(soapVersion);
    this.headers = headers;
    this.attachmentSet = attachmentSet;
    this.reader = reader;
    this.bodyEnvNs = bodyEnvNs;

    if (reader.getEventType() == START_DOCUMENT) {
      XMLStreamReaderUtil.nextElementContent(reader);
    }

    // if the reader is pointing to the end element </soapenv:Body> then its empty message
    // or no payload
    if (reader.getEventType() == XMLStreamConstants.END_ELEMENT) {
      String body = reader.getLocalName();
      String nsUri = reader.getNamespaceURI();
      assert body != null;
      assert nsUri != null;
      // if its not soapenv:Body then throw exception, we received malformed stream
      if (body.equals("Body") && nsUri.equals(soapVersion.nsUri)) {
        this.payloadLocalName = null;
        this.payloadNamespaceURI = null;
      } else { // TODO: i18n and also we should be throwing better message that this
        throw new WebServiceException("Malformed stream: {" + nsUri + "}" + body);
      }
    } else {
      this.payloadLocalName = reader.getLocalName();
      this.payloadNamespaceURI = reader.getNamespaceURI();
    }

    // use the default infoset representation for headers
    int base = soapVersion.ordinal() * 3;
    this.envelopeTag = DEFAULT_TAGS[base];
    this.headerTag = DEFAULT_TAGS[base + 1];
    this.bodyTag = DEFAULT_TAGS[base + 2];
  }
 private static void create(SOAPVersion v) {
   int base = v.ordinal() * 3;
   DEFAULT_TAGS[base] = new TagInfoset(v.nsUri, "Envelope", "S", EMPTY_ATTS, "S", v.nsUri);
   DEFAULT_TAGS[base + 1] = new TagInfoset(v.nsUri, "Header", "S", EMPTY_ATTS);
   DEFAULT_TAGS[base + 2] = new TagInfoset(v.nsUri, "Body", "S", EMPTY_ATTS);
 }