Thu, 31 Aug 2017 15:18:52 +0800
merge
1 /*
2 * Copyright (c) 1997, 2012, 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 */
26 package com.sun.xml.internal.ws.message;
28 import javax.xml.stream.XMLStreamReader;
29 import javax.xml.stream.XMLStreamException;
30 import javax.xml.stream.XMLStreamWriter;
31 import javax.xml.soap.SOAPMessage;
32 import javax.xml.soap.SOAPException;
33 import javax.xml.soap.SOAPHeader;
34 import javax.xml.soap.SOAPHeaderElement;
35 import javax.xml.namespace.QName;
37 import com.sun.istack.internal.Nullable;
38 import com.sun.istack.internal.NotNull;
39 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
40 import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
41 import org.xml.sax.ContentHandler;
42 import org.xml.sax.ErrorHandler;
43 import org.xml.sax.SAXException;
45 /**
46 * @author Arun Gupta
47 */
48 public class FaultDetailHeader extends AbstractHeaderImpl {
50 private AddressingVersion av;
51 private String wrapper;
52 private String problemValue = null;
54 public FaultDetailHeader(AddressingVersion av, String wrapper, QName problemHeader) {
55 this.av = av;
56 this.wrapper = wrapper;
57 this.problemValue = problemHeader.toString();
58 }
60 public FaultDetailHeader(AddressingVersion av, String wrapper, String problemValue) {
61 this.av = av;
62 this.wrapper = wrapper;
63 this.problemValue = problemValue;
64 }
66 public
67 @NotNull
68 String getNamespaceURI() {
69 return av.nsUri;
70 }
72 public
73 @NotNull
74 String getLocalPart() {
75 return av.faultDetailTag.getLocalPart();
76 }
78 @Nullable
79 public String getAttribute(@NotNull String nsUri, @NotNull String localName) {
80 return null;
81 }
83 public XMLStreamReader readHeader() throws XMLStreamException {
84 MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
85 XMLStreamWriter w = buf.createFromXMLStreamWriter();
86 writeTo(w);
87 return buf.readAsXMLStreamReader();
88 }
90 public void writeTo(XMLStreamWriter w) throws XMLStreamException {
91 w.writeStartElement("", av.faultDetailTag.getLocalPart(), av.faultDetailTag.getNamespaceURI());
92 w.writeDefaultNamespace(av.nsUri);
93 w.writeStartElement("", wrapper, av.nsUri);
94 w.writeCharacters(problemValue);
95 w.writeEndElement();
96 w.writeEndElement();
97 }
99 public void writeTo(SOAPMessage saaj) throws SOAPException {
100 SOAPHeader header = saaj.getSOAPHeader();
101 if (header == null)
102 header = saaj.getSOAPPart().getEnvelope().addHeader();
103 SOAPHeaderElement she = header.addHeaderElement(av.faultDetailTag);
104 she = header.addHeaderElement(new QName(av.nsUri, wrapper));
105 she.addTextNode(problemValue);
106 }
108 public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException {
109 String nsUri = av.nsUri;
110 String ln = av.faultDetailTag.getLocalPart();
112 h.startPrefixMapping("",nsUri);
113 h.startElement(nsUri,ln,ln,EMPTY_ATTS);
114 h.startElement(nsUri,wrapper,wrapper,EMPTY_ATTS);
115 h.characters(problemValue.toCharArray(),0,problemValue.length());
116 h.endElement(nsUri,wrapper,wrapper);
117 h.endElement(nsUri,ln,ln);
118 }
119 }