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/ver1_1/Fault1_1Impl.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,387 @@ 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 +/** 1.30 +* 1.31 +* @author SAAJ RI Development Team 1.32 +*/ 1.33 +package com.sun.xml.internal.messaging.saaj.soap.ver1_1; 1.34 + 1.35 +import java.util.Iterator; 1.36 +import java.util.Locale; 1.37 +import java.util.logging.Logger; 1.38 +import java.util.logging.Level; 1.39 + 1.40 +import javax.xml.namespace.QName; 1.41 +import javax.xml.soap.SOAPElement; 1.42 +import javax.xml.soap.SOAPFaultElement; 1.43 +import javax.xml.soap.SOAPException; 1.44 +import javax.xml.soap.SOAPConstants; 1.45 +import javax.xml.soap.Name; 1.46 +import javax.xml.soap.Name; 1.47 + 1.48 +import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument; 1.49 +import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; 1.50 +import com.sun.xml.internal.messaging.saaj.soap.impl.*; 1.51 +import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; 1.52 +import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants; 1.53 +import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; 1.54 + 1.55 + 1.56 +public class Fault1_1Impl extends FaultImpl { 1.57 + 1.58 + protected static final Logger log = 1.59 + Logger.getLogger( 1.60 + LogDomainConstants.SOAP_VER1_1_DOMAIN, 1.61 + "com.sun.xml.internal.messaging.saaj.soap.ver1_1.LocalStrings"); 1.62 + 1.63 + public Fault1_1Impl(SOAPDocumentImpl ownerDocument, String prefix) { 1.64 + super(ownerDocument, NameImpl.createFault1_1Name(prefix)); 1.65 + } 1.66 + 1.67 + protected NameImpl getDetailName() { 1.68 + return NameImpl.createDetail1_1Name(); 1.69 + } 1.70 + 1.71 + protected NameImpl getFaultCodeName() { 1.72 + return NameImpl.createFromUnqualifiedName("faultcode"); 1.73 + } 1.74 + 1.75 + protected NameImpl getFaultStringName() { 1.76 + return NameImpl.createFromUnqualifiedName("faultstring"); 1.77 + } 1.78 + 1.79 + protected NameImpl getFaultActorName() { 1.80 + return NameImpl.createFromUnqualifiedName("faultactor"); 1.81 + } 1.82 + 1.83 + protected DetailImpl createDetail() { 1.84 + return new Detail1_1Impl( 1.85 + ((SOAPDocument) getOwnerDocument()).getDocument()); 1.86 + } 1.87 + 1.88 + protected FaultElementImpl createSOAPFaultElement(String localName) { 1.89 + return new FaultElement1_1Impl( 1.90 + ((SOAPDocument) getOwnerDocument()).getDocument(), 1.91 + localName); 1.92 + } 1.93 + 1.94 + protected void checkIfStandardFaultCode(String faultCode, String uri) 1.95 + throws SOAPException { 1.96 + // SOAP 1.1 doesn't seem to mandate using faultcode from a particular 1.97 + // set of values. 1.98 + // Also need to be backward compatible. 1.99 + } 1.100 + 1.101 + protected void finallySetFaultCode(String faultcode) throws SOAPException { 1.102 + this.faultCodeElement.addTextNode(faultcode); 1.103 + } 1.104 + 1.105 + public String getFaultCode() { 1.106 + if (this.faultCodeElement == null) 1.107 + findFaultCodeElement(); 1.108 + return this.faultCodeElement.getValue(); 1.109 + } 1.110 + 1.111 + public Name getFaultCodeAsName() { 1.112 + 1.113 + String faultcodeString = getFaultCode(); 1.114 + if (faultcodeString == null) { 1.115 + return null; 1.116 + } 1.117 + int prefixIndex = faultcodeString.indexOf(':'); 1.118 + if (prefixIndex == -1) { 1.119 + // Not a valid SOAP message, but we return the unqualified name 1.120 + // anyway since some apps do not strictly conform to SOAP 1.121 + // specs. A message that does not contain a <faultcode> 1.122 + // element itself is also not valid in which case we return 1.123 + // null instead of throwing an exception so this is consistent. 1.124 + return NameImpl.createFromUnqualifiedName(faultcodeString); 1.125 + } 1.126 + 1.127 + // Get the prefix and map it to a namespace name (AKA namespace URI) 1.128 + String prefix = faultcodeString.substring(0, prefixIndex); 1.129 + if (this.faultCodeElement == null) 1.130 + findFaultCodeElement(); 1.131 + String nsName = this.faultCodeElement.getNamespaceURI(prefix); 1.132 + return NameImpl.createFromQualifiedName(faultcodeString, nsName); 1.133 + } 1.134 + 1.135 + public QName getFaultCodeAsQName() { 1.136 + String faultcodeString = getFaultCode(); 1.137 + if (faultcodeString == null) { 1.138 + return null; 1.139 + } 1.140 + if (this.faultCodeElement == null) 1.141 + findFaultCodeElement(); 1.142 + return convertCodeToQName(faultcodeString, this.faultCodeElement); 1.143 + } 1.144 + 1.145 + public void setFaultString(String faultString) throws SOAPException { 1.146 + 1.147 + if (this.faultStringElement == null) 1.148 + findFaultStringElement(); 1.149 + 1.150 + if (this.faultStringElement == null) 1.151 + this.faultStringElement = addSOAPFaultElement("faultstring"); 1.152 + else { 1.153 + this.faultStringElement.removeContents(); 1.154 + //this.faultStringElement.removeAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"); 1.155 + this.faultStringElement.removeAttribute("xml:lang"); 1.156 + } 1.157 + 1.158 + this.faultStringElement.addTextNode(faultString); 1.159 + } 1.160 + 1.161 + public String getFaultString() { 1.162 + if (this.faultStringElement == null) 1.163 + findFaultStringElement(); 1.164 + return this.faultStringElement.getValue(); 1.165 + 1.166 + } 1.167 + 1.168 + public Locale getFaultStringLocale() { 1.169 + if (this.faultStringElement == null) 1.170 + findFaultStringElement(); 1.171 + if (this.faultStringElement != null) { 1.172 + String xmlLangAttr = 1.173 + this.faultStringElement.getAttributeValue( 1.174 + NameImpl.createFromUnqualifiedName("xml:lang")); 1.175 + if (xmlLangAttr != null) 1.176 + return xmlLangToLocale(xmlLangAttr); 1.177 + } 1.178 + return null; 1.179 + } 1.180 + 1.181 + public void setFaultString(String faultString, Locale locale) 1.182 + throws SOAPException { 1.183 + setFaultString(faultString); 1.184 + this.faultStringElement.addAttribute( 1.185 + NameImpl.createFromTagName("xml:lang"), 1.186 + localeToXmlLang(locale)); 1.187 + } 1.188 + 1.189 + protected boolean isStandardFaultElement(String localName) { 1.190 + if (localName.equalsIgnoreCase("detail") || 1.191 + localName.equalsIgnoreCase("faultcode") || 1.192 + localName.equalsIgnoreCase("faultstring") || 1.193 + localName.equalsIgnoreCase("faultactor")) { 1.194 + return true; 1.195 + } 1.196 + return false; 1.197 + } 1.198 + 1.199 + public void appendFaultSubcode(QName subcode) { 1.200 + log.log( 1.201 + Level.SEVERE, 1.202 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.203 + "appendFaultSubcode"); 1.204 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.205 + } 1.206 + 1.207 + public void removeAllFaultSubcodes() { 1.208 + log.log( 1.209 + Level.SEVERE, 1.210 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.211 + "removeAllFaultSubcodes"); 1.212 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.213 + } 1.214 + 1.215 + public Iterator getFaultSubcodes() { 1.216 + log.log( 1.217 + Level.SEVERE, 1.218 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.219 + "getFaultSubcodes"); 1.220 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.221 + } 1.222 + 1.223 + public String getFaultReasonText(Locale locale) { 1.224 + log.log( 1.225 + Level.SEVERE, 1.226 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.227 + "getFaultReasonText"); 1.228 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.229 + } 1.230 + 1.231 + public Iterator getFaultReasonTexts() { 1.232 + log.log( 1.233 + Level.SEVERE, 1.234 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.235 + "getFaultReasonTexts"); 1.236 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.237 + } 1.238 + 1.239 + public Iterator getFaultReasonLocales() { 1.240 + log.log( 1.241 + Level.SEVERE, 1.242 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.243 + "getFaultReasonLocales"); 1.244 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.245 + } 1.246 + 1.247 + public void addFaultReasonText(String text, java.util.Locale locale) 1.248 + throws SOAPException { 1.249 + log.log( 1.250 + Level.SEVERE, 1.251 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.252 + "addFaultReasonText"); 1.253 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.254 + } 1.255 + 1.256 + public String getFaultRole() { 1.257 + log.log( 1.258 + Level.SEVERE, 1.259 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.260 + "getFaultRole"); 1.261 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.262 + } 1.263 + 1.264 + public void setFaultRole(String uri) { 1.265 + log.log( 1.266 + Level.SEVERE, 1.267 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.268 + "setFaultRole"); 1.269 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.270 + } 1.271 + 1.272 + public String getFaultNode() { 1.273 + log.log( 1.274 + Level.SEVERE, 1.275 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.276 + "getFaultNode"); 1.277 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.278 + } 1.279 + 1.280 + public void setFaultNode(String uri) { 1.281 + log.log( 1.282 + Level.SEVERE, 1.283 + "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1", 1.284 + "setFaultNode"); 1.285 + throw new UnsupportedOperationException("Not supported in SOAP 1.1"); 1.286 + } 1.287 + 1.288 + protected QName getDefaultFaultCode() { 1.289 + return new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "Server"); 1.290 + } 1.291 + 1.292 + public SOAPElement addChildElement(SOAPElement element) 1.293 + throws SOAPException { 1.294 + String localName = element.getLocalName(); 1.295 + if ("Detail".equalsIgnoreCase(localName)) { 1.296 + if (hasDetail()) { 1.297 + log.severe("SAAJ0305.ver1_2.detail.exists.error"); 1.298 + throw new SOAPExceptionImpl("Cannot add Detail, Detail already exists"); 1.299 + } 1.300 + } 1.301 + return super.addChildElement(element); 1.302 + } 1.303 + 1.304 + protected FaultElementImpl createSOAPFaultElement(QName qname) { 1.305 + return new FaultElement1_1Impl( 1.306 + ((SOAPDocument) getOwnerDocument()).getDocument(), 1.307 + qname); 1.308 + } 1.309 + 1.310 + protected FaultElementImpl createSOAPFaultElement(Name qname) { 1.311 + return new FaultElement1_1Impl( 1.312 + ((SOAPDocument) getOwnerDocument()).getDocument(), 1.313 + (NameImpl)qname); 1.314 + } 1.315 + 1.316 + public void setFaultCode(String faultCode, String prefix, String uri) 1.317 + throws SOAPException { 1.318 + if (prefix == null || "".equals(prefix)) { 1.319 + if (uri != null && !"".equals(uri)) { 1.320 + prefix = getNamespacePrefix(uri); 1.321 + if (prefix == null || "".equals(prefix)) { 1.322 + prefix = "ns0"; 1.323 + } 1.324 + } 1.325 + } 1.326 + 1.327 + if (this.faultCodeElement == null) 1.328 + findFaultCodeElement(); 1.329 + 1.330 + if (this.faultCodeElement == null) 1.331 + this.faultCodeElement = addFaultCodeElement(); 1.332 + else 1.333 + this.faultCodeElement.removeContents(); 1.334 + 1.335 + if (uri == null || "".equals(uri)) { 1.336 + if (prefix != null && !"".equals("prefix")) { 1.337 + uri = this.faultCodeElement.getNamespaceURI(prefix); 1.338 + } 1.339 + } 1.340 + 1.341 + if (uri == null || "".equals(uri)) { 1.342 + if (prefix != null && !"".equals(prefix)) { 1.343 + //cannot allow an empty URI for a non-Empty prefix 1.344 + log.log(Level.SEVERE, "SAAJ0307.impl.no.ns.URI", new Object[]{prefix + ":" + faultCode}); 1.345 + throw new SOAPExceptionImpl("Empty/Null NamespaceURI specified for faultCode \"" + prefix + ":" + faultCode + "\""); 1.346 + } else { 1.347 + uri = ""; 1.348 + } 1.349 + } 1.350 + 1.351 + checkIfStandardFaultCode(faultCode, uri); 1.352 + ((FaultElementImpl) this.faultCodeElement).ensureNamespaceIsDeclared(prefix, uri); 1.353 + 1.354 + if (prefix == null || "".equals(prefix)) { 1.355 + finallySetFaultCode(faultCode); 1.356 + } else { 1.357 + finallySetFaultCode(prefix + ":" + faultCode); 1.358 + } 1.359 + } 1.360 + 1.361 + private boolean standardFaultCode(String faultCode) { 1.362 + if (faultCode.equals("VersionMismatch") || faultCode.equals("MustUnderstand") 1.363 + || faultCode.equals("Client") || faultCode.equals("Server")) { 1.364 + return true; 1.365 + } 1.366 + if (faultCode.startsWith("VersionMismatch.") || faultCode.startsWith("MustUnderstand.") 1.367 + || faultCode.startsWith("Client.") || faultCode.startsWith("Server.")) { 1.368 + return true; 1.369 + } 1.370 + return false; 1.371 + } 1.372 + 1.373 + public void setFaultActor(String faultActor) throws SOAPException { 1.374 + if (this.faultActorElement == null) 1.375 + findFaultActorElement(); 1.376 + if (this.faultActorElement != null) 1.377 + this.faultActorElement.detachNode(); 1.378 + if (faultActor == null) 1.379 + return; 1.380 + this.faultActorElement = 1.381 + createSOAPFaultElement(getFaultActorName()); 1.382 + this.faultActorElement.addTextNode(faultActor); 1.383 + if (hasDetail()) { 1.384 + insertBefore(this.faultActorElement, this.detail); 1.385 + return; 1.386 + } 1.387 + addNode(this.faultActorElement); 1.388 + 1.389 + } 1.390 +}