1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/SOAPFactoryImpl.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,179 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.messaging.saaj.soap; 1.30 + 1.31 +import java.util.logging.Logger; 1.32 +import java.util.logging.Level; 1.33 + 1.34 +import javax.xml.namespace.QName; 1.35 +import javax.xml.soap.*; 1.36 + 1.37 +import com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory; 1.38 +import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl; 1.39 +import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; 1.40 +import com.sun.xml.internal.messaging.saaj.util.*; 1.41 + 1.42 +import org.w3c.dom.Element; 1.43 +import org.w3c.dom.Document; 1.44 +import org.w3c.dom.NodeList; 1.45 +import org.w3c.dom.NamedNodeMap; 1.46 +import org.w3c.dom.Attr; 1.47 + 1.48 +public abstract class SOAPFactoryImpl extends SOAPFactory { 1.49 + 1.50 + protected static final Logger 1.51 + log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN, 1.52 + "com.sun.xml.internal.messaging.saaj.soap.LocalStrings"); 1.53 + 1.54 + protected abstract SOAPDocumentImpl createDocument(); 1.55 + 1.56 + public SOAPElement createElement(String tagName) throws SOAPException { 1.57 + if (tagName == null) { 1.58 + log.log( 1.59 + Level.SEVERE,"SAAJ0567.soap.null.input", 1.60 + new Object[] {"tagName","SOAPFactory.createElement"}); 1.61 + throw new SOAPException("Null tagName argument passed to createElement"); 1.62 + } 1.63 + return ElementFactory.createElement(createDocument(), 1.64 + NameImpl.createFromTagName(tagName)); 1.65 + } 1.66 + 1.67 + public SOAPElement createElement(Name name) throws SOAPException { 1.68 + // @since SAAJ 1.3 1.69 + // If the Name was null it would cause a NullPointerException in earlier release 1.70 + if (name == null) { 1.71 + log.log(Level.SEVERE,"SAAJ0567.soap.null.input", 1.72 + new Object[] {"name","SOAPFactory.createElement"}); 1.73 + throw new SOAPException("Null name argument passed to createElement"); 1.74 + } 1.75 + return ElementFactory.createElement(createDocument(), name); 1.76 + } 1.77 + 1.78 + public SOAPElement createElement(QName qname) throws SOAPException { 1.79 + if (qname == null) { 1.80 + log.log(Level.SEVERE,"SAAJ0567.soap.null.input", 1.81 + new Object[] {"qname","SOAPFactory.createElement"}); 1.82 + throw new SOAPException("Null qname argument passed to createElement"); 1.83 + } 1.84 + return ElementFactory.createElement(createDocument(),qname); 1.85 + } 1.86 + 1.87 + public SOAPElement createElement( 1.88 + String localName, 1.89 + String prefix, 1.90 + String uri) throws SOAPException { 1.91 + 1.92 + // @since SAAJ 1.3 1.93 + // if prefix !=null but localName== null then in earlier releases it would create 1.94 + // a Qualified Name <prefix>:null which is not meaningful 1.95 + if (localName == null) { 1.96 + log.log(Level.SEVERE,"SAAJ0567.soap.null.input", 1.97 + new Object[] {"localName","SOAPFactory.createElement"}); 1.98 + throw new SOAPException("Null localName argument passed to createElement"); 1.99 + } 1.100 + return ElementFactory.createElement(createDocument(), localName, prefix, uri); 1.101 + } 1.102 + 1.103 + public Name createName(String localName, String prefix, String uri) 1.104 + throws SOAPException { 1.105 + // @since SAAJ 1.3 1.106 + // if localName==null, earlier impl would create Name with localName="" 1.107 + // which is absurd. 1.108 + if (localName == null) { 1.109 + log.log( 1.110 + Level.SEVERE,"SAAJ0567.soap.null.input", 1.111 + new Object[] {"localName","SOAPFactory.createName"}); 1.112 + throw new SOAPException("Null localName argument passed to createName"); 1.113 + } 1.114 + return NameImpl.create(localName, prefix, uri); 1.115 + } 1.116 + 1.117 + public Name createName(String localName) throws SOAPException { 1.118 + // @since SAAJ 1.3 1.119 + // if localName==null, earlier impl would create Name with localName=null 1.120 + // which is absurd. 1.121 + if (localName == null) { 1.122 + log.log( 1.123 + Level.SEVERE,"SAAJ0567.soap.null.input", 1.124 + new Object[] {"localName","SOAPFactory.createName"}); 1.125 + throw new SOAPException("Null localName argument passed to createName"); 1.126 + } 1.127 + return NameImpl.createFromUnqualifiedName(localName); 1.128 + } 1.129 + 1.130 + // Note: the child elements might still be org.w3c.dom.Element's, but the 1.131 + // getChildElements will do the conversion to SOAPElement when called. 1.132 + public SOAPElement createElement(Element domElement) throws SOAPException { 1.133 + if (domElement == null) { 1.134 + return null; 1.135 + } 1.136 + return convertToSoapElement(domElement); 1.137 + } 1.138 + 1.139 + private SOAPElement convertToSoapElement(Element element) throws SOAPException { 1.140 + 1.141 + if (element instanceof SOAPElement) { 1.142 + return (SOAPElement) element; 1.143 + } 1.144 + 1.145 + SOAPElement copy = createElement( 1.146 + element.getLocalName(), 1.147 + element.getPrefix(), 1.148 + element.getNamespaceURI()); 1.149 + 1.150 + Document ownerDoc = copy.getOwnerDocument(); 1.151 + 1.152 + NamedNodeMap attrMap = element.getAttributes(); 1.153 + for (int i=0; i < attrMap.getLength(); i++) { 1.154 + Attr nextAttr = (Attr)attrMap.item(i); 1.155 + Attr importedAttr = (Attr)ownerDoc.importNode(nextAttr, true); 1.156 + copy.setAttributeNodeNS(importedAttr); 1.157 + } 1.158 + 1.159 + 1.160 + NodeList nl = element.getChildNodes(); 1.161 + for (int i=0; i < nl.getLength(); i++) { 1.162 + org.w3c.dom.Node next = nl.item(i); 1.163 + org.w3c.dom.Node imported = ownerDoc.importNode(next, true); 1.164 + copy.appendChild(imported); 1.165 + } 1.166 + 1.167 + return copy; 1.168 + } 1.169 + 1.170 + public Detail createDetail() throws SOAPException { 1.171 + throw new UnsupportedOperationException(); 1.172 + } 1.173 + 1.174 + public SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException { 1.175 + throw new UnsupportedOperationException(); 1.176 + } 1.177 + 1.178 + public SOAPFault createFault() throws SOAPException { 1.179 + throw new UnsupportedOperationException(); 1.180 + } 1.181 + 1.182 +}