src/share/classes/com/sun/xml/internal/messaging/saaj/soap/SOAPFactoryImpl.java

Mon, 04 May 2009 21:10:41 -0700

author
tbell
date
Mon, 04 May 2009 21:10:41 -0700
changeset 50
42dfec6871f6
parent 45
31822b475baa
child 78
860b95cc8d1d
permissions
-rw-r--r--

6658158: Mutable statics in SAAJ (findbugs)
6658163: txw2.DatatypeWriter.BUILDIN is a mutable static (findbugs)
Reviewed-by: darcy

     1 /*
     2  * Copyright 2005-2006 Sun Microsystems, Inc.  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.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    25 /*
    26  *
    27  *
    28  *
    29  */
    32 package com.sun.xml.internal.messaging.saaj.soap;
    34 import java.util.logging.Logger;
    35 import java.util.logging.Level;
    37 import javax.xml.namespace.QName;
    38 import javax.xml.soap.*;
    40 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory;
    41 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl;
    42 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
    43 import com.sun.xml.internal.messaging.saaj.util.*;
    45 import org.w3c.dom.Element;
    46 import org.w3c.dom.Document;
    47 import org.w3c.dom.NodeList;
    48 import org.w3c.dom.NamedNodeMap;
    49 import org.w3c.dom.Attr;
    51 public abstract class SOAPFactoryImpl extends SOAPFactory {
    53     protected static final Logger
    54         log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
    55                                "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
    57     protected abstract SOAPDocumentImpl createDocument();
    59     public SOAPElement createElement(String tagName) throws SOAPException {
    60          if (tagName == null) {
    61              log.log(
    62                  Level.SEVERE,"SAAJ0567.soap.null.input",
    63                  new Object[] {"tagName","SOAPFactory.createElement"});
    64              throw new SOAPException("Null tagName argument passed to createElement");
    65          }
    66         return ElementFactory.createElement(createDocument(),
    67                         NameImpl.createFromTagName(tagName));
    68     }
    70     public SOAPElement createElement(Name name) throws SOAPException {
    71         // @since SAAJ 1.3
    72         // If the Name was null it would cause a NullPointerException in earlier release
    73         if (name == null) {
    74             log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
    75                         new Object[] {"name","SOAPFactory.createElement"});
    76             throw new SOAPException("Null name argument passed to createElement");
    77         }
    78         return ElementFactory.createElement(createDocument(), name);
    79     }
    81     public SOAPElement createElement(QName qname) throws SOAPException {
    82         if (qname == null) {
    83             log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
    84                         new Object[] {"qname","SOAPFactory.createElement"});
    85             throw new SOAPException("Null qname argument passed to createElement");
    86         }
    87         return ElementFactory.createElement(createDocument(),qname);
    88     }
    90     public SOAPElement createElement(
    91         String localName,
    92         String prefix,
    93         String uri)  throws SOAPException {
    95         // @since SAAJ 1.3
    96         // if prefix !=null but localName== null then in earlier releases it would create
    97         // a Qualified Name  <prefix>:null which is not meaningful
    98         if (localName == null) {
    99             log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
   100                         new Object[] {"localName","SOAPFactory.createElement"});
   101             throw new SOAPException("Null localName argument passed to createElement");
   102         }
   103         return ElementFactory.createElement(createDocument(), localName, prefix, uri);
   104     }
   106     public Name createName(String localName, String prefix, String uri)
   107         throws SOAPException {
   108         // @since SAAJ 1.3
   109         // if localName==null, earlier impl would create Name with localName=""
   110         // which is absurd.
   111         if (localName == null) {
   112             log.log(
   113                  Level.SEVERE,"SAAJ0567.soap.null.input",
   114                  new Object[] {"localName","SOAPFactory.createName"});
   115             throw new SOAPException("Null localName argument passed to createName");
   116         }
   117         return NameImpl.create(localName, prefix, uri);
   118     }
   120     public Name createName(String localName) throws SOAPException {
   121         // @since SAAJ 1.3
   122         // if localName==null, earlier impl would create Name with localName=null
   123         // which is absurd.
   124         if (localName == null) {
   125             log.log(
   126                 Level.SEVERE,"SAAJ0567.soap.null.input",
   127                 new Object[] {"localName","SOAPFactory.createName"});
   128             throw new SOAPException("Null localName argument passed to createName");
   129         }
   130         return NameImpl.createFromUnqualifiedName(localName);
   131     }
   133     // Note: the child elements might still be org.w3c.dom.Element's, but the
   134     // getChildElements will do the conversion to SOAPElement when called.
   135     public SOAPElement createElement(Element domElement) throws SOAPException {
   136         if (domElement == null) {
   137             return null;
   138         }
   139         return convertToSoapElement(domElement);
   140     }
   142     private  SOAPElement convertToSoapElement(Element element) throws SOAPException {
   144         if (element instanceof SOAPElement) {
   145             return (SOAPElement) element;
   146         }
   148         SOAPElement copy = createElement(
   149                                 element.getLocalName(),
   150                                 element.getPrefix(),
   151                                 element.getNamespaceURI());
   153         Document ownerDoc = copy.getOwnerDocument();
   155         NamedNodeMap attrMap = element.getAttributes();
   156         for (int i=0; i < attrMap.getLength(); i++) {
   157             Attr nextAttr = (Attr)attrMap.item(i);
   158             Attr importedAttr = (Attr)ownerDoc.importNode(nextAttr, true);
   159             copy.setAttributeNodeNS(importedAttr);
   160         }
   163         NodeList nl = element.getChildNodes();
   164         for (int i=0; i < nl.getLength(); i++) {
   165             org.w3c.dom.Node next = nl.item(i);
   166             org.w3c.dom.Node imported = ownerDoc.importNode(next, true);
   167             copy.appendChild(imported);
   168         }
   170         return copy;
   171     }
   173     public Detail createDetail() throws SOAPException {
   174         throw new UnsupportedOperationException();
   175     }
   177     public  SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException {
   178         throw new UnsupportedOperationException();
   179     }
   181     public SOAPFault createFault() throws SOAPException {
   182         throw new UnsupportedOperationException();
   183     }
   185 }

mercurial