View Javadoc
1   /*
2    * Copyright (c) 1997, 2013, 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.api.message;
27  
28  import javax.xml.bind.JAXBException;
29  import javax.xml.bind.Unmarshaller;
30  import javax.xml.namespace.QName;
31  import javax.xml.soap.SOAPException;
32  import javax.xml.soap.SOAPMessage;
33  import javax.xml.stream.XMLStreamException;
34  import javax.xml.stream.XMLStreamReader;
35  import javax.xml.stream.XMLStreamWriter;
36  import javax.xml.transform.Source;
37  
38  import org.xml.sax.ContentHandler;
39  import org.xml.sax.ErrorHandler;
40  import org.xml.sax.SAXException;
41  
42  import com.sun.istack.internal.NotNull;
43  import com.sun.xml.internal.bind.api.Bridge;
44  import com.sun.xml.internal.ws.api.SOAPVersion;
45  import com.sun.xml.internal.ws.api.WSBinding;
46  import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
47  import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
48  import com.sun.xml.internal.ws.message.saaj.SAAJMessage;
49  import com.sun.xml.internal.ws.message.stream.StreamMessage;
50  import com.sun.xml.internal.ws.spi.db.XMLBridge;
51  
52  /**
53   * A <code>MessageWrapper</code> wraps the Message for the access through Packet.
54   *
55   * @author shih-chang.chen@oracle.com
56   */
57  class MessageWrapper extends StreamMessage {
58  
59      Packet packet;
60      Message delegate;
61      StreamMessage streamDelegate;
62  
63      @Override
64      public void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
65          streamDelegate.writePayloadTo(contentHandler, errorHandler, fragment);
66      }
67  
68      @Override
69      public String getBodyPrologue() {
70          return streamDelegate.getBodyPrologue();
71      }
72  
73      @Override
74      public String getBodyEpilogue() {
75          return streamDelegate.getBodyEpilogue();
76      }
77  
78      MessageWrapper(Packet p, Message m) {
79          super(m.getSOAPVersion());
80          packet = p;
81          delegate = m;
82          streamDelegate = (m instanceof StreamMessage) ? (StreamMessage) m : null;
83          setMessageMedadata(p);
84      }
85  
86      @Override
87      public int hashCode() {
88          return delegate.hashCode();
89      }
90  
91      @Override
92      public boolean equals(Object obj) {
93          return delegate.equals(obj);
94      }
95  
96      @Override
97      public boolean hasHeaders() {
98          return delegate.hasHeaders();
99      }
100 
101     @Override
102     public AttachmentSet getAttachments() {
103         return delegate.getAttachments();
104     }
105 
106     @Override
107     public String toString() {
108         return delegate.toString();
109     }
110 
111     @Override
112     public boolean isOneWay(WSDLPort port) {
113         return delegate.isOneWay(port);
114     }
115 
116     @Override
117     public String getPayloadLocalPart() {
118         return delegate.getPayloadLocalPart();
119     }
120 
121     @Override
122     public String getPayloadNamespaceURI() {
123         return delegate.getPayloadNamespaceURI();
124     }
125 
126     @Override
127     public boolean hasPayload() {
128         return delegate.hasPayload();
129     }
130 
131     @Override
132     public boolean isFault() {
133         return delegate.isFault();
134     }
135 
136     @Override
137     public QName getFirstDetailEntryName() {
138         return delegate.getFirstDetailEntryName();
139     }
140 
141     @Override
142     public Source readEnvelopeAsSource() {
143         //TODO if (delegate instanceof SAAJMessage)
144         return delegate.readEnvelopeAsSource();
145     }
146 
147     @Override
148     public Source readPayloadAsSource() {
149         //TODO if (delegate instanceof SAAJMessage)
150         return delegate.readPayloadAsSource();
151     }
152 
153     @Override
154     public SOAPMessage readAsSOAPMessage() throws SOAPException {
155         if (!(delegate instanceof SAAJMessage)) {
156             delegate = toSAAJ(packet, null);
157         }
158         return delegate.readAsSOAPMessage();
159     }
160 
161     @Override
162     public SOAPMessage readAsSOAPMessage(Packet p, boolean inbound) throws SOAPException {
163         if (!(delegate instanceof SAAJMessage)) {
164             delegate = toSAAJ(p, inbound);
165         }
166         return delegate.readAsSOAPMessage();
167     }
168 
169     @Override
170     public Object readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
171         return delegate.readPayloadAsJAXB(unmarshaller);
172     }
173 
174     @Override
175     public <T> T readPayloadAsJAXB(Bridge<T> bridge) throws JAXBException {
176         return delegate.readPayloadAsJAXB(bridge);
177     }
178 
179     @Override
180     public <T> T readPayloadAsJAXB(XMLBridge<T> bridge) throws JAXBException {
181         return delegate.readPayloadAsJAXB(bridge);
182     }
183 
184     @Override
185     public XMLStreamReader readPayload() {
186         try {
187             return delegate.readPayload();
188         } catch (XMLStreamException e) {
189             e.printStackTrace();
190         }
191         return null;
192     }
193 
194     @Override
195     public void consume() {
196         delegate.consume();
197     }
198 
199     @Override
200     public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
201         delegate.writePayloadTo(sw);
202     }
203 
204     @Override
205     public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
206         delegate.writeTo(sw);
207     }
208 
209     @Override
210     public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler)
211             throws SAXException {
212         delegate.writeTo(contentHandler, errorHandler);
213     }
214 
215     @Override
216     public Message copy() {
217         return delegate.copy();
218     }
219 
220     @Override
221     public String getID(WSBinding binding) {
222         return delegate.getID(binding);
223     }
224 
225     @Override
226     public String getID(AddressingVersion av, SOAPVersion sv) {
227         return delegate.getID(av, sv);
228     }
229 
230     @Override
231     public SOAPVersion getSOAPVersion() {
232         return delegate.getSOAPVersion();
233     }
234 
235     @Override
236     public @NotNull MessageHeaders getHeaders() {
237         return delegate.getHeaders();
238     }
239 
240     @Override
241     public void setMessageMedadata(MessageMetadata metadata) {
242         super.setMessageMedadata(metadata);
243         delegate.setMessageMedadata(metadata);
244     }
245 }