author | tbell |
Mon, 04 May 2009 21:10:41 -0700 | |
changeset 2719 | 99d59312294b |
parent 2678 | 57cf2a1c1a05 |
child 3530 | 18fb7507984b |
permissions | -rw-r--r-- |
8 | 1 |
/* |
2678
57cf2a1c1a05
6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents:
8
diff
changeset
|
2 |
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
8 | 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
2678
57cf2a1c1a05
6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents:
8
diff
changeset
|
25 |
/* |
2719 | 26 |
* |
27 |
* |
|
28 |
* |
|
2678
57cf2a1c1a05
6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents:
8
diff
changeset
|
29 |
*/ |
57cf2a1c1a05
6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents:
8
diff
changeset
|
30 |
|
57cf2a1c1a05
6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents:
8
diff
changeset
|
31 |
|
8 | 32 |
package com.sun.xml.internal.messaging.saaj.soap; |
33 |
||
34 |
import java.io.*; |
|
35 |
import java.util.Iterator; |
|
36 |
import java.util.logging.Logger; |
|
37 |
import java.util.logging.Level; |
|
38 |
||
39 |
import javax.activation.DataHandler; |
|
40 |
import javax.activation.DataSource; |
|
41 |
import javax.xml.soap.*; |
|
42 |
import javax.xml.transform.Source; |
|
43 |
import javax.xml.transform.stream.StreamSource; |
|
44 |
||
45 |
import org.w3c.dom.*; |
|
46 |
||
47 |
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart; |
|
48 |
||
49 |
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; |
|
50 |
import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl; |
|
51 |
import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl; |
|
52 |
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; |
|
53 |
import com.sun.xml.internal.messaging.saaj.util.*; |
|
54 |
import javax.xml.transform.sax.SAXSource; |
|
55 |
||
56 |
/** |
|
57 |
* SOAPPartImpl is the first attachment. This contains the XML/SOAP document. |
|
58 |
* |
|
59 |
* @author Anil Vijendran (anil@sun.com) |
|
60 |
*/ |
|
61 |
public abstract class SOAPPartImpl extends SOAPPart implements SOAPDocument { |
|
2719 | 62 |
protected static final Logger log = |
8 | 63 |
Logger.getLogger(LogDomainConstants.SOAP_DOMAIN, |
64 |
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings"); |
|
65 |
||
66 |
protected MimeHeaders headers; |
|
67 |
protected Envelope envelope; |
|
68 |
protected Source source; |
|
69 |
protected SOAPDocumentImpl document; |
|
70 |
||
71 |
//flag to indicate if a setContent happened. |
|
72 |
private boolean sourceWasSet = false; |
|
73 |
||
74 |
// Records whether the input source had an xml decl or not. |
|
75 |
protected boolean omitXmlDecl = true; |
|
76 |
||
77 |
// Records the charset encoding of the input stream source if provided. |
|
78 |
protected String sourceCharsetEncoding = null; |
|
79 |
||
80 |
/** |
|
81 |
* Reference to containing message (may be null) |
|
82 |
*/ |
|
83 |
protected MessageImpl message; |
|
84 |
||
85 |
protected SOAPPartImpl() { |
|
86 |
this(null); |
|
87 |
} |
|
88 |
||
89 |
protected SOAPPartImpl(MessageImpl message) { |
|
90 |
document = new SOAPDocumentImpl(this); |
|
91 |
headers = new MimeHeaders(); |
|
92 |
this.message = message; |
|
93 |
headers.setHeader("Content-Type", getContentType()); |
|
94 |
} |
|
95 |
||
96 |
protected abstract String getContentType(); |
|
97 |
protected abstract Envelope createEnvelopeFromSource() |
|
98 |
throws SOAPException; |
|
99 |
protected abstract Envelope createEmptyEnvelope(String prefix) |
|
100 |
throws SOAPException; |
|
101 |
protected abstract SOAPPartImpl duplicateType(); |
|
102 |
||
103 |
protected String getContentTypeString() { |
|
104 |
return getContentType(); |
|
105 |
} |
|
106 |
||
107 |
public boolean isFastInfoset() { |
|
108 |
return (message != null) ? message.isFastInfoset() : false; |
|
109 |
} |
|
110 |
||
111 |
public SOAPEnvelope getEnvelope() throws SOAPException { |
|
112 |
||
113 |
// If there is no SOAP envelope already created, then create |
|
114 |
// one from a source if one exists. If there is a newer source |
|
115 |
// then use that source. |
|
116 |
||
117 |
if (sourceWasSet) |
|
118 |
sourceWasSet = false; |
|
119 |
||
120 |
lookForEnvelope(); |
|
121 |
if (envelope != null) { |
|
122 |
if (source != null) { // there's a newer source, use it |
|
123 |
document.removeChild(envelope); |
|
124 |
envelope = createEnvelopeFromSource(); |
|
125 |
} |
|
126 |
} else if (source != null) { |
|
127 |
envelope = createEnvelopeFromSource(); |
|
128 |
} else { |
|
129 |
envelope = createEmptyEnvelope(null); |
|
130 |
document.insertBefore(envelope, null); |
|
131 |
} |
|
132 |
return envelope; |
|
133 |
} |
|
134 |
||
135 |
protected void lookForEnvelope() throws SOAPException { |
|
136 |
Element envelopeChildElement = document.doGetDocumentElement(); |
|
137 |
if (envelopeChildElement == null || envelopeChildElement instanceof Envelope) { |
|
138 |
envelope = (EnvelopeImpl) envelopeChildElement; |
|
139 |
} else if (!(envelopeChildElement instanceof ElementImpl)) { |
|
140 |
log.severe("SAAJ0512.soap.incorrect.factory.used"); |
|
141 |
throw new SOAPExceptionImpl("Unable to create envelope: incorrect factory used during tree construction"); |
|
142 |
} else { |
|
143 |
ElementImpl soapElement = (ElementImpl) envelopeChildElement; |
|
144 |
if (soapElement.getLocalName().equalsIgnoreCase("Envelope")) { |
|
145 |
String prefix = soapElement.getPrefix(); |
|
146 |
String uri = (prefix == null) ? soapElement.getNamespaceURI() : soapElement.getNamespaceURI(prefix); |
|
147 |
if(!uri.equals(NameImpl.SOAP11_NAMESPACE) && !uri.equals(NameImpl.SOAP12_NAMESPACE)) { |
|
148 |
log.severe("SAAJ0513.soap.unknown.ns"); |
|
149 |
throw new SOAPVersionMismatchException("Unable to create envelope from given source because the namespace was not recognized"); |
|
150 |
} |
|
151 |
} else { |
|
152 |
log.severe("SAAJ0514.soap.root.elem.not.named.envelope"); |
|
153 |
throw new SOAPExceptionImpl( |
|
154 |
"Unable to create envelope from given source because the root element is not named \"Envelope\""); |
|
155 |
} |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
public void removeAllMimeHeaders() { |
|
160 |
headers.removeAllHeaders(); |
|
161 |
} |
|
162 |
||
163 |
public void removeMimeHeader(String header) { |
|
164 |
headers.removeHeader(header); |
|
165 |
} |
|
166 |
||
167 |
public String[] getMimeHeader(String name) { |
|
168 |
return headers.getHeader(name); |
|
169 |
} |
|
170 |
||
171 |
public void setMimeHeader(String name, String value) { |
|
172 |
headers.setHeader(name, value); |
|
173 |
} |
|
174 |
||
175 |
public void addMimeHeader(String name, String value) { |
|
176 |
headers.addHeader(name, value); |
|
177 |
} |
|
178 |
||
179 |
public Iterator getAllMimeHeaders() { |
|
180 |
return headers.getAllHeaders(); |
|
181 |
} |
|
182 |
||
183 |
public Iterator getMatchingMimeHeaders(String[] names) { |
|
184 |
return headers.getMatchingHeaders(names); |
|
185 |
} |
|
186 |
||
187 |
public Iterator getNonMatchingMimeHeaders(String[] names) { |
|
188 |
return headers.getNonMatchingHeaders(names); |
|
189 |
} |
|
190 |
||
191 |
public Source getContent() throws SOAPException { |
|
192 |
if (source != null) { |
|
193 |
InputStream bis = null; |
|
194 |
if (source instanceof JAXMStreamSource) { |
|
195 |
StreamSource streamSource = (StreamSource)source; |
|
196 |
bis = streamSource.getInputStream(); |
|
197 |
} else if (FastInfosetReflection.isFastInfosetSource(source)) { |
|
198 |
// FastInfosetSource inherits from SAXSource |
|
199 |
SAXSource saxSource = (SAXSource)source; |
|
200 |
bis = saxSource.getInputSource().getByteStream(); |
|
201 |
} |
|
202 |
||
203 |
if (bis != null) { |
|
204 |
try { |
|
205 |
bis.reset(); |
|
206 |
} catch (IOException e) { |
|
207 |
/* This exception will never be thrown. |
|
208 |
* |
|
209 |
* The setContent method will modify the source |
|
210 |
* if StreamSource to JAXMStreamSource, that uses |
|
211 |
* a ByteInputStream, and for a FastInfosetSource will |
|
212 |
* replace the InputStream with a ByteInputStream. |
|
213 |
*/ |
|
214 |
} |
|
215 |
} |
|
216 |
return source; |
|
217 |
} |
|
218 |
||
219 |
return ((Envelope) getEnvelope()).getContent(); |
|
220 |
} |
|
221 |
||
222 |
public void setContent(Source source) throws SOAPException { |
|
223 |
try { |
|
224 |
if (source instanceof StreamSource) { |
|
225 |
InputStream is = ((StreamSource) source).getInputStream(); |
|
226 |
Reader rdr = ((StreamSource) source).getReader(); |
|
227 |
||
228 |
if (is != null) { |
|
229 |
this.source = new JAXMStreamSource(is); |
|
230 |
} else if (rdr != null) { |
|
231 |
this.source = new JAXMStreamSource(rdr); |
|
232 |
} else { |
|
233 |
log.severe("SAAJ0544.soap.no.valid.reader.for.src"); |
|
234 |
throw new SOAPExceptionImpl("Source does not have a valid Reader or InputStream"); |
|
235 |
} |
|
236 |
} |
|
237 |
else if (FastInfosetReflection.isFastInfosetSource(source)) { |
|
238 |
// InputStream is = source.getInputStream() |
|
239 |
InputStream is = FastInfosetReflection.FastInfosetSource_getInputStream(source); |
|
240 |
||
241 |
/* |
|
242 |
* Underlying stream must be ByteInputStream for getContentAsStream(). We pay the |
|
243 |
* cost of copying the underlying bytes here to avoid multiple copies every time |
|
244 |
* getBytes() is called on a ByteInputStream. |
|
245 |
*/ |
|
246 |
if (!(is instanceof ByteInputStream)) { |
|
247 |
ByteOutputStream bout = new ByteOutputStream(); |
|
248 |
bout.write(is); |
|
249 |
||
250 |
// source.setInputStream(new ByteInputStream(...)) |
|
251 |
FastInfosetReflection.FastInfosetSource_setInputStream( |
|
252 |
source, bout.newInputStream()); |
|
253 |
} |
|
254 |
this.source = source; |
|
255 |
} |
|
256 |
else { |
|
257 |
this.source = source; |
|
258 |
} |
|
259 |
sourceWasSet = true; |
|
260 |
} |
|
261 |
catch (Exception ex) { |
|
262 |
ex.printStackTrace(); |
|
263 |
||
264 |
log.severe("SAAJ0545.soap.cannot.set.src.for.part"); |
|
265 |
throw new SOAPExceptionImpl( |
|
266 |
"Error setting the source for SOAPPart: " + ex.getMessage()); |
|
267 |
} |
|
268 |
} |
|
269 |
||
270 |
public ByteInputStream getContentAsStream() throws IOException { |
|
271 |
if (source != null) { |
|
272 |
InputStream is = null; |
|
273 |
||
274 |
// Allow message to be transcode if so requested |
|
275 |
if (source instanceof StreamSource && !isFastInfoset()) { |
|
276 |
is = ((StreamSource) source).getInputStream(); |
|
277 |
} |
|
278 |
else if (FastInfosetReflection.isFastInfosetSource(source) && |
|
279 |
isFastInfoset()) |
|
280 |
{ |
|
281 |
try { |
|
282 |
// InputStream is = source.getInputStream() |
|
283 |
is = FastInfosetReflection.FastInfosetSource_getInputStream(source); |
|
284 |
} |
|
285 |
catch (Exception e) { |
|
286 |
throw new IOException(e.toString()); |
|
287 |
} |
|
288 |
} |
|
289 |
||
290 |
if (is != null) { |
|
291 |
if (!(is instanceof ByteInputStream)) { |
|
292 |
log.severe("SAAJ0546.soap.stream.incorrect.type"); |
|
293 |
throw new IOException("Internal error: stream not of the right type"); |
|
294 |
} |
|
295 |
return (ByteInputStream) is; |
|
296 |
} |
|
297 |
// need to do something here for reader... |
|
298 |
// for now we'll see if we can fallback... |
|
299 |
} |
|
300 |
||
301 |
ByteOutputStream b = new ByteOutputStream(); |
|
302 |
||
303 |
Envelope env = null; |
|
304 |
||
305 |
try { |
|
306 |
env = (Envelope) getEnvelope(); |
|
307 |
env.output(b, isFastInfoset()); |
|
308 |
} |
|
309 |
catch (SOAPException soapException) { |
|
310 |
log.severe("SAAJ0547.soap.cannot.externalize"); |
|
311 |
throw new SOAPIOException( |
|
312 |
"SOAP exception while trying to externalize: ", |
|
313 |
soapException); |
|
314 |
} |
|
315 |
||
316 |
return b.newInputStream(); |
|
317 |
} |
|
318 |
||
319 |
MimeBodyPart getMimePart() throws SOAPException { |
|
320 |
try { |
|
321 |
MimeBodyPart headerEnvelope = new MimeBodyPart(); |
|
322 |
||
323 |
headerEnvelope.setDataHandler(getDataHandler()); |
|
324 |
AttachmentPartImpl.copyMimeHeaders(headers, headerEnvelope); |
|
325 |
||
326 |
return headerEnvelope; |
|
327 |
} catch (SOAPException ex) { |
|
328 |
throw ex; |
|
329 |
} catch (Exception ex) { |
|
330 |
log.severe("SAAJ0548.soap.cannot.externalize.hdr"); |
|
331 |
throw new SOAPExceptionImpl("Unable to externalize header", ex); |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
MimeHeaders getMimeHeaders() { |
|
336 |
return headers; |
|
337 |
} |
|
338 |
||
339 |
DataHandler getDataHandler() { |
|
340 |
DataSource ds = new DataSource() { |
|
341 |
public OutputStream getOutputStream() throws IOException { |
|
342 |
throw new IOException("Illegal Operation"); |
|
343 |
} |
|
344 |
||
345 |
public String getContentType() { |
|
346 |
return getContentTypeString(); |
|
347 |
} |
|
348 |
||
349 |
public String getName() { |
|
350 |
return getContentId(); |
|
351 |
} |
|
352 |
||
353 |
public InputStream getInputStream() throws IOException { |
|
354 |
return getContentAsStream(); |
|
355 |
} |
|
356 |
}; |
|
357 |
return new DataHandler(ds); |
|
358 |
} |
|
359 |
||
360 |
public SOAPDocumentImpl getDocument() { |
|
361 |
handleNewSource(); |
|
362 |
return document; |
|
363 |
} |
|
364 |
||
365 |
public SOAPPartImpl getSOAPPart() { |
|
366 |
return this; |
|
367 |
} |
|
368 |
||
369 |
public DocumentType getDoctype() { |
|
370 |
return document.getDoctype(); |
|
371 |
} |
|
372 |
||
373 |
// Forward all of these calls to the document to ensure that they work the |
|
374 |
// same way whether they are called from here or directly from the document. |
|
375 |
// If the document needs any help from this SOAPPart then |
|
376 |
// Make it use a call-back as in doGetDocumentElement() below |
|
377 |
public DOMImplementation getImplementation() { |
|
378 |
return document.getImplementation(); |
|
379 |
} |
|
380 |
||
381 |
public Element getDocumentElement() { |
|
382 |
// If there is no SOAP envelope already created, then create |
|
383 |
// one from a source if one exists. If there is a newer source |
|
384 |
// then use that source. |
|
385 |
try { |
|
386 |
getEnvelope(); |
|
387 |
} catch (SOAPException e) { |
|
388 |
} |
|
389 |
return document.getDocumentElement(); |
|
390 |
} |
|
391 |
||
392 |
protected void doGetDocumentElement() { |
|
393 |
handleNewSource(); |
|
394 |
try { |
|
395 |
lookForEnvelope(); |
|
396 |
} catch (SOAPException e) { |
|
397 |
} |
|
398 |
} |
|
399 |
||
400 |
public Element createElement(String tagName) throws DOMException { |
|
401 |
return document.createElement(tagName); |
|
402 |
} |
|
403 |
||
404 |
public DocumentFragment createDocumentFragment() { |
|
405 |
return document.createDocumentFragment(); |
|
406 |
} |
|
407 |
||
408 |
public org.w3c.dom.Text createTextNode(String data) { |
|
409 |
return document.createTextNode(data); |
|
410 |
} |
|
411 |
||
412 |
public Comment createComment(String data) { |
|
413 |
return document.createComment(data); |
|
414 |
} |
|
415 |
||
416 |
public CDATASection createCDATASection(String data) throws DOMException { |
|
417 |
return document.createCDATASection(data); |
|
418 |
} |
|
419 |
||
420 |
public ProcessingInstruction createProcessingInstruction( |
|
421 |
String target, |
|
422 |
String data) |
|
423 |
throws DOMException { |
|
424 |
return document.createProcessingInstruction(target, data); |
|
425 |
} |
|
426 |
||
427 |
public Attr createAttribute(String name) throws DOMException { |
|
428 |
return document.createAttribute(name); |
|
429 |
} |
|
430 |
||
431 |
public EntityReference createEntityReference(String name) |
|
432 |
throws DOMException { |
|
433 |
return document.createEntityReference(name); |
|
434 |
} |
|
435 |
||
436 |
public NodeList getElementsByTagName(String tagname) { |
|
437 |
handleNewSource(); |
|
438 |
return document.getElementsByTagName(tagname); |
|
439 |
} |
|
440 |
||
441 |
public org.w3c.dom.Node importNode( |
|
442 |
org.w3c.dom.Node importedNode, |
|
443 |
boolean deep) |
|
444 |
throws DOMException { |
|
445 |
handleNewSource(); |
|
446 |
return document.importNode(importedNode, deep); |
|
447 |
} |
|
448 |
||
449 |
public Element createElementNS(String namespaceURI, String qualifiedName) |
|
450 |
throws DOMException { |
|
451 |
return document.createElementNS(namespaceURI, qualifiedName); |
|
452 |
} |
|
453 |
||
454 |
public Attr createAttributeNS(String namespaceURI, String qualifiedName) |
|
455 |
throws DOMException { |
|
456 |
return document.createAttributeNS(namespaceURI, qualifiedName); |
|
457 |
} |
|
458 |
||
459 |
public NodeList getElementsByTagNameNS( |
|
460 |
String namespaceURI, |
|
461 |
String localName) { |
|
462 |
handleNewSource(); |
|
463 |
return document.getElementsByTagNameNS(namespaceURI, localName); |
|
464 |
} |
|
465 |
||
466 |
public Element getElementById(String elementId) { |
|
467 |
handleNewSource(); |
|
468 |
return document.getElementById(elementId); |
|
469 |
} |
|
470 |
public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) |
|
471 |
throws DOMException { |
|
472 |
handleNewSource(); |
|
473 |
return document.appendChild(newChild); |
|
474 |
} |
|
475 |
||
476 |
public org.w3c.dom.Node cloneNode(boolean deep) { |
|
477 |
handleNewSource(); |
|
478 |
return document.cloneNode(deep); |
|
479 |
} |
|
480 |
||
481 |
protected SOAPPartImpl doCloneNode() { |
|
482 |
handleNewSource(); |
|
483 |
SOAPPartImpl newSoapPart = duplicateType(); |
|
484 |
||
485 |
newSoapPart.headers = MimeHeadersUtil.copy(this.headers); |
|
486 |
newSoapPart.source = this.source; |
|
487 |
return newSoapPart; |
|
488 |
} |
|
489 |
||
490 |
public NamedNodeMap getAttributes() { |
|
491 |
return document.getAttributes(); |
|
492 |
} |
|
493 |
||
494 |
public NodeList getChildNodes() { |
|
495 |
handleNewSource(); |
|
496 |
return document.getChildNodes(); |
|
497 |
} |
|
498 |
||
499 |
public org.w3c.dom.Node getFirstChild() { |
|
500 |
handleNewSource(); |
|
501 |
return document.getFirstChild(); |
|
502 |
} |
|
503 |
||
504 |
public org.w3c.dom.Node getLastChild() { |
|
505 |
handleNewSource(); |
|
506 |
return document.getLastChild(); |
|
507 |
} |
|
508 |
||
509 |
public String getLocalName() { |
|
510 |
return document.getLocalName(); |
|
511 |
} |
|
512 |
||
513 |
public String getNamespaceURI() { |
|
514 |
return document.getNamespaceURI(); |
|
515 |
} |
|
516 |
||
517 |
public org.w3c.dom.Node getNextSibling() { |
|
518 |
handleNewSource(); |
|
519 |
return document.getNextSibling(); |
|
520 |
} |
|
521 |
||
522 |
public String getNodeName() { |
|
523 |
return document.getNodeName(); |
|
524 |
} |
|
525 |
||
526 |
public short getNodeType() { |
|
527 |
return document.getNodeType(); |
|
528 |
} |
|
529 |
||
530 |
public String getNodeValue() throws DOMException { |
|
531 |
return document.getNodeValue(); |
|
532 |
} |
|
533 |
||
534 |
public Document getOwnerDocument() { |
|
535 |
return document.getOwnerDocument(); |
|
536 |
} |
|
537 |
||
538 |
public org.w3c.dom.Node getParentNode() { |
|
539 |
return document.getParentNode(); |
|
540 |
} |
|
541 |
||
542 |
public String getPrefix() { |
|
543 |
return document.getPrefix(); |
|
544 |
} |
|
545 |
||
546 |
public org.w3c.dom.Node getPreviousSibling() { |
|
547 |
return document.getPreviousSibling(); |
|
548 |
} |
|
549 |
||
550 |
public boolean hasAttributes() { |
|
551 |
return document.hasAttributes(); |
|
552 |
} |
|
553 |
||
554 |
public boolean hasChildNodes() { |
|
555 |
handleNewSource(); |
|
556 |
return document.hasChildNodes(); |
|
557 |
} |
|
558 |
||
559 |
public org.w3c.dom.Node insertBefore( |
|
560 |
org.w3c.dom.Node arg0, |
|
561 |
org.w3c.dom.Node arg1) |
|
562 |
throws DOMException { |
|
563 |
handleNewSource(); |
|
564 |
return document.insertBefore(arg0, arg1); |
|
565 |
} |
|
566 |
||
567 |
public boolean isSupported(String arg0, String arg1) { |
|
568 |
return document.isSupported(arg0, arg1); |
|
569 |
} |
|
570 |
||
571 |
public void normalize() { |
|
572 |
handleNewSource(); |
|
573 |
document.normalize(); |
|
574 |
} |
|
575 |
||
576 |
public org.w3c.dom.Node removeChild(org.w3c.dom.Node arg0) |
|
577 |
throws DOMException { |
|
578 |
handleNewSource(); |
|
579 |
return document.removeChild(arg0); |
|
580 |
} |
|
581 |
||
582 |
public org.w3c.dom.Node replaceChild( |
|
583 |
org.w3c.dom.Node arg0, |
|
584 |
org.w3c.dom.Node arg1) |
|
585 |
throws DOMException { |
|
586 |
handleNewSource(); |
|
587 |
return document.replaceChild(arg0, arg1); |
|
588 |
} |
|
589 |
||
590 |
public void setNodeValue(String arg0) throws DOMException { |
|
591 |
document.setNodeValue(arg0); |
|
592 |
} |
|
593 |
||
594 |
public void setPrefix(String arg0) throws DOMException { |
|
595 |
document.setPrefix(arg0); |
|
596 |
} |
|
597 |
||
598 |
private void handleNewSource() { |
|
599 |
if (sourceWasSet) { |
|
600 |
// There is a newer source use that source. |
|
601 |
try { |
|
602 |
getEnvelope(); |
|
603 |
} catch (SOAPException e) { |
|
604 |
} |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
protected XMLDeclarationParser lookForXmlDecl() throws SOAPException { |
|
609 |
if ((source != null) && (source instanceof StreamSource)) { |
|
610 |
||
611 |
Reader reader = null; |
|
612 |
||
613 |
InputStream inputStream = ((StreamSource) source).getInputStream(); |
|
614 |
if (inputStream != null) { |
|
615 |
if (sourceCharsetEncoding == null) { |
|
616 |
reader = new InputStreamReader(inputStream); |
|
617 |
} else { |
|
618 |
try { |
|
619 |
reader = |
|
620 |
new InputStreamReader( |
|
621 |
inputStream, sourceCharsetEncoding); |
|
622 |
} catch (UnsupportedEncodingException uee) { |
|
623 |
log.log( |
|
624 |
Level.SEVERE, |
|
625 |
"SAAJ0551.soap.unsupported.encoding", |
|
626 |
new Object[] {sourceCharsetEncoding}); |
|
627 |
throw new SOAPExceptionImpl( |
|
628 |
"Unsupported encoding " + sourceCharsetEncoding, |
|
629 |
uee); |
|
630 |
} |
|
631 |
} |
|
632 |
} else { |
|
633 |
reader = ((StreamSource) source).getReader(); |
|
634 |
} |
|
635 |
if (reader != null) { |
|
636 |
PushbackReader pushbackReader = |
|
637 |
new PushbackReader(reader, 4096); //some size to unread <?xml ....?> |
|
638 |
XMLDeclarationParser ev = |
|
639 |
new XMLDeclarationParser(pushbackReader); |
|
640 |
try { |
|
641 |
ev.parse(); |
|
642 |
} catch (Exception e) { |
|
643 |
log.log( |
|
644 |
Level.SEVERE, |
|
645 |
"SAAJ0552.soap.xml.decl.parsing.failed"); |
|
646 |
throw new SOAPExceptionImpl( |
|
647 |
"XML declaration parsing failed", e); |
|
648 |
} |
|
649 |
String xmlDecl = ev.getXmlDeclaration(); |
|
650 |
if ((xmlDecl != null) && (xmlDecl.length() > 0)) |
|
651 |
this.omitXmlDecl = false; |
|
652 |
return ev; |
|
653 |
} |
|
654 |
} |
|
655 |
return null; |
|
656 |
} |
|
657 |
||
658 |
public void setSourceCharsetEncoding(String charset) { |
|
659 |
this.sourceCharsetEncoding = charset; |
|
660 |
} |
|
661 |
||
662 |
public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName) |
|
663 |
throws DOMException { |
|
664 |
handleNewSource(); |
|
665 |
return document.renameNode(n, namespaceURI, qualifiedName); |
|
666 |
} |
|
667 |
||
668 |
public void normalizeDocument() { |
|
669 |
document.normalizeDocument(); |
|
670 |
} |
|
671 |
||
672 |
public DOMConfiguration getDomConfig() { |
|
673 |
return document.getDomConfig(); |
|
674 |
} |
|
675 |
||
676 |
public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) throws DOMException { |
|
677 |
handleNewSource(); |
|
678 |
return document.adoptNode(source); |
|
679 |
} |
|
680 |
||
681 |
public void setDocumentURI(String documentURI) { |
|
682 |
document.setDocumentURI(documentURI); |
|
683 |
} |
|
684 |
||
685 |
public String getDocumentURI() { |
|
686 |
return document.getDocumentURI(); |
|
687 |
} |
|
688 |
||
689 |
public void setStrictErrorChecking(boolean strictErrorChecking) { |
|
690 |
document.setStrictErrorChecking(strictErrorChecking); |
|
691 |
} |
|
692 |
||
693 |
public String getInputEncoding() { |
|
694 |
return document.getInputEncoding(); |
|
695 |
} |
|
696 |
||
697 |
public String getXmlEncoding() { |
|
698 |
return document.getXmlEncoding(); |
|
699 |
} |
|
700 |
||
701 |
public boolean getXmlStandalone() { |
|
702 |
return document.getXmlStandalone(); |
|
703 |
} |
|
704 |
||
705 |
public void setXmlStandalone(boolean xmlStandalone) throws DOMException { |
|
706 |
document.setXmlStandalone(xmlStandalone); |
|
707 |
} |
|
708 |
||
709 |
public String getXmlVersion() { |
|
710 |
return document.getXmlVersion(); |
|
711 |
} |
|
712 |
||
713 |
public void setXmlVersion(String xmlVersion) throws DOMException { |
|
714 |
document.setXmlVersion(xmlVersion); |
|
715 |
} |
|
716 |
||
717 |
public boolean getStrictErrorChecking() { |
|
718 |
return document.getStrictErrorChecking(); |
|
719 |
} |
|
720 |
||
721 |
// DOM L3 methods from org.w3c.dom.Node |
|
722 |
public String getBaseURI() { |
|
723 |
return document.getBaseURI(); |
|
724 |
} |
|
725 |
||
726 |
public short compareDocumentPosition(org.w3c.dom.Node other) |
|
727 |
throws DOMException { |
|
728 |
return document.compareDocumentPosition(other); |
|
729 |
} |
|
730 |
||
731 |
public String getTextContent() |
|
732 |
throws DOMException { |
|
733 |
return document.getTextContent(); |
|
734 |
} |
|
735 |
||
736 |
public void setTextContent(String textContent) throws DOMException { |
|
737 |
document.setTextContent(textContent); |
|
738 |
} |
|
739 |
||
740 |
public boolean isSameNode(org.w3c.dom.Node other) { |
|
741 |
return document.isSameNode(other); |
|
742 |
} |
|
743 |
||
744 |
public String lookupPrefix(String namespaceURI) { |
|
745 |
return document.lookupPrefix(namespaceURI); |
|
746 |
} |
|
747 |
||
748 |
public boolean isDefaultNamespace(String namespaceURI) { |
|
749 |
return document.isDefaultNamespace(namespaceURI); |
|
750 |
} |
|
751 |
||
752 |
public String lookupNamespaceURI(String prefix) { |
|
753 |
return document.lookupNamespaceURI(prefix); |
|
754 |
} |
|
755 |
||
756 |
public boolean isEqualNode(org.w3c.dom.Node arg) { |
|
757 |
return document.isEqualNode(arg); |
|
758 |
} |
|
759 |
||
760 |
public Object getFeature(String feature, |
|
761 |
String version) { |
|
762 |
return document.getFeature(feature,version); |
|
763 |
} |
|
764 |
||
765 |
public Object setUserData(String key, |
|
766 |
Object data, |
|
767 |
UserDataHandler handler) { |
|
768 |
return document.setUserData(key, data, handler); |
|
769 |
} |
|
770 |
||
771 |
public Object getUserData(String key) { |
|
772 |
return document.getUserData(key); |
|
773 |
} |
|
774 |
||
775 |
public void recycleNode() { |
|
776 |
// Nothing seems to be required to be done here |
|
777 |
} |
|
778 |
||
779 |
public String getValue() { |
|
780 |
return null; |
|
781 |
} |
|
782 |
||
783 |
public void setValue(String value) { |
|
784 |
log.severe("SAAJ0571.soappart.setValue.not.defined"); |
|
785 |
throw new IllegalStateException("Setting value of a soap part is not defined"); |
|
786 |
} |
|
787 |
||
788 |
public void setParentElement(SOAPElement parent) throws SOAPException { |
|
789 |
log.severe("SAAJ0570.soappart.parent.element.not.defined"); |
|
790 |
throw new SOAPExceptionImpl("The parent element of a soap part is not defined"); |
|
791 |
} |
|
792 |
||
793 |
public SOAPElement getParentElement() { |
|
794 |
return null; |
|
795 |
} |
|
796 |
||
797 |
public void detachNode() { |
|
798 |
// Nothing seems to be required to be done here |
|
799 |
} |
|
800 |
} |