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