src/share/classes/com/sun/xml/internal/messaging/saaj/soap/ver1_1/Fault1_1Impl.java

Mon, 04 May 2009 21:10:41 -0700

author
tbell
date
Mon, 04 May 2009 21:10:41 -0700
changeset 50
42dfec6871f6
parent 45
31822b475baa
child 78
860b95cc8d1d
permissions
-rw-r--r--

6658158: Mutable statics in SAAJ (findbugs)
6658163: txw2.DatatypeWriter.BUILDIN is a mutable static (findbugs)
Reviewed-by: darcy

     1 /*
     2  * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    25 /*
    26  *
    27  */
    31 /**
    32 *
    33 * @author SAAJ RI Development Team
    34 */
    35 package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
    37 import java.util.Iterator;
    38 import java.util.Locale;
    39 import java.util.logging.Logger;
    40 import java.util.logging.Level;
    42 import javax.xml.namespace.QName;
    43 import javax.xml.soap.SOAPElement;
    44 import javax.xml.soap.SOAPFaultElement;
    45 import javax.xml.soap.SOAPException;
    46 import javax.xml.soap.SOAPConstants;
    47 import javax.xml.soap.Name;
    48 import javax.xml.soap.Name;
    50 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
    51 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
    52 import com.sun.xml.internal.messaging.saaj.soap.impl.*;
    53 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
    54 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
    55 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    58 public class Fault1_1Impl extends FaultImpl {
    60     protected static final Logger log =
    61         Logger.getLogger(
    62             LogDomainConstants.SOAP_VER1_1_DOMAIN,
    63             "com.sun.xml.internal.messaging.saaj.soap.ver1_1.LocalStrings");
    65     public Fault1_1Impl(SOAPDocumentImpl ownerDocument, String prefix) {
    66        super(ownerDocument, NameImpl.createFault1_1Name(prefix));
    67     }
    69     protected NameImpl getDetailName() {
    70         return NameImpl.createDetail1_1Name();
    71     }
    73     protected NameImpl getFaultCodeName() {
    74         return NameImpl.createFromUnqualifiedName("faultcode");
    75     }
    77     protected NameImpl getFaultStringName() {
    78         return NameImpl.createFromUnqualifiedName("faultstring");
    79     }
    81     protected NameImpl getFaultActorName() {
    82         return NameImpl.createFromUnqualifiedName("faultactor");
    83     }
    85     protected DetailImpl createDetail() {
    86         return new Detail1_1Impl(
    87                        ((SOAPDocument) getOwnerDocument()).getDocument());
    88     }
    90     protected FaultElementImpl createSOAPFaultElement(String localName) {
    91         return new FaultElement1_1Impl(
    92                        ((SOAPDocument) getOwnerDocument()).getDocument(),
    93                        localName);
    94     }
    96     protected void checkIfStandardFaultCode(String faultCode, String uri)
    97         throws SOAPException {
    98         // SOAP 1.1 doesn't seem to mandate using faultcode from a particular
    99         // set of values.
   100         // Also need to be backward compatible.
   101     }
   103     protected void finallySetFaultCode(String faultcode) throws SOAPException {
   104         this.faultCodeElement.addTextNode(faultcode);
   105     }
   107     public String getFaultCode() {
   108         if (this.faultCodeElement == null)
   109             findFaultCodeElement();
   110         return this.faultCodeElement.getValue();
   111     }
   113     public Name getFaultCodeAsName() {
   115         String faultcodeString = getFaultCode();
   116         if (faultcodeString == null) {
   117             return null;
   118         }
   119         int prefixIndex = faultcodeString.indexOf(':');
   120         if (prefixIndex == -1) {
   121             // Not a valid SOAP message, but we return the unqualified name
   122             // anyway since some apps do not strictly conform to SOAP
   123             // specs.  A message that does not contain a <faultcode>
   124             // element itself is also not valid in which case we return
   125             // null instead of throwing an exception so this is consistent.
   126             return NameImpl.createFromUnqualifiedName(faultcodeString);
   127         }
   129         // Get the prefix and map it to a namespace name (AKA namespace URI)
   130         String prefix = faultcodeString.substring(0, prefixIndex);
   131         if (this.faultCodeElement == null)
   132             findFaultCodeElement();
   133         String nsName = this.faultCodeElement.getNamespaceURI(prefix);
   134         return NameImpl.createFromQualifiedName(faultcodeString, nsName);
   135     }
   137     public QName getFaultCodeAsQName() {
   138         String faultcodeString = getFaultCode();
   139         if (faultcodeString == null) {
   140             return null;
   141         }
   142         if (this.faultCodeElement == null)
   143             findFaultCodeElement();
   144         return convertCodeToQName(faultcodeString, this.faultCodeElement);
   145     }
   147     public void setFaultString(String faultString) throws SOAPException {
   149         if (this.faultStringElement == null)
   150             findFaultStringElement();
   152         if (this.faultStringElement == null)
   153             this.faultStringElement = addSOAPFaultElement("faultstring");
   154         else {
   155             this.faultStringElement.removeContents();
   156             //this.faultStringElement.removeAttributeNS("http://www.w3.org/XML/1998/namespace", "lang");
   157             this.faultStringElement.removeAttribute("xml:lang");
   158         }
   160         this.faultStringElement.addTextNode(faultString);
   161     }
   163     public String getFaultString() {
   164         if (this.faultStringElement == null)
   165             findFaultStringElement();
   166         return this.faultStringElement.getValue();
   168     }
   170     public Locale getFaultStringLocale() {
   171         if (this.faultStringElement == null)
   172             findFaultStringElement();
   173         if (this.faultStringElement != null) {
   174             String xmlLangAttr =
   175                 this.faultStringElement.getAttributeValue(
   176                     NameImpl.createFromUnqualifiedName("xml:lang"));
   177             if (xmlLangAttr != null)
   178                 return xmlLangToLocale(xmlLangAttr);
   179         }
   180         return null;
   181     }
   183     public void setFaultString(String faultString, Locale locale)
   184         throws SOAPException {
   185         setFaultString(faultString);
   186         this.faultStringElement.addAttribute(
   187             NameImpl.createFromTagName("xml:lang"),
   188             localeToXmlLang(locale));
   189     }
   191     protected boolean isStandardFaultElement(String localName) {
   192         if (localName.equalsIgnoreCase("detail") ||
   193             localName.equalsIgnoreCase("faultcode") ||
   194             localName.equalsIgnoreCase("faultstring") ||
   195             localName.equalsIgnoreCase("faultactor")) {
   196             return true;
   197         }
   198         return false;
   199     }
   201     public void appendFaultSubcode(QName subcode) {
   202         log.log(
   203             Level.SEVERE,
   204             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   205             "appendFaultSubcode");
   206         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   207     }
   209     public void removeAllFaultSubcodes() {
   210         log.log(
   211             Level.SEVERE,
   212             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   213             "removeAllFaultSubcodes");
   214         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   215     }
   217     public Iterator getFaultSubcodes() {
   218         log.log(
   219             Level.SEVERE,
   220             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   221             "getFaultSubcodes");
   222         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   223     }
   225     public String getFaultReasonText(Locale locale) {
   226         log.log(
   227             Level.SEVERE,
   228             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   229             "getFaultReasonText");
   230         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   231     }
   233     public Iterator getFaultReasonTexts() {
   234         log.log(
   235             Level.SEVERE,
   236             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   237             "getFaultReasonTexts");
   238         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   239     }
   241     public Iterator getFaultReasonLocales() {
   242         log.log(
   243             Level.SEVERE,
   244             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   245             "getFaultReasonLocales");
   246         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   247     }
   249     public void addFaultReasonText(String text, java.util.Locale locale)
   250         throws SOAPException {
   251         log.log(
   252             Level.SEVERE,
   253             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   254             "addFaultReasonText");
   255         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   256     }
   258     public String getFaultRole() {
   259         log.log(
   260             Level.SEVERE,
   261             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   262             "getFaultRole");
   263         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   264     }
   266     public void setFaultRole(String uri) {
   267         log.log(
   268             Level.SEVERE,
   269             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   270             "setFaultRole");
   271         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   272     }
   274     public String getFaultNode() {
   275         log.log(
   276             Level.SEVERE,
   277             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   278             "getFaultNode");
   279         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   280     }
   282     public void setFaultNode(String uri) {
   283         log.log(
   284             Level.SEVERE,
   285             "SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
   286             "setFaultNode");
   287         throw new UnsupportedOperationException("Not supported in SOAP 1.1");
   288     }
   290     protected QName getDefaultFaultCode() {
   291         return new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "Server");
   292     }
   294     public SOAPElement addChildElement(SOAPElement element)
   295         throws SOAPException {
   296         String localName = element.getLocalName();
   297         if ("Detail".equalsIgnoreCase(localName)) {
   298             if (hasDetail()) {
   299                 log.severe("SAAJ0305.ver1_2.detail.exists.error");
   300                 throw new SOAPExceptionImpl("Cannot add Detail, Detail already exists");
   301             }
   302         }
   303         return super.addChildElement(element);
   304     }
   306     protected FaultElementImpl createSOAPFaultElement(QName qname) {
   307          return new FaultElement1_1Impl(
   308                        ((SOAPDocument) getOwnerDocument()).getDocument(),
   309                        qname);
   310     }
   312     protected FaultElementImpl createSOAPFaultElement(Name qname) {
   313          return new FaultElement1_1Impl(
   314                        ((SOAPDocument) getOwnerDocument()).getDocument(),
   315                        (NameImpl)qname);
   316     }
   318 }

mercurial