1 /* |
1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
28 import javax.xml.namespace.QName; |
28 import javax.xml.namespace.QName; |
29 import javax.xml.soap.*; |
29 import javax.xml.soap.*; |
30 |
30 |
31 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; |
31 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; |
32 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; |
32 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; |
33 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.*; |
33 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.Body1_1Impl; |
34 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.*; |
34 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.Detail1_1Impl; |
|
35 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.Envelope1_1Impl; |
|
36 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.Fault1_1Impl; |
|
37 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.FaultElement1_1Impl; |
|
38 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.Header1_1Impl; |
|
39 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl; |
|
40 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.Body1_2Impl; |
|
41 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.Detail1_2Impl; |
|
42 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.Envelope1_2Impl; |
|
43 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.Fault1_2Impl; |
|
44 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.Header1_2Impl; |
|
45 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPPart1_2Impl; |
|
46 import org.w3c.dom.Element; |
|
47 |
|
48 import java.util.Objects; |
35 |
49 |
36 |
50 |
37 public class ElementFactory { |
51 public class ElementFactory { |
38 public static SOAPElement createElement( |
52 public static SOAPElement createElement( |
39 SOAPDocumentImpl ownerDocument, |
53 SOAPDocumentImpl ownerDocument, |
52 name.getLocalPart(), |
66 name.getLocalPart(), |
53 name.getPrefix(), |
67 name.getPrefix(), |
54 name.getNamespaceURI()); |
68 name.getNamespaceURI()); |
55 } |
69 } |
56 |
70 |
|
71 /** |
|
72 * Create element wrapper for existing DOM element. |
|
73 * |
|
74 * @param ownerDocument SOAP document wrapper not null |
|
75 * @param element DOM element not null |
|
76 * @return SOAP wrapper for DOM element |
|
77 */ |
|
78 public static SOAPElement createElement(SOAPDocumentImpl ownerDocument, Element element) { |
|
79 Objects.requireNonNull(ownerDocument); |
|
80 Objects.requireNonNull(element); |
|
81 |
|
82 String localName = element.getLocalName(); |
|
83 String namespaceUri = element.getNamespaceURI(); |
|
84 String prefix = element.getPrefix(); |
|
85 |
|
86 if ("Envelope".equalsIgnoreCase(localName)) { |
|
87 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
|
88 return new Envelope1_1Impl(ownerDocument, element); |
|
89 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
|
90 return new Envelope1_2Impl(ownerDocument, element); |
|
91 } |
|
92 } |
|
93 if ("Body".equalsIgnoreCase(localName)) { |
|
94 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
|
95 return new Body1_1Impl(ownerDocument, element); |
|
96 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
|
97 return new Body1_2Impl(ownerDocument, element); |
|
98 } |
|
99 } |
|
100 if ("Header".equalsIgnoreCase(localName)) { |
|
101 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
|
102 return new Header1_1Impl(ownerDocument, element); |
|
103 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
|
104 return new Header1_2Impl(ownerDocument, element); |
|
105 } |
|
106 } |
|
107 if ("Fault".equalsIgnoreCase(localName)) { |
|
108 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
|
109 return new Fault1_1Impl(element, ownerDocument); |
|
110 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
|
111 return new Fault1_2Impl(element, ownerDocument); |
|
112 } |
|
113 |
|
114 } |
|
115 if ("Detail".equalsIgnoreCase(localName)) { |
|
116 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
|
117 return new Detail1_1Impl(ownerDocument, element); |
|
118 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
|
119 return new Detail1_2Impl(ownerDocument, element); |
|
120 } |
|
121 } |
|
122 if ("faultcode".equalsIgnoreCase(localName) |
|
123 || "faultstring".equalsIgnoreCase(localName) |
|
124 || "faultactor".equalsIgnoreCase(localName)) { |
|
125 // SOAP 1.2 does not have fault(code/string/actor) |
|
126 // So there is no else case required |
|
127 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
|
128 return new FaultElement1_1Impl(ownerDocument, |
|
129 localName, |
|
130 prefix); |
|
131 } |
|
132 } |
|
133 |
|
134 return new ElementImpl(ownerDocument, element); |
|
135 } |
|
136 |
57 public static SOAPElement createElement( |
137 public static SOAPElement createElement( |
58 SOAPDocumentImpl ownerDocument, |
138 SOAPDocumentImpl ownerDocument, |
59 String localName, |
139 String localName, |
60 String prefix, |
140 String prefix, |
61 String namespaceUri) { |
141 String namespaceUri) { |
90 |
170 |
91 if (prefix == null) { |
171 if (prefix == null) { |
92 prefix = NameImpl.SOAP_ENVELOPE_PREFIX; |
172 prefix = NameImpl.SOAP_ENVELOPE_PREFIX; |
93 } |
173 } |
94 |
174 |
95 if (localName.equalsIgnoreCase("Envelope")) { |
175 if ("Envelope".equalsIgnoreCase(localName)) { |
96 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
176 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
97 return new Envelope1_1Impl(ownerDocument, prefix); |
177 return new Envelope1_1Impl(ownerDocument, prefix); |
98 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
178 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
99 return new Envelope1_2Impl(ownerDocument, prefix); |
179 return new Envelope1_2Impl(ownerDocument, prefix); |
100 } |
180 } |
101 } |
181 } |
102 if (localName.equalsIgnoreCase("Body")) { |
182 if ("Body".equalsIgnoreCase(localName)) { |
103 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
183 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
104 return new Body1_1Impl(ownerDocument, prefix); |
184 return new Body1_1Impl(ownerDocument, prefix); |
105 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
185 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
106 return new Body1_2Impl(ownerDocument, prefix); |
186 return new Body1_2Impl(ownerDocument, prefix); |
107 } |
187 } |
108 } |
188 } |
109 if (localName.equalsIgnoreCase("Header")) { |
189 if ("Header".equalsIgnoreCase(localName)) { |
110 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
190 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
111 return new Header1_1Impl(ownerDocument, prefix); |
191 return new Header1_1Impl(ownerDocument, prefix); |
112 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
192 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
113 return new Header1_2Impl(ownerDocument, prefix); |
193 return new Header1_2Impl(ownerDocument, prefix); |
114 } |
194 } |
115 } |
195 } |
116 if (localName.equalsIgnoreCase("Fault")) { |
196 if ("Fault".equalsIgnoreCase(localName)) { |
117 SOAPFault fault = null; |
197 SOAPFault fault = null; |
118 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
198 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
119 fault = new Fault1_1Impl(ownerDocument, prefix); |
199 fault = new Fault1_1Impl(ownerDocument, prefix); |
120 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
200 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
121 fault = new Fault1_2Impl(ownerDocument, prefix); |
201 fault = new Fault1_2Impl(ownerDocument, prefix); |
137 // } |
217 // } |
138 return fault; |
218 return fault; |
139 } |
219 } |
140 |
220 |
141 } |
221 } |
142 if (localName.equalsIgnoreCase("Detail")) { |
222 if ("Detail".equalsIgnoreCase(localName)) { |
143 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
223 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
144 return new Detail1_1Impl(ownerDocument, prefix); |
224 return new Detail1_1Impl(ownerDocument, prefix); |
145 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
225 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) { |
146 return new Detail1_2Impl(ownerDocument, prefix); |
226 return new Detail1_2Impl(ownerDocument, prefix); |
147 } |
227 } |
148 } |
228 } |
149 if (localName.equalsIgnoreCase("faultcode") |
229 if ("faultcode".equalsIgnoreCase(localName) |
150 || localName.equalsIgnoreCase("faultstring") |
230 || "faultstring".equalsIgnoreCase(localName) |
151 || localName.equalsIgnoreCase("faultactor")) { |
231 || "faultactor".equalsIgnoreCase(localName)) { |
152 // SOAP 1.2 does not have fault(code/string/actor) |
232 // SOAP 1.2 does not have fault(code/string/actor) |
153 // So there is no else case required |
233 // So there is no else case required |
154 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
234 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) { |
155 return new FaultElement1_1Impl(ownerDocument, |
235 return new FaultElement1_1Impl(ownerDocument, |
156 localName, |
236 localName, |