duke@1: /* tbell@45: * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. Sun designates this duke@1: * particular file as subject to the "Classpath" exception as provided duke@1: * by Sun in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ tbell@45: /* tbell@45: * $Id: SOAPFactoryImpl.java,v 1.21 2006/01/27 12:49:29 vj135062 Exp $ tbell@45: * $Revision: 1.21 $ tbell@45: * $Date: 2006/01/27 12:49:29 $ tbell@45: */ tbell@45: tbell@45: duke@1: package com.sun.xml.internal.messaging.saaj.soap; duke@1: duke@1: import java.util.logging.Logger; duke@1: import java.util.logging.Level; duke@1: duke@1: import javax.xml.namespace.QName; duke@1: import javax.xml.soap.*; duke@1: duke@1: import com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory; duke@1: import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl; duke@1: import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; duke@1: import com.sun.xml.internal.messaging.saaj.util.*; duke@1: duke@1: import org.w3c.dom.Element; duke@1: import org.w3c.dom.Document; duke@1: import org.w3c.dom.NodeList; duke@1: import org.w3c.dom.NamedNodeMap; duke@1: import org.w3c.dom.Attr; duke@1: duke@1: public abstract class SOAPFactoryImpl extends SOAPFactory { duke@1: duke@1: protected static Logger duke@1: log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN, duke@1: "com.sun.xml.internal.messaging.saaj.soap.LocalStrings"); duke@1: duke@1: protected abstract SOAPDocumentImpl createDocument(); duke@1: duke@1: public SOAPElement createElement(String tagName) throws SOAPException { duke@1: if (tagName == null) { duke@1: log.log( duke@1: Level.SEVERE,"SAAJ0567.soap.null.input", duke@1: new Object[] {"tagName","SOAPFactory.createElement"}); duke@1: throw new SOAPException("Null tagName argument passed to createElement"); duke@1: } duke@1: return ElementFactory.createElement(createDocument(), duke@1: NameImpl.createFromTagName(tagName)); duke@1: } duke@1: duke@1: public SOAPElement createElement(Name name) throws SOAPException { duke@1: // @since SAAJ 1.3 duke@1: // If the Name was null it would cause a NullPointerException in earlier release duke@1: if (name == null) { duke@1: log.log(Level.SEVERE,"SAAJ0567.soap.null.input", duke@1: new Object[] {"name","SOAPFactory.createElement"}); duke@1: throw new SOAPException("Null name argument passed to createElement"); duke@1: } duke@1: return ElementFactory.createElement(createDocument(), name); duke@1: } duke@1: duke@1: public SOAPElement createElement(QName qname) throws SOAPException { duke@1: if (qname == null) { duke@1: log.log(Level.SEVERE,"SAAJ0567.soap.null.input", duke@1: new Object[] {"qname","SOAPFactory.createElement"}); duke@1: throw new SOAPException("Null qname argument passed to createElement"); duke@1: } duke@1: return ElementFactory.createElement(createDocument(),qname); duke@1: } duke@1: duke@1: public SOAPElement createElement( duke@1: String localName, duke@1: String prefix, duke@1: String uri) throws SOAPException { duke@1: duke@1: // @since SAAJ 1.3 duke@1: // if prefix !=null but localName== null then in earlier releases it would create duke@1: // a Qualified Name :null which is not meaningful duke@1: if (localName == null) { duke@1: log.log(Level.SEVERE,"SAAJ0567.soap.null.input", duke@1: new Object[] {"localName","SOAPFactory.createElement"}); duke@1: throw new SOAPException("Null localName argument passed to createElement"); duke@1: } duke@1: return ElementFactory.createElement(createDocument(), localName, prefix, uri); duke@1: } duke@1: duke@1: public Name createName(String localName, String prefix, String uri) duke@1: throws SOAPException { duke@1: // @since SAAJ 1.3 duke@1: // if localName==null, earlier impl would create Name with localName="" duke@1: // which is absurd. duke@1: if (localName == null) { duke@1: log.log( duke@1: Level.SEVERE,"SAAJ0567.soap.null.input", duke@1: new Object[] {"localName","SOAPFactory.createName"}); duke@1: throw new SOAPException("Null localName argument passed to createName"); duke@1: } duke@1: return NameImpl.create(localName, prefix, uri); duke@1: } duke@1: duke@1: public Name createName(String localName) throws SOAPException { duke@1: // @since SAAJ 1.3 duke@1: // if localName==null, earlier impl would create Name with localName=null duke@1: // which is absurd. duke@1: if (localName == null) { duke@1: log.log( duke@1: Level.SEVERE,"SAAJ0567.soap.null.input", duke@1: new Object[] {"localName","SOAPFactory.createName"}); duke@1: throw new SOAPException("Null localName argument passed to createName"); duke@1: } duke@1: return NameImpl.createFromUnqualifiedName(localName); duke@1: } duke@1: duke@1: // Note: the child elements might still be org.w3c.dom.Element's, but the duke@1: // getChildElements will do the conversion to SOAPElement when called. duke@1: public SOAPElement createElement(Element domElement) throws SOAPException { duke@1: if (domElement == null) { duke@1: return null; duke@1: } duke@1: return convertToSoapElement(domElement); duke@1: } duke@1: duke@1: private SOAPElement convertToSoapElement(Element element) throws SOAPException { duke@1: duke@1: if (element instanceof SOAPElement) { duke@1: return (SOAPElement) element; duke@1: } duke@1: duke@1: SOAPElement copy = createElement( duke@1: element.getLocalName(), duke@1: element.getPrefix(), duke@1: element.getNamespaceURI()); duke@1: duke@1: Document ownerDoc = copy.getOwnerDocument(); duke@1: duke@1: NamedNodeMap attrMap = element.getAttributes(); duke@1: for (int i=0; i < attrMap.getLength(); i++) { duke@1: Attr nextAttr = (Attr)attrMap.item(i); duke@1: Attr importedAttr = (Attr)ownerDoc.importNode(nextAttr, true); duke@1: copy.setAttributeNodeNS(importedAttr); duke@1: } duke@1: duke@1: duke@1: NodeList nl = element.getChildNodes(); duke@1: for (int i=0; i < nl.getLength(); i++) { duke@1: org.w3c.dom.Node next = nl.item(i); duke@1: org.w3c.dom.Node imported = ownerDoc.importNode(next, true); duke@1: copy.appendChild(imported); duke@1: } duke@1: duke@1: return copy; duke@1: } duke@1: duke@1: public Detail createDetail() throws SOAPException { duke@1: throw new UnsupportedOperationException(); duke@1: } duke@1: duke@1: public SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException { duke@1: throw new UnsupportedOperationException(); duke@1: } duke@1: duke@1: public SOAPFault createFault() throws SOAPException { duke@1: throw new UnsupportedOperationException(); duke@1: } duke@1: duke@1: }