1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.ws.message.stream;
  27 
  28 import com.sun.xml.internal.ws.api.SOAPVersion;
  29 import com.sun.xml.internal.ws.api.message.AttachmentSet;
  30 import com.sun.xml.internal.ws.api.message.Message;
  31 import com.sun.xml.internal.ws.api.message.MessageHeaders;
  32 import com.sun.xml.internal.ws.message.AbstractMessageImpl;
  33 import com.sun.xml.internal.ws.message.AttachmentSetImpl;
  34 import com.sun.istack.internal.Nullable;
  35 import com.sun.istack.internal.NotNull;
  36 import org.xml.sax.ContentHandler;
  37 import org.xml.sax.ErrorHandler;
  38 import org.xml.sax.SAXException;
  39 
  40 import javax.xml.bind.JAXBException;
  41 import javax.xml.bind.Unmarshaller;
  42 import javax.xml.stream.XMLStreamException;
  43 import javax.xml.stream.XMLStreamReader;
  44 import javax.xml.stream.XMLStreamWriter;
  45 import javax.xml.transform.Source;
  46 
  47 /**
  48  * {@link Message} backed by {@link XMLStreamReader} as payload
  49  *
  50  * @author Jitendra Kotamraju
  51  */
  52 public class PayloadStreamReaderMessage extends AbstractMessageImpl {
  53     private final StreamMessage message;
  54 
  55     public PayloadStreamReaderMessage(XMLStreamReader reader, SOAPVersion soapVer) {
  56         this(null, reader,new AttachmentSetImpl(), soapVer);
  57     }
  58 
  59     public PayloadStreamReaderMessage(@Nullable MessageHeaders headers, @NotNull XMLStreamReader reader,
  60                                       @NotNull AttachmentSet attSet, @NotNull SOAPVersion soapVersion) {
  61         super(soapVersion);
  62         message = new StreamMessage(headers, attSet, reader, soapVersion);
  63     }
  64 
  65     public boolean hasHeaders() {
  66         return message.hasHeaders();
  67     }
  68 
  69     public AttachmentSet getAttachments() {
  70         return message.getAttachments();
  71     }
  72 
  73     public String getPayloadLocalPart() {
  74         return message.getPayloadLocalPart();
  75     }
  76 
  77     public String getPayloadNamespaceURI() {
  78         return message.getPayloadNamespaceURI();
  79     }
  80 
  81     public boolean hasPayload() {
  82         return true;
  83     }
  84 
  85     public Source readPayloadAsSource() {
  86         return message.readPayloadAsSource();
  87     }
  88 
  89     public XMLStreamReader readPayload() throws XMLStreamException {
  90         return message.readPayload();
  91     }
  92 
  93     public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
  94         message.writePayloadTo(sw);
  95     }
  96 
  97     public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
  98         return (T) message.readPayloadAsJAXB(unmarshaller);
  99     }
 100 
 101     public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
 102         message.writeTo(contentHandler, errorHandler);
 103     }
 104 
 105     protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
 106         message.writePayloadTo(contentHandler, errorHandler, fragment);
 107     }
 108 
 109     public Message copy() {
 110         return message.copy().copyFrom(message);
 111     }
 112 
 113     @Override
 114     public @NotNull MessageHeaders getHeaders() {
 115         return message.getHeaders();
 116     }
 117 }