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