View Javadoc

1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.saaj;
18  
19  import java.util.Iterator;
20  import javax.xml.namespace.QName;
21  import javax.xml.soap.Detail;
22  import javax.xml.soap.DetailEntry;
23  import javax.xml.soap.SOAPException;
24  import javax.xml.soap.SOAPFaultElement;
25  import javax.xml.transform.Result;
26  
27  import org.springframework.util.Assert;
28  import org.springframework.ws.soap.SoapFaultDetail;
29  import org.springframework.ws.soap.SoapFaultDetailElement;
30  
31  /**
32   * SAAJ-specific implementation of the <code>SoapFaultDetail</code> interface. Wraps a {@link
33   * javax.xml.soap.SOAPFaultElement}.
34   *
35   * @author Arjen Poutsma
36   * @since 1.0.0
37   */
38  class SaajSoapFaultDetail extends SaajSoapElement<SOAPFaultElement> implements SoapFaultDetail {
39  
40      public SaajSoapFaultDetail(SOAPFaultElement faultElement) {
41          super(faultElement);
42      }
43  
44      public Result getResult() {
45          return getImplementation().getResult(getSaajDetail());
46      }
47  
48      public SoapFaultDetailElement addFaultDetailElement(QName name) {
49          try {
50              DetailEntry detailEntry = getImplementation().addDetailEntry(getSaajDetail(), name);
51              return new SaajSoapFaultDetailElement(detailEntry);
52          }
53          catch (SOAPException ex) {
54              throw new SaajSoapFaultException(ex);
55          }
56      }
57  
58      public Iterator<SoapFaultDetailElement> getDetailEntries() {
59          Iterator<DetailEntry> iterator = getImplementation().getDetailEntries(getSaajDetail());
60          return new SaajSoapFaultDetailElementIterator(iterator);
61      }
62  
63      protected Detail getSaajDetail() {
64          return (Detail) getSaajElement();
65      }
66  
67      private static class SaajSoapFaultDetailElementIterator implements Iterator<SoapFaultDetailElement> {
68  
69          private final Iterator<DetailEntry> iterator;
70  
71          private SaajSoapFaultDetailElementIterator(Iterator<DetailEntry> iterator) {
72              Assert.notNull(iterator, "No iterator given");
73              this.iterator = iterator;
74          }
75  
76          public boolean hasNext() {
77              return iterator.hasNext();
78          }
79  
80          public SoapFaultDetailElement next() {
81              DetailEntry saajDetailEntry = iterator.next();
82              return new SaajSoapFaultDetailElement(saajDetailEntry);
83          }
84  
85          public void remove() {
86              iterator.remove();
87          }
88      }
89  
90  
91  }