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