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.source;
038:
039: import com.sun.xml.bind.api.Bridge;
040: import com.sun.xml.ws.api.SOAPVersion;
041: import com.sun.xml.ws.api.pipe.Codecs;
042: import com.sun.xml.ws.api.pipe.StreamSOAPCodec;
043: import com.sun.xml.ws.api.message.HeaderList;
044: import com.sun.xml.ws.api.message.Message;
045: import com.sun.xml.ws.api.message.Packet;
046: import com.sun.xml.ws.streaming.SourceReaderFactory;
047: import javax.xml.bind.JAXBException;
048: import javax.xml.bind.Unmarshaller;
049: import javax.xml.soap.SOAPException;
050: import javax.xml.soap.SOAPMessage;
051: import org.xml.sax.ContentHandler;
052: import org.xml.sax.ErrorHandler;
053: import org.xml.sax.SAXException;
054:
055: import javax.xml.stream.XMLStreamException;
056: import javax.xml.stream.XMLStreamReader;
057: import javax.xml.stream.XMLStreamWriter;
058: import javax.xml.transform.Source;
059:
060: /**
061: * Implementation of {@link Message} backed by {@link Source} where the Source
062: * represents the complete message such as a SOAP envelope. It uses
063: * {@link StreamSOAPCodec} to create a {@link Message} and uses it as a
064: * delegate for all the methods.
065: *
066: * @author Vivek Pandey
067: * @author Jitendra Kotamraju
068: */
069: public class ProtocolSourceMessage extends Message {
070: private final Message sm;
071:
072: public ProtocolSourceMessage(Source source, SOAPVersion soapVersion) {
073: XMLStreamReader reader = SourceReaderFactory
074: .createSourceReader(source, true);
075: com.sun.xml.ws.api.pipe.StreamSOAPCodec codec = Codecs
076: .createSOAPEnvelopeXmlCodec(soapVersion);
077: sm = codec.decode(reader);
078: }
079:
080: public boolean hasHeaders() {
081: return sm.hasHeaders();
082: }
083:
084: public HeaderList getHeaders() {
085: return sm.getHeaders();
086: }
087:
088: public String getPayloadLocalPart() {
089: return sm.getPayloadLocalPart();
090: }
091:
092: public String getPayloadNamespaceURI() {
093: return sm.getPayloadNamespaceURI();
094: }
095:
096: public boolean hasPayload() {
097: return sm.hasPayload();
098: }
099:
100: public Source readPayloadAsSource() {
101: return sm.readPayloadAsSource();
102: }
103:
104: public XMLStreamReader readPayload() throws XMLStreamException {
105: return sm.readPayload();
106: }
107:
108: public void writePayloadTo(XMLStreamWriter sw)
109: throws XMLStreamException {
110: sm.writePayloadTo(sw);
111: }
112:
113: public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
114: sm.writeTo(sw);
115: }
116:
117: public Message copy() {
118: return sm.copy();
119: }
120:
121: public Source readEnvelopeAsSource() {
122: return sm.readEnvelopeAsSource();
123: }
124:
125: public SOAPMessage readAsSOAPMessage() throws SOAPException {
126: return sm.readAsSOAPMessage();
127: }
128:
129: public SOAPMessage readAsSOAPMessage(Packet packet, boolean inbound)
130: throws SOAPException {
131: return sm.readAsSOAPMessage(packet, inbound);
132: }
133:
134: public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller)
135: throws JAXBException {
136: return (T) sm.readPayloadAsJAXB(unmarshaller);
137: }
138:
139: public <T> T readPayloadAsJAXB(Bridge<T> bridge)
140: throws JAXBException {
141: return sm.readPayloadAsJAXB(bridge);
142: }
143:
144: public void writeTo(ContentHandler contentHandler,
145: ErrorHandler errorHandler) throws SAXException {
146: sm.writeTo(contentHandler, errorHandler);
147: }
148: }
|