< prev index next >

src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/soap/ver1_2/Fault1_2Impl.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 129             "SAAJ0435.ver1_2.code.not.standard",
 130             qname);
 131         throw new SOAPExceptionImpl(qname + " is not a standard Code value");
 132     }
 133 
 134     protected void finallySetFaultCode(String faultcode) throws SOAPException {
 135         SOAPElement value = this.faultCodeElement.addChildElement(valueName);
 136         value.addTextNode(faultcode);
 137     }
 138 
 139     private void findReasonElement() {
 140         findFaultStringElement();
 141     }
 142 
 143     public Iterator getFaultReasonTexts() throws SOAPException {
 144         // Fault Reason has similar semantics as faultstring
 145         if (this.faultStringElement == null)
 146             findReasonElement();
 147         Iterator eachTextElement =
 148             this.faultStringElement.getChildElements(textName);
 149         List texts = new ArrayList();
 150         while (eachTextElement.hasNext()) {
 151             SOAPElement textElement = (SOAPElement) eachTextElement.next();
 152             Locale thisLocale = getLocale(textElement);
 153             if (thisLocale == null) {
 154                 log.severe("SAAJ0431.ver1_2.xml.lang.missing");
 155                 throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
 156             }
 157             texts.add(textElement.getValue());
 158         }
 159         if (texts.isEmpty()) {
 160             log.severe("SAAJ0434.ver1_2.text.element.not.present");
 161             throw new SOAPExceptionImpl("env:Text must be present inside env:Reason");
 162         }
 163         return texts.iterator();
 164     }
 165 
 166     public void addFaultReasonText(String text, java.util.Locale locale)
 167         throws SOAPException {
 168 
 169         if (locale == null) {


 218         if (this.faultStringElement == null)
 219             findReasonElement();
 220 
 221         if (this.faultStringElement != null) {
 222             SOAPElement textElement = getFaultReasonTextElement(locale);
 223             if (textElement != null) {
 224                 textElement.normalize();
 225                 return textElement.getFirstChild().getNodeValue();
 226             }
 227         }
 228 
 229         return null;
 230     }
 231 
 232     public Iterator getFaultReasonLocales() throws SOAPException {
 233         // Fault Reason has similar semantics as faultstring
 234         if (this.faultStringElement == null)
 235             findReasonElement();
 236         Iterator eachTextElement =
 237             this.faultStringElement.getChildElements(textName);
 238         List localeSet = new ArrayList();
 239         while (eachTextElement.hasNext()) {
 240             SOAPElement textElement = (SOAPElement) eachTextElement.next();
 241             Locale thisLocale = getLocale(textElement);
 242             if (thisLocale == null) {
 243                 log.severe("SAAJ0431.ver1_2.xml.lang.missing");
 244                 throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
 245             }
 246             localeSet.add(thisLocale);
 247         }
 248         if (localeSet.isEmpty()) {
 249             log.severe("SAAJ0434.ver1_2.text.element.not.present");
 250             throw new SOAPExceptionImpl("env:Text elements with mandatory xml:lang attributes must be present inside env:Reason");
 251         }
 252         return localeSet.iterator();
 253     }
 254 
 255     public Locale getFaultStringLocale() {
 256         Locale locale = null;
 257         try {
 258             locale = (Locale) getFaultReasonLocales().next();


 418         ((ElementImpl) subcodeValueElement).ensureNamespaceIsDeclared(
 419             prefix,
 420             subcode.getNamespaceURI());
 421         subcodeValueElement.addTextNode(prefix + ":" + subcode.getLocalPart());
 422     }
 423 
 424     public void removeAllFaultSubcodes() {
 425         if (this.faultCodeElement == null)
 426             findFaultCodeElement();
 427         Iterator subcodeElements =
 428             this.faultCodeElement.getChildElements(subcodeName);
 429         if (subcodeElements.hasNext()) {
 430             SOAPElement subcode = (SOAPElement) subcodeElements.next();
 431             subcode.detachNode();
 432         }
 433     }
 434 
 435     public Iterator getFaultSubcodes() {
 436         if (this.faultCodeElement == null)
 437             findFaultCodeElement();
 438         final List subcodeList = new ArrayList();
 439         SOAPElement currentCodeElement = this.faultCodeElement;
 440         Iterator subcodeElements =
 441             currentCodeElement.getChildElements(subcodeName);
 442         while (subcodeElements.hasNext()) {
 443             currentCodeElement = (ElementImpl) subcodeElements.next();
 444             Iterator valueElements =
 445                 currentCodeElement.getChildElements(valueName);
 446             SOAPElement valueElement = (SOAPElement) valueElements.next();
 447             String code = valueElement.getValue();
 448             subcodeList.add(convertCodeToQName(code, valueElement));
 449             subcodeElements = currentCodeElement.getChildElements(subcodeName);
 450         }
 451         //return subcodeList.iterator();
 452         return new Iterator() {
 453             Iterator subCodeIter = subcodeList.iterator();
 454 
 455             public boolean hasNext() {
 456                 return subCodeIter.hasNext();
 457             }
 458 
 459             public Object next() {
 460                 return subCodeIter.next();
 461             }
 462 
 463             public void remove() {
 464                 throw new UnsupportedOperationException(
 465                     "Method remove() not supported on SubCodes Iterator");
 466             }
 467         };
 468     }
 469 
 470     private static Locale getLocale(SOAPElement reasonText) {
 471         return xmlLangToLocale(reasonText.getAttributeValue(getXmlLangName()));
 472     }
 473 
 474     /*
 475      * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
 476      * attribute to SOAP Fault (SOAP 1.2 spec, part 1, section 5.1.1)
 477      */
 478     public void setEncodingStyle(String encodingStyle) throws SOAPException {
 479         log.severe("SAAJ0407.ver1_2.no.encodingStyle.in.fault");


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 129             "SAAJ0435.ver1_2.code.not.standard",
 130             qname);
 131         throw new SOAPExceptionImpl(qname + " is not a standard Code value");
 132     }
 133 
 134     protected void finallySetFaultCode(String faultcode) throws SOAPException {
 135         SOAPElement value = this.faultCodeElement.addChildElement(valueName);
 136         value.addTextNode(faultcode);
 137     }
 138 
 139     private void findReasonElement() {
 140         findFaultStringElement();
 141     }
 142 
 143     public Iterator getFaultReasonTexts() throws SOAPException {
 144         // Fault Reason has similar semantics as faultstring
 145         if (this.faultStringElement == null)
 146             findReasonElement();
 147         Iterator eachTextElement =
 148             this.faultStringElement.getChildElements(textName);
 149         List<String> texts = new ArrayList<String>();
 150         while (eachTextElement.hasNext()) {
 151             SOAPElement textElement = (SOAPElement) eachTextElement.next();
 152             Locale thisLocale = getLocale(textElement);
 153             if (thisLocale == null) {
 154                 log.severe("SAAJ0431.ver1_2.xml.lang.missing");
 155                 throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
 156             }
 157             texts.add(textElement.getValue());
 158         }
 159         if (texts.isEmpty()) {
 160             log.severe("SAAJ0434.ver1_2.text.element.not.present");
 161             throw new SOAPExceptionImpl("env:Text must be present inside env:Reason");
 162         }
 163         return texts.iterator();
 164     }
 165 
 166     public void addFaultReasonText(String text, java.util.Locale locale)
 167         throws SOAPException {
 168 
 169         if (locale == null) {


 218         if (this.faultStringElement == null)
 219             findReasonElement();
 220 
 221         if (this.faultStringElement != null) {
 222             SOAPElement textElement = getFaultReasonTextElement(locale);
 223             if (textElement != null) {
 224                 textElement.normalize();
 225                 return textElement.getFirstChild().getNodeValue();
 226             }
 227         }
 228 
 229         return null;
 230     }
 231 
 232     public Iterator getFaultReasonLocales() throws SOAPException {
 233         // Fault Reason has similar semantics as faultstring
 234         if (this.faultStringElement == null)
 235             findReasonElement();
 236         Iterator eachTextElement =
 237             this.faultStringElement.getChildElements(textName);
 238         List<Locale> localeSet = new ArrayList<Locale>();
 239         while (eachTextElement.hasNext()) {
 240             SOAPElement textElement = (SOAPElement) eachTextElement.next();
 241             Locale thisLocale = getLocale(textElement);
 242             if (thisLocale == null) {
 243                 log.severe("SAAJ0431.ver1_2.xml.lang.missing");
 244                 throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
 245             }
 246             localeSet.add(thisLocale);
 247         }
 248         if (localeSet.isEmpty()) {
 249             log.severe("SAAJ0434.ver1_2.text.element.not.present");
 250             throw new SOAPExceptionImpl("env:Text elements with mandatory xml:lang attributes must be present inside env:Reason");
 251         }
 252         return localeSet.iterator();
 253     }
 254 
 255     public Locale getFaultStringLocale() {
 256         Locale locale = null;
 257         try {
 258             locale = (Locale) getFaultReasonLocales().next();


 418         ((ElementImpl) subcodeValueElement).ensureNamespaceIsDeclared(
 419             prefix,
 420             subcode.getNamespaceURI());
 421         subcodeValueElement.addTextNode(prefix + ":" + subcode.getLocalPart());
 422     }
 423 
 424     public void removeAllFaultSubcodes() {
 425         if (this.faultCodeElement == null)
 426             findFaultCodeElement();
 427         Iterator subcodeElements =
 428             this.faultCodeElement.getChildElements(subcodeName);
 429         if (subcodeElements.hasNext()) {
 430             SOAPElement subcode = (SOAPElement) subcodeElements.next();
 431             subcode.detachNode();
 432         }
 433     }
 434 
 435     public Iterator getFaultSubcodes() {
 436         if (this.faultCodeElement == null)
 437             findFaultCodeElement();
 438         final List<QName> subcodeList = new ArrayList<QName>();
 439         SOAPElement currentCodeElement = this.faultCodeElement;
 440         Iterator subcodeElements =
 441             currentCodeElement.getChildElements(subcodeName);
 442         while (subcodeElements.hasNext()) {
 443             currentCodeElement = (ElementImpl) subcodeElements.next();
 444             Iterator valueElements =
 445                 currentCodeElement.getChildElements(valueName);
 446             SOAPElement valueElement = (SOAPElement) valueElements.next();
 447             String code = valueElement.getValue();
 448             subcodeList.add(convertCodeToQName(code, valueElement));
 449             subcodeElements = currentCodeElement.getChildElements(subcodeName);
 450         }
 451         //return subcodeList.iterator();
 452         return new Iterator<QName>() {
 453             Iterator<QName> subCodeIter = subcodeList.iterator();
 454 
 455             public boolean hasNext() {
 456                 return subCodeIter.hasNext();
 457             }
 458 
 459             public QName next() {
 460                 return subCodeIter.next();
 461             }
 462 
 463             public void remove() {
 464                 throw new UnsupportedOperationException(
 465                     "Method remove() not supported on SubCodes Iterator");
 466             }
 467         };
 468     }
 469 
 470     private static Locale getLocale(SOAPElement reasonText) {
 471         return xmlLangToLocale(reasonText.getAttributeValue(getXmlLangName()));
 472     }
 473 
 474     /*
 475      * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
 476      * attribute to SOAP Fault (SOAP 1.2 spec, part 1, section 5.1.1)
 477      */
 478     public void setEncodingStyle(String encodingStyle) throws SOAPException {
 479         log.severe("SAAJ0407.ver1_2.no.encodingStyle.in.fault");


< prev index next >