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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 384
8f2986ff0235
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

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

mercurial