1 /*
   2  * Copyright (c) 2004, 2015, 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 /**
  29  * {@code SOAPElementFactory} is a factory for XML fragments that
  30  * will eventually end up in the SOAP part. These fragments
  31  * can be inserted as children of the {@code SOAPHeader} or
  32  * {@code SOAPBody} or {@code SOAPEnvelope}.
  33  *
  34  * <p>Elements created using this factory do not have the properties
  35  * of an element that lives inside a SOAP header document. These
  36  * elements are copied into the XML document tree when they are
  37  * inserted.
  38  * @deprecated - Use {@code javax.xml.soap.SOAPFactory} for creating SOAPElements.
  39  * @see javax.xml.soap.SOAPFactory
  40  * @since 1.6
  41  */
  42 public class SOAPElementFactory {
  43 
  44     private SOAPFactory soapFactory;
  45 
  46     private SOAPElementFactory(SOAPFactory soapFactory) {
  47         this.soapFactory = soapFactory;
  48     }
  49 
  50     /**
  51      * Create a {@code SOAPElement} object initialized with the
  52      * given {@code Name} object.
  53      *
  54      * @param name a {@code Name} object with the XML name for
  55      *             the new element
  56      *
  57      * @return the new {@code SOAPElement} object that was
  58      *         created
  59      *
  60      * @exception SOAPException if there is an error in creating the
  61      *            {@code SOAPElement} object
  62      *
  63      * @deprecated Use
  64      * javax.xml.soap.SOAPFactory.createElement(javax.xml.soap.Name)
  65      * instead
  66      *
  67      * @see javax.xml.soap.SOAPFactory#createElement(javax.xml.soap.Name)
  68      * @see javax.xml.soap.SOAPFactory#createElement(javax.xml.namespace.QName)
  69      */
  70     public SOAPElement create(Name name) throws SOAPException {
  71         return soapFactory.createElement(name);
  72     }
  73 
  74     /**
  75      * Create a {@code SOAPElement} object initialized with the
  76      * given local name.
  77      *
  78      * @param localName a {@code String} giving the local name for
  79      *             the new element
  80      *
  81      * @return the new {@code SOAPElement} object that was
  82      *         created
  83      *
  84      * @exception SOAPException if there is an error in creating the
  85      *            {@code SOAPElement} object
  86      *
  87      * @deprecated Use
  88      * javax.xml.soap.SOAPFactory.createElement(String localName) instead
  89      *
  90      * @see javax.xml.soap.SOAPFactory#createElement(java.lang.String)
  91      */
  92     public SOAPElement create(String localName) throws SOAPException {
  93         return soapFactory.createElement(localName);
  94     }
  95 
  96     /**
  97      * Create a new {@code SOAPElement} object with the given
  98      * local name, prefix and uri.
  99      *
 100      * @param localName a {@code String} giving the local name
 101      *                  for the new element
 102      * @param prefix the prefix for this {@code SOAPElement}
 103      * @param uri a {@code String} giving the URI of the
 104      *            namespace to which the new element belongs
 105      *
 106      * @exception SOAPException if there is an error in creating the
 107      *            {@code SOAPElement} object
 108      *
 109      * @deprecated Use
 110      * javax.xml.soap.SOAPFactory.createElement(String localName,
 111      *                      String prefix,
 112      *                      String uri)
 113      * instead
 114      *
 115      * @see javax.xml.soap.SOAPFactory#createElement(java.lang.String, java.lang.String, java.lang.String)
 116      */
 117     public SOAPElement create(String localName, String prefix, String uri)
 118         throws SOAPException {
 119         return soapFactory.createElement(localName, prefix, uri);
 120     }
 121 
 122     /**
 123      * Creates a new instance of {@code SOAPElementFactory}.
 124      *
 125      * @return a new instance of a {@code SOAPElementFactory}
 126      *
 127      * @exception SOAPException if there was an error creating the
 128      *            default {@code SOAPElementFactory}
 129      */
 130     public static SOAPElementFactory newInstance() throws SOAPException {
 131         try {
 132             return new SOAPElementFactory(SOAPFactory.newInstance());
 133         } catch (Exception ex) {
 134             throw new SOAPException(
 135                 "Unable to create SOAP Element Factory: " + ex.getMessage());
 136         }
 137     }
 138 }