src/share/jaxws_classes/javax/xml/soap/SOAPFactory.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 1921
7166269ef0f1
parent 637
9c07ef4934dd
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset fdbe50121f48

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package javax.xml.soap;
aoqi@0 27
aoqi@0 28 import javax.xml.namespace.QName;
aoqi@0 29
aoqi@0 30 import org.w3c.dom.Element;
aoqi@0 31
aoqi@0 32 /**
aoqi@0 33 * <code>SOAPFactory</code> is a factory for creating various objects
aoqi@0 34 * that exist in the SOAP XML tree.
aoqi@0 35
aoqi@0 36 * <code>SOAPFactory</code> can be
aoqi@0 37 * used to create XML fragments that will eventually end up in the
aoqi@0 38 * SOAP part. These fragments can be inserted as children of the
aoqi@0 39 * {@link SOAPHeaderElement} or {@link SOAPBodyElement} or
aoqi@0 40 * {@link SOAPEnvelope} or other {@link SOAPElement} objects.
aoqi@0 41 *
aoqi@0 42 * <code>SOAPFactory</code> also has methods to create
aoqi@0 43 * <code>javax.xml.soap.Detail</code> objects as well as
aoqi@0 44 * <code>java.xml.soap.Name</code> objects.
aoqi@0 45 *
aoqi@0 46 */
aoqi@0 47 public abstract class SOAPFactory {
aoqi@0 48
aoqi@0 49 /**
aoqi@0 50 * A constant representing the property used to lookup the name of
aoqi@0 51 * a <code>SOAPFactory</code> implementation class.
aoqi@0 52 */
aoqi@0 53 static private final String SOAP_FACTORY_PROPERTY =
aoqi@0 54 "javax.xml.soap.SOAPFactory";
aoqi@0 55
aoqi@0 56 /**
aoqi@0 57 * Class name of default <code>SOAPFactory</code> implementation.
aoqi@0 58 */
aoqi@0 59 static final String DEFAULT_SOAP_FACTORY
aoqi@0 60 = "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl";
aoqi@0 61
aoqi@0 62 /**
aoqi@0 63 * Creates a <code>SOAPElement</code> object from an existing DOM
aoqi@0 64 * <code>Element</code>. If the DOM <code>Element</code> that is passed in
aoqi@0 65 * as an argument is already a <code>SOAPElement</code> then this method
aoqi@0 66 * must return it unmodified without any further work. Otherwise, a new
aoqi@0 67 * <code>SOAPElement</code> is created and a deep copy is made of the
aoqi@0 68 * <code>domElement</code> argument. The concrete type of the return value
aoqi@0 69 * will depend on the name of the <code>domElement</code> argument. If any
aoqi@0 70 * part of the tree rooted in <code>domElement</code> violates SOAP rules, a
aoqi@0 71 * <code>SOAPException</code> will be thrown.
aoqi@0 72 *
aoqi@0 73 * @param domElement - the <code>Element</code> to be copied.
aoqi@0 74 *
aoqi@0 75 * @return a new <code>SOAPElement</code> that is a copy of <code>domElement</code>.
aoqi@0 76 *
aoqi@0 77 * @exception SOAPException if there is an error in creating the
aoqi@0 78 * <code>SOAPElement</code> object
aoqi@0 79 *
aoqi@0 80 * @since SAAJ 1.3
aoqi@0 81 */
aoqi@0 82 public SOAPElement createElement(Element domElement) throws SOAPException {
aoqi@0 83 throw new UnsupportedOperationException("createElement(org.w3c.dom.Element) must be overridden by all subclasses of SOAPFactory.");
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 /**
aoqi@0 87 * Creates a <code>SOAPElement</code> object initialized with the
aoqi@0 88 * given <code>Name</code> object. The concrete type of the return value
aoqi@0 89 * will depend on the name given to the new <code>SOAPElement</code>. For
aoqi@0 90 * instance, a new <code>SOAPElement</code> with the name
aoqi@0 91 * "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a
aoqi@0 92 * <code>SOAPEnvelope</code> that supports SOAP 1.2 behavior to be created.
aoqi@0 93 *
aoqi@0 94 * @param name a <code>Name</code> object with the XML name for
aoqi@0 95 * the new element
aoqi@0 96 *
aoqi@0 97 * @return the new <code>SOAPElement</code> object that was
aoqi@0 98 * created
aoqi@0 99 *
aoqi@0 100 * @exception SOAPException if there is an error in creating the
aoqi@0 101 * <code>SOAPElement</code> object
aoqi@0 102 * @see SOAPFactory#createElement(javax.xml.namespace.QName)
aoqi@0 103 */
aoqi@0 104 public abstract SOAPElement createElement(Name name) throws SOAPException;
aoqi@0 105
aoqi@0 106 /**
aoqi@0 107 * Creates a <code>SOAPElement</code> object initialized with the
aoqi@0 108 * given <code>QName</code> object. The concrete type of the return value
aoqi@0 109 * will depend on the name given to the new <code>SOAPElement</code>. For
aoqi@0 110 * instance, a new <code>SOAPElement</code> with the name
aoqi@0 111 * "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a
aoqi@0 112 * <code>SOAPEnvelope</code> that supports SOAP 1.2 behavior to be created.
aoqi@0 113 *
aoqi@0 114 * @param qname a <code>QName</code> object with the XML name for
aoqi@0 115 * the new element
aoqi@0 116 *
aoqi@0 117 * @return the new <code>SOAPElement</code> object that was
aoqi@0 118 * created
aoqi@0 119 *
aoqi@0 120 * @exception SOAPException if there is an error in creating the
aoqi@0 121 * <code>SOAPElement</code> object
aoqi@0 122 * @see SOAPFactory#createElement(Name)
aoqi@0 123 * @since SAAJ 1.3
aoqi@0 124 */
aoqi@0 125 public SOAPElement createElement(QName qname) throws SOAPException {
aoqi@0 126 throw new UnsupportedOperationException("createElement(QName) must be overridden by all subclasses of SOAPFactory.");
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 /**
aoqi@0 130 * Creates a <code>SOAPElement</code> object initialized with the
aoqi@0 131 * given local name.
aoqi@0 132 *
aoqi@0 133 * @param localName a <code>String</code> giving the local name for
aoqi@0 134 * the new element
aoqi@0 135 *
aoqi@0 136 * @return the new <code>SOAPElement</code> object that was
aoqi@0 137 * created
aoqi@0 138 *
aoqi@0 139 * @exception SOAPException if there is an error in creating the
aoqi@0 140 * <code>SOAPElement</code> object
aoqi@0 141 */
aoqi@0 142 public abstract SOAPElement createElement(String localName)
aoqi@0 143 throws SOAPException;
aoqi@0 144
aoqi@0 145
aoqi@0 146 /**
aoqi@0 147 * Creates a new <code>SOAPElement</code> object with the given
aoqi@0 148 * local name, prefix and uri. The concrete type of the return value
aoqi@0 149 * will depend on the name given to the new <code>SOAPElement</code>. For
aoqi@0 150 * instance, a new <code>SOAPElement</code> with the name
aoqi@0 151 * "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a
aoqi@0 152 * <code>SOAPEnvelope</code> that supports SOAP 1.2 behavior to be created.
aoqi@0 153 *
aoqi@0 154 * @param localName a <code>String</code> giving the local name
aoqi@0 155 * for the new element
aoqi@0 156 * @param prefix the prefix for this <code>SOAPElement</code>
aoqi@0 157 * @param uri a <code>String</code> giving the URI of the
aoqi@0 158 * namespace to which the new element belongs
aoqi@0 159 *
aoqi@0 160 * @exception SOAPException if there is an error in creating the
aoqi@0 161 * <code>SOAPElement</code> object
aoqi@0 162 */
aoqi@0 163 public abstract SOAPElement createElement(
aoqi@0 164 String localName,
aoqi@0 165 String prefix,
aoqi@0 166 String uri)
aoqi@0 167 throws SOAPException;
aoqi@0 168
aoqi@0 169 /**
aoqi@0 170 * Creates a new <code>Detail</code> object which serves as a container
aoqi@0 171 * for <code>DetailEntry</code> objects.
aoqi@0 172 * <P>
aoqi@0 173 * This factory method creates <code>Detail</code> objects for use in
aoqi@0 174 * situations where it is not practical to use the <code>SOAPFault</code>
aoqi@0 175 * abstraction.
aoqi@0 176 *
aoqi@0 177 * @return a <code>Detail</code> object
aoqi@0 178 * @throws SOAPException if there is a SOAP error
aoqi@0 179 * @throws UnsupportedOperationException if the protocol specified
aoqi@0 180 * for the SOAPFactory was <code>DYNAMIC_SOAP_PROTOCOL</code>
aoqi@0 181 */
aoqi@0 182 public abstract Detail createDetail() throws SOAPException;
aoqi@0 183
aoqi@0 184 /**
aoqi@0 185 *Creates a new <code>SOAPFault</code> object initialized with the given <code>reasonText</code>
aoqi@0 186 * and <code>faultCode</code>
aoqi@0 187 *@param reasonText the ReasonText/FaultString for the fault
aoqi@0 188 *@param faultCode the FaultCode for the fault
aoqi@0 189 *@return a <code>SOAPFault</code> object
aoqi@0 190 *@throws SOAPException if there is a SOAP error
aoqi@0 191 *@since SAAJ 1.3
aoqi@0 192 */
aoqi@0 193 public abstract SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException;
aoqi@0 194
aoqi@0 195 /**
aoqi@0 196 *Creates a new default <code>SOAPFault</code> object
aoqi@0 197 *@return a <code>SOAPFault</code> object
aoqi@0 198 *@throws SOAPException if there is a SOAP error
aoqi@0 199 *@since SAAJ 1.3
aoqi@0 200 */
aoqi@0 201 public abstract SOAPFault createFault() throws SOAPException;
aoqi@0 202
aoqi@0 203 /**
aoqi@0 204 * Creates a new <code>Name</code> object initialized with the
aoqi@0 205 * given local name, namespace prefix, and namespace URI.
aoqi@0 206 * <P>
aoqi@0 207 * This factory method creates <code>Name</code> objects for use in
aoqi@0 208 * situations where it is not practical to use the <code>SOAPEnvelope</code>
aoqi@0 209 * abstraction.
aoqi@0 210 *
aoqi@0 211 * @param localName a <code>String</code> giving the local name
aoqi@0 212 * @param prefix a <code>String</code> giving the prefix of the namespace
aoqi@0 213 * @param uri a <code>String</code> giving the URI of the namespace
aoqi@0 214 * @return a <code>Name</code> object initialized with the given
aoqi@0 215 * local name, namespace prefix, and namespace URI
aoqi@0 216 * @throws SOAPException if there is a SOAP error
aoqi@0 217 */
aoqi@0 218 public abstract Name createName(
aoqi@0 219 String localName,
aoqi@0 220 String prefix,
aoqi@0 221 String uri)
aoqi@0 222 throws SOAPException;
aoqi@0 223
aoqi@0 224 /**
aoqi@0 225 * Creates a new <code>Name</code> object initialized with the
aoqi@0 226 * given local name.
aoqi@0 227 * <P>
aoqi@0 228 * This factory method creates <code>Name</code> objects for use in
aoqi@0 229 * situations where it is not practical to use the <code>SOAPEnvelope</code>
aoqi@0 230 * abstraction.
aoqi@0 231 *
aoqi@0 232 * @param localName a <code>String</code> giving the local name
aoqi@0 233 * @return a <code>Name</code> object initialized with the given
aoqi@0 234 * local name
aoqi@0 235 * @throws SOAPException if there is a SOAP error
aoqi@0 236 */
aoqi@0 237 public abstract Name createName(String localName) throws SOAPException;
aoqi@0 238
aoqi@0 239 /**
aoqi@0 240 * Creates a new <code>SOAPFactory</code> object that is an instance of
aoqi@0 241 * the default implementation (SOAP 1.1),
aoqi@0 242 *
aoqi@0 243 * This method uses the following ordered lookup procedure to determine the SOAPFactory implementation class to load:
aoqi@0 244 * <UL>
aoqi@0 245 * <LI> Use the javax.xml.soap.SOAPFactory system property.
aoqi@0 246 * <LI> Use the properties file "lib/jaxm.properties" in the JRE directory. This configuration file is in standard
aoqi@0 247 * java.util.Properties format and contains the fully qualified name of the implementation class with the key being the
aoqi@0 248 * system property defined above.
aoqi@0 249 * <LI> Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API
aoqi@0 250 * will look for a classname in the file META-INF/services/javax.xml.soap.SOAPFactory in jars available to the runtime.
aoqi@0 251 * <LI> Use the SAAJMetaFactory instance to locate the SOAPFactory implementation class.
aoqi@0 252 * </UL>
aoqi@0 253 *
aoqi@0 254 * @return a new instance of a <code>SOAPFactory</code>
aoqi@0 255 *
aoqi@0 256 * @exception SOAPException if there was an error creating the
aoqi@0 257 * default <code>SOAPFactory</code>
aoqi@0 258 * @see SAAJMetaFactory
aoqi@0 259 */
aoqi@0 260 public static SOAPFactory newInstance()
aoqi@0 261 throws SOAPException
aoqi@0 262 {
aoqi@0 263 try {
aoqi@0 264 SOAPFactory factory = (SOAPFactory) FactoryFinder.find(
aoqi@0 265 SOAP_FACTORY_PROPERTY, DEFAULT_SOAP_FACTORY, false);
aoqi@0 266 if (factory != null)
aoqi@0 267 return factory;
aoqi@0 268 return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
aoqi@0 269 } catch (Exception ex) {
aoqi@0 270 throw new SOAPException(
aoqi@0 271 "Unable to create SOAP Factory: " + ex.getMessage());
aoqi@0 272 }
aoqi@0 273
aoqi@0 274 }
aoqi@0 275
aoqi@0 276 /**
aoqi@0 277 * Creates a new <code>SOAPFactory</code> object that is an instance of
aoqi@0 278 * the specified implementation, this method uses the SAAJMetaFactory to
aoqi@0 279 * locate the implementation class and create the SOAPFactory instance.
aoqi@0 280 *
aoqi@0 281 * @return a new instance of a <code>SOAPFactory</code>
aoqi@0 282 *
aoqi@0 283 * @param protocol a string constant representing the protocol of the
aoqi@0 284 * specified SOAP factory implementation. May be
aoqi@0 285 * either <code>DYNAMIC_SOAP_PROTOCOL</code>,
aoqi@0 286 * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
aoqi@0 287 * as) <code>SOAP_1_1_PROTOCOL</code>, or
aoqi@0 288 * <code>SOAP_1_2_PROTOCOL</code>.
aoqi@0 289 *
aoqi@0 290 * @exception SOAPException if there was an error creating the
aoqi@0 291 * specified <code>SOAPFactory</code>
aoqi@0 292 * @see SAAJMetaFactory
aoqi@0 293 * @since SAAJ 1.3
aoqi@0 294 */
aoqi@0 295 public static SOAPFactory newInstance(String protocol)
aoqi@0 296 throws SOAPException {
aoqi@0 297 return SAAJMetaFactory.getInstance().newSOAPFactory(protocol);
aoqi@0 298 }
aoqi@0 299 }

mercurial