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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
0961a4a21176
child 45
31822b475baa
permissions
-rw-r--r--

Initial load

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

mercurial