001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.message.stream;
038:
039: import com.sun.xml.ws.api.SOAPVersion;
040: import com.sun.xml.ws.api.message.AttachmentSet;
041: import com.sun.xml.ws.api.message.HeaderList;
042: import com.sun.xml.ws.api.message.Message;
043: import com.sun.xml.ws.message.AbstractMessageImpl;
044: import com.sun.xml.ws.message.AttachmentSetImpl;
045: import com.sun.istack.Nullable;
046: import com.sun.istack.NotNull;
047: import org.xml.sax.ContentHandler;
048: import org.xml.sax.ErrorHandler;
049: import org.xml.sax.SAXException;
050:
051: import javax.xml.bind.JAXBException;
052: import javax.xml.bind.Unmarshaller;
053: import javax.xml.stream.XMLStreamException;
054: import javax.xml.stream.XMLStreamReader;
055: import javax.xml.stream.XMLStreamWriter;
056: import javax.xml.transform.Source;
057:
058: /**
059: * {@link Message} backed by {@link XMLStreamReader} as payload
060: *
061: * @author Jitendra Kotamraju
062: */
063: public class PayloadStreamReaderMessage extends AbstractMessageImpl {
064: private final StreamMessage message;
065:
066: public PayloadStreamReaderMessage(XMLStreamReader reader,
067: SOAPVersion soapVer) {
068: this (null, reader, new AttachmentSetImpl(), soapVer);
069: }
070:
071: public PayloadStreamReaderMessage(@Nullable
072: HeaderList headers, @NotNull
073: XMLStreamReader reader, @NotNull
074: AttachmentSet attSet, @NotNull
075: SOAPVersion soapVersion) {
076: super (soapVersion);
077: message = new StreamMessage(headers, attSet, reader,
078: soapVersion);
079: }
080:
081: public boolean hasHeaders() {
082: return message.hasHeaders();
083: }
084:
085: public HeaderList getHeaders() {
086: return message.getHeaders();
087: }
088:
089: public AttachmentSet getAttachments() {
090: return message.getAttachments();
091: }
092:
093: public String getPayloadLocalPart() {
094: return message.getPayloadLocalPart();
095: }
096:
097: public String getPayloadNamespaceURI() {
098: return message.getPayloadNamespaceURI();
099: }
100:
101: public boolean hasPayload() {
102: return true;
103: }
104:
105: public Source readPayloadAsSource() {
106: return message.readPayloadAsSource();
107: }
108:
109: public XMLStreamReader readPayload() throws XMLStreamException {
110: return message.readPayload();
111: }
112:
113: public void writePayloadTo(XMLStreamWriter sw)
114: throws XMLStreamException {
115: message.writePayloadTo(sw);
116: }
117:
118: public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller)
119: throws JAXBException {
120: return (T) message.readPayloadAsJAXB(unmarshaller);
121: }
122:
123: public void writeTo(ContentHandler contentHandler,
124: ErrorHandler errorHandler) throws SAXException {
125: message.writeTo(contentHandler, errorHandler);
126: }
127:
128: protected void writePayloadTo(ContentHandler contentHandler,
129: ErrorHandler errorHandler, boolean fragment)
130: throws SAXException {
131: message.writePayloadTo(contentHandler, errorHandler, fragment);
132: }
133:
134: public Message copy() {
135: return message.copy();
136: }
137: }
|