12009
|
1 |
/*
|
|
2 |
* Copyright (c) 2004, 2011, 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 javax.xml.soap;
|
|
27 |
|
|
28 |
import javax.xml.namespace.QName;
|
|
29 |
|
|
30 |
import org.w3c.dom.Element;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* <code>SOAPFactory</code> is a factory for creating various objects
|
|
34 |
* that exist in the SOAP XML tree.
|
|
35 |
|
|
36 |
* <code>SOAPFactory</code> can be
|
|
37 |
* used to create XML fragments that will eventually end up in the
|
|
38 |
* SOAP part. These fragments can be inserted as children of the
|
|
39 |
* {@link SOAPHeaderElement} or {@link SOAPBodyElement} or
|
|
40 |
* {@link SOAPEnvelope} or other {@link SOAPElement} objects.
|
|
41 |
*
|
|
42 |
* <code>SOAPFactory</code> also has methods to create
|
|
43 |
* <code>javax.xml.soap.Detail</code> objects as well as
|
|
44 |
* <code>java.xml.soap.Name</code> objects.
|
|
45 |
*
|
|
46 |
*/
|
|
47 |
public abstract class SOAPFactory {
|
|
48 |
|
|
49 |
/**
|
|
50 |
* A constant representing the property used to lookup the name of
|
|
51 |
* a <code>SOAPFactory</code> implementation class.
|
|
52 |
*/
|
|
53 |
static private final String SOAP_FACTORY_PROPERTY =
|
|
54 |
"javax.xml.soap.SOAPFactory";
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Creates a <code>SOAPElement</code> object from an existing DOM
|
|
58 |
* <code>Element</code>. If the DOM <code>Element</code> that is passed in
|
|
59 |
* as an argument is already a <code>SOAPElement</code> then this method
|
|
60 |
* must return it unmodified without any further work. Otherwise, a new
|
|
61 |
* <code>SOAPElement</code> is created and a deep copy is made of the
|
|
62 |
* <code>domElement</code> argument. The concrete type of the return value
|
|
63 |
* will depend on the name of the <code>domElement</code> argument. If any
|
|
64 |
* part of the tree rooted in <code>domElement</code> violates SOAP rules, a
|
|
65 |
* <code>SOAPException</code> will be thrown.
|
|
66 |
*
|
|
67 |
* @param domElement - the <code>Element</code> to be copied.
|
|
68 |
*
|
|
69 |
* @return a new <code>SOAPElement</code> that is a copy of <code>domElement</code>.
|
|
70 |
*
|
|
71 |
* @exception SOAPException if there is an error in creating the
|
|
72 |
* <code>SOAPElement</code> object
|
|
73 |
*
|
|
74 |
* @since SAAJ 1.3
|
|
75 |
*/
|
|
76 |
public SOAPElement createElement(Element domElement) throws SOAPException {
|
|
77 |
throw new UnsupportedOperationException("createElement(org.w3c.dom.Element) must be overridden by all subclasses of SOAPFactory.");
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Creates a <code>SOAPElement</code> object initialized with the
|
|
82 |
* given <code>Name</code> object. The concrete type of the return value
|
|
83 |
* will depend on the name given to the new <code>SOAPElement</code>. For
|
|
84 |
* instance, a new <code>SOAPElement</code> with the name
|
|
85 |
* "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a
|
|
86 |
* <code>SOAPEnvelope</code> that supports SOAP 1.2 behavior to be created.
|
|
87 |
*
|
|
88 |
* @param name a <code>Name</code> object with the XML name for
|
|
89 |
* the new element
|
|
90 |
*
|
|
91 |
* @return the new <code>SOAPElement</code> object that was
|
|
92 |
* created
|
|
93 |
*
|
|
94 |
* @exception SOAPException if there is an error in creating the
|
|
95 |
* <code>SOAPElement</code> object
|
|
96 |
* @see SOAPFactory#createElement(javax.xml.namespace.QName)
|
|
97 |
*/
|
|
98 |
public abstract SOAPElement createElement(Name name) throws SOAPException;
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Creates a <code>SOAPElement</code> object initialized with the
|
|
102 |
* given <code>QName</code> object. The concrete type of the return value
|
|
103 |
* will depend on the name given to the new <code>SOAPElement</code>. For
|
|
104 |
* instance, a new <code>SOAPElement</code> with the name
|
|
105 |
* "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a
|
|
106 |
* <code>SOAPEnvelope</code> that supports SOAP 1.2 behavior to be created.
|
|
107 |
*
|
|
108 |
* @param qname a <code>QName</code> object with the XML name for
|
|
109 |
* the new element
|
|
110 |
*
|
|
111 |
* @return the new <code>SOAPElement</code> object that was
|
|
112 |
* created
|
|
113 |
*
|
|
114 |
* @exception SOAPException if there is an error in creating the
|
|
115 |
* <code>SOAPElement</code> object
|
|
116 |
* @see SOAPFactory#createElement(Name)
|
|
117 |
* @since SAAJ 1.3
|
|
118 |
*/
|
|
119 |
public SOAPElement createElement(QName qname) throws SOAPException {
|
|
120 |
throw new UnsupportedOperationException("createElement(QName) must be overridden by all subclasses of SOAPFactory.");
|
|
121 |
}
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Creates a <code>SOAPElement</code> object initialized with the
|
|
125 |
* given local name.
|
|
126 |
*
|
|
127 |
* @param localName a <code>String</code> giving the local name for
|
|
128 |
* the new element
|
|
129 |
*
|
|
130 |
* @return the new <code>SOAPElement</code> object that was
|
|
131 |
* created
|
|
132 |
*
|
|
133 |
* @exception SOAPException if there is an error in creating the
|
|
134 |
* <code>SOAPElement</code> object
|
|
135 |
*/
|
|
136 |
public abstract SOAPElement createElement(String localName)
|
|
137 |
throws SOAPException;
|
|
138 |
|
|
139 |
|
|
140 |
/**
|
|
141 |
* Creates a new <code>SOAPElement</code> object with the given
|
|
142 |
* local name, prefix and uri. The concrete type of the return value
|
|
143 |
* will depend on the name given to the new <code>SOAPElement</code>. For
|
|
144 |
* instance, a new <code>SOAPElement</code> with the name
|
|
145 |
* "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a
|
|
146 |
* <code>SOAPEnvelope</code> that supports SOAP 1.2 behavior to be created.
|
|
147 |
*
|
|
148 |
* @param localName a <code>String</code> giving the local name
|
|
149 |
* for the new element
|
|
150 |
* @param prefix the prefix for this <code>SOAPElement</code>
|
|
151 |
* @param uri a <code>String</code> giving the URI of the
|
|
152 |
* namespace to which the new element belongs
|
|
153 |
*
|
|
154 |
* @exception SOAPException if there is an error in creating the
|
|
155 |
* <code>SOAPElement</code> object
|
|
156 |
*/
|
|
157 |
public abstract SOAPElement createElement(
|
|
158 |
String localName,
|
|
159 |
String prefix,
|
|
160 |
String uri)
|
|
161 |
throws SOAPException;
|
|
162 |
|
|
163 |
/**
|
|
164 |
* Creates a new <code>Detail</code> object which serves as a container
|
|
165 |
* for <code>DetailEntry</code> objects.
|
|
166 |
* <P>
|
|
167 |
* This factory method creates <code>Detail</code> objects for use in
|
|
168 |
* situations where it is not practical to use the <code>SOAPFault</code>
|
|
169 |
* abstraction.
|
|
170 |
*
|
|
171 |
* @return a <code>Detail</code> object
|
|
172 |
* @throws SOAPException if there is a SOAP error
|
|
173 |
* @throws UnsupportedOperationException if the protocol specified
|
|
174 |
* for the SOAPFactory was <code>DYNAMIC_SOAP_PROTOCOL</code>
|
|
175 |
*/
|
|
176 |
public abstract Detail createDetail() throws SOAPException;
|
|
177 |
|
|
178 |
/**
|
|
179 |
*Creates a new <code>SOAPFault</code> object initialized with the given <code>reasonText</code>
|
|
180 |
* and <code>faultCode</code>
|
|
181 |
*@param reasonText the ReasonText/FaultString for the fault
|
|
182 |
*@param faultCode the FaultCode for the fault
|
|
183 |
*@return a <code>SOAPFault</code> object
|
|
184 |
*@throws SOAPException if there is a SOAP error
|
|
185 |
*@since SAAJ 1.3
|
|
186 |
*/
|
|
187 |
public abstract SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException;
|
|
188 |
|
|
189 |
/**
|
|
190 |
*Creates a new default <code>SOAPFault</code> object
|
|
191 |
*@return a <code>SOAPFault</code> object
|
|
192 |
*@throws SOAPException if there is a SOAP error
|
|
193 |
*@since SAAJ 1.3
|
|
194 |
*/
|
|
195 |
public abstract SOAPFault createFault() throws SOAPException;
|
|
196 |
|
|
197 |
/**
|
|
198 |
* Creates a new <code>Name</code> object initialized with the
|
|
199 |
* given local name, namespace prefix, and namespace URI.
|
|
200 |
* <P>
|
|
201 |
* This factory method creates <code>Name</code> objects for use in
|
|
202 |
* situations where it is not practical to use the <code>SOAPEnvelope</code>
|
|
203 |
* abstraction.
|
|
204 |
*
|
|
205 |
* @param localName a <code>String</code> giving the local name
|
|
206 |
* @param prefix a <code>String</code> giving the prefix of the namespace
|
|
207 |
* @param uri a <code>String</code> giving the URI of the namespace
|
|
208 |
* @return a <code>Name</code> object initialized with the given
|
|
209 |
* local name, namespace prefix, and namespace URI
|
|
210 |
* @throws SOAPException if there is a SOAP error
|
|
211 |
*/
|
|
212 |
public abstract Name createName(
|
|
213 |
String localName,
|
|
214 |
String prefix,
|
|
215 |
String uri)
|
|
216 |
throws SOAPException;
|
|
217 |
|
|
218 |
/**
|
|
219 |
* Creates a new <code>Name</code> object initialized with the
|
|
220 |
* given local name.
|
|
221 |
* <P>
|
|
222 |
* This factory method creates <code>Name</code> objects for use in
|
|
223 |
* situations where it is not practical to use the <code>SOAPEnvelope</code>
|
|
224 |
* abstraction.
|
|
225 |
*
|
|
226 |
* @param localName a <code>String</code> giving the local name
|
|
227 |
* @return a <code>Name</code> object initialized with the given
|
|
228 |
* local name
|
|
229 |
* @throws SOAPException if there is a SOAP error
|
|
230 |
*/
|
|
231 |
public abstract Name createName(String localName) throws SOAPException;
|
|
232 |
|
|
233 |
/**
|
|
234 |
* Creates a new <code>SOAPFactory</code> object that is an instance of
|
|
235 |
* the default implementation (SOAP 1.1),
|
|
236 |
*
|
|
237 |
* This method uses the following ordered lookup procedure to determine the SOAPFactory implementation class to load:
|
|
238 |
* <UL>
|
|
239 |
* <LI> Use the javax.xml.soap.SOAPFactory system property.
|
|
240 |
* <LI> Use the properties file "lib/jaxm.properties" in the JRE directory. This configuration file is in standard
|
|
241 |
* java.util.Properties format and contains the fully qualified name of the implementation class with the key being the
|
|
242 |
* system property defined above.
|
|
243 |
* <LI> Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API
|
|
244 |
* will look for a classname in the file META-INF/services/javax.xml.soap.SOAPFactory in jars available to the runtime.
|
|
245 |
* <LI> Use the SAAJMetaFactory instance to locate the SOAPFactory implementation class.
|
|
246 |
* </UL>
|
|
247 |
*
|
|
248 |
* @return a new instance of a <code>SOAPFactory</code>
|
|
249 |
*
|
|
250 |
* @exception SOAPException if there was an error creating the
|
|
251 |
* default <code>SOAPFactory</code>
|
|
252 |
* @see SAAJMetaFactory
|
|
253 |
*/
|
|
254 |
public static SOAPFactory newInstance()
|
|
255 |
throws SOAPException
|
|
256 |
{
|
|
257 |
try {
|
|
258 |
SOAPFactory factory = (SOAPFactory) FactoryFinder.find(SOAP_FACTORY_PROPERTY);
|
|
259 |
if (factory != null)
|
|
260 |
return factory;
|
|
261 |
return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
|
262 |
} catch (Exception ex) {
|
|
263 |
throw new SOAPException(
|
|
264 |
"Unable to create SOAP Factory: " + ex.getMessage());
|
|
265 |
}
|
|
266 |
|
|
267 |
}
|
|
268 |
|
|
269 |
/**
|
|
270 |
* Creates a new <code>SOAPFactory</code> object that is an instance of
|
|
271 |
* the specified implementation, this method uses the SAAJMetaFactory to
|
|
272 |
* locate the implementation class and create the SOAPFactory instance.
|
|
273 |
*
|
|
274 |
* @return a new instance of a <code>SOAPFactory</code>
|
|
275 |
*
|
|
276 |
* @param protocol a string constant representing the protocol of the
|
|
277 |
* specified SOAP factory implementation. May be
|
|
278 |
* either <code>DYNAMIC_SOAP_PROTOCOL</code>,
|
|
279 |
* <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
|
|
280 |
* as) <code>SOAP_1_1_PROTOCOL</code>, or
|
|
281 |
* <code>SOAP_1_2_PROTOCOL</code>.
|
|
282 |
*
|
|
283 |
* @exception SOAPException if there was an error creating the
|
|
284 |
* specified <code>SOAPFactory</code>
|
|
285 |
* @see SAAJMetaFactory
|
|
286 |
* @since SAAJ 1.3
|
|
287 |
*/
|
|
288 |
public static SOAPFactory newInstance(String protocol)
|
|
289 |
throws SOAPException {
|
|
290 |
return SAAJMetaFactory.getInstance().newSOAPFactory(protocol);
|
|
291 |
}
|
|
292 |
}
|