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

duke@1 1 /*
tbell@45 2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
tbell@45 25 /*
tbell@50 26 *
tbell@50 27 *
tbell@50 28 *
tbell@45 29 */
tbell@45 30
tbell@45 31
duke@1 32 package com.sun.xml.internal.messaging.saaj.soap;
duke@1 33
duke@1 34 import java.util.logging.Logger;
duke@1 35 import java.util.logging.Level;
duke@1 36
duke@1 37 import javax.xml.namespace.QName;
duke@1 38 import javax.xml.soap.*;
duke@1 39
duke@1 40 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory;
duke@1 41 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl;
duke@1 42 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
duke@1 43 import com.sun.xml.internal.messaging.saaj.util.*;
duke@1 44
duke@1 45 import org.w3c.dom.Element;
duke@1 46 import org.w3c.dom.Document;
duke@1 47 import org.w3c.dom.NodeList;
duke@1 48 import org.w3c.dom.NamedNodeMap;
duke@1 49 import org.w3c.dom.Attr;
duke@1 50
duke@1 51 public abstract class SOAPFactoryImpl extends SOAPFactory {
duke@1 52
tbell@50 53 protected static final Logger
duke@1 54 log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
duke@1 55 "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
duke@1 56
duke@1 57 protected abstract SOAPDocumentImpl createDocument();
duke@1 58
duke@1 59 public SOAPElement createElement(String tagName) throws SOAPException {
duke@1 60 if (tagName == null) {
duke@1 61 log.log(
duke@1 62 Level.SEVERE,"SAAJ0567.soap.null.input",
duke@1 63 new Object[] {"tagName","SOAPFactory.createElement"});
duke@1 64 throw new SOAPException("Null tagName argument passed to createElement");
duke@1 65 }
duke@1 66 return ElementFactory.createElement(createDocument(),
duke@1 67 NameImpl.createFromTagName(tagName));
duke@1 68 }
duke@1 69
duke@1 70 public SOAPElement createElement(Name name) throws SOAPException {
duke@1 71 // @since SAAJ 1.3
duke@1 72 // If the Name was null it would cause a NullPointerException in earlier release
duke@1 73 if (name == null) {
duke@1 74 log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
duke@1 75 new Object[] {"name","SOAPFactory.createElement"});
duke@1 76 throw new SOAPException("Null name argument passed to createElement");
duke@1 77 }
duke@1 78 return ElementFactory.createElement(createDocument(), name);
duke@1 79 }
duke@1 80
duke@1 81 public SOAPElement createElement(QName qname) throws SOAPException {
duke@1 82 if (qname == null) {
duke@1 83 log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
duke@1 84 new Object[] {"qname","SOAPFactory.createElement"});
duke@1 85 throw new SOAPException("Null qname argument passed to createElement");
duke@1 86 }
duke@1 87 return ElementFactory.createElement(createDocument(),qname);
duke@1 88 }
duke@1 89
duke@1 90 public SOAPElement createElement(
duke@1 91 String localName,
duke@1 92 String prefix,
duke@1 93 String uri) throws SOAPException {
duke@1 94
duke@1 95 // @since SAAJ 1.3
duke@1 96 // if prefix !=null but localName== null then in earlier releases it would create
duke@1 97 // a Qualified Name <prefix>:null which is not meaningful
duke@1 98 if (localName == null) {
duke@1 99 log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
duke@1 100 new Object[] {"localName","SOAPFactory.createElement"});
duke@1 101 throw new SOAPException("Null localName argument passed to createElement");
duke@1 102 }
duke@1 103 return ElementFactory.createElement(createDocument(), localName, prefix, uri);
duke@1 104 }
duke@1 105
duke@1 106 public Name createName(String localName, String prefix, String uri)
duke@1 107 throws SOAPException {
duke@1 108 // @since SAAJ 1.3
duke@1 109 // if localName==null, earlier impl would create Name with localName=""
duke@1 110 // which is absurd.
duke@1 111 if (localName == null) {
duke@1 112 log.log(
duke@1 113 Level.SEVERE,"SAAJ0567.soap.null.input",
duke@1 114 new Object[] {"localName","SOAPFactory.createName"});
duke@1 115 throw new SOAPException("Null localName argument passed to createName");
duke@1 116 }
duke@1 117 return NameImpl.create(localName, prefix, uri);
duke@1 118 }
duke@1 119
duke@1 120 public Name createName(String localName) throws SOAPException {
duke@1 121 // @since SAAJ 1.3
duke@1 122 // if localName==null, earlier impl would create Name with localName=null
duke@1 123 // which is absurd.
duke@1 124 if (localName == null) {
duke@1 125 log.log(
duke@1 126 Level.SEVERE,"SAAJ0567.soap.null.input",
duke@1 127 new Object[] {"localName","SOAPFactory.createName"});
duke@1 128 throw new SOAPException("Null localName argument passed to createName");
duke@1 129 }
duke@1 130 return NameImpl.createFromUnqualifiedName(localName);
duke@1 131 }
duke@1 132
duke@1 133 // Note: the child elements might still be org.w3c.dom.Element's, but the
duke@1 134 // getChildElements will do the conversion to SOAPElement when called.
duke@1 135 public SOAPElement createElement(Element domElement) throws SOAPException {
duke@1 136 if (domElement == null) {
duke@1 137 return null;
duke@1 138 }
duke@1 139 return convertToSoapElement(domElement);
duke@1 140 }
duke@1 141
duke@1 142 private SOAPElement convertToSoapElement(Element element) throws SOAPException {
duke@1 143
duke@1 144 if (element instanceof SOAPElement) {
duke@1 145 return (SOAPElement) element;
duke@1 146 }
duke@1 147
duke@1 148 SOAPElement copy = createElement(
duke@1 149 element.getLocalName(),
duke@1 150 element.getPrefix(),
duke@1 151 element.getNamespaceURI());
duke@1 152
duke@1 153 Document ownerDoc = copy.getOwnerDocument();
duke@1 154
duke@1 155 NamedNodeMap attrMap = element.getAttributes();
duke@1 156 for (int i=0; i < attrMap.getLength(); i++) {
duke@1 157 Attr nextAttr = (Attr)attrMap.item(i);
duke@1 158 Attr importedAttr = (Attr)ownerDoc.importNode(nextAttr, true);
duke@1 159 copy.setAttributeNodeNS(importedAttr);
duke@1 160 }
duke@1 161
duke@1 162
duke@1 163 NodeList nl = element.getChildNodes();
duke@1 164 for (int i=0; i < nl.getLength(); i++) {
duke@1 165 org.w3c.dom.Node next = nl.item(i);
duke@1 166 org.w3c.dom.Node imported = ownerDoc.importNode(next, true);
duke@1 167 copy.appendChild(imported);
duke@1 168 }
duke@1 169
duke@1 170 return copy;
duke@1 171 }
duke@1 172
duke@1 173 public Detail createDetail() throws SOAPException {
duke@1 174 throw new UnsupportedOperationException();
duke@1 175 }
duke@1 176
duke@1 177 public SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException {
duke@1 178 throw new UnsupportedOperationException();
duke@1 179 }
duke@1 180
duke@1 181 public SOAPFault createFault() throws SOAPException {
duke@1 182 throw new UnsupportedOperationException();
duke@1 183 }
duke@1 184
duke@1 185 }

mercurial