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.axiom;
18  
19  import java.util.Iterator;
20  import javax.xml.namespace.QName;
21  import javax.xml.transform.Result;
22  
23  import org.springframework.ws.soap.SoapFaultDetail;
24  import org.springframework.ws.soap.SoapFaultDetailElement;
25  
26  import org.apache.axiom.om.OMElement;
27  import org.apache.axiom.om.OMException;
28  import org.apache.axiom.soap.SOAPFactory;
29  import org.apache.axiom.soap.SOAPFaultDetail;
30  
31  /**
32   * Axiom-specific version of <code>org.springframework.ws.soap.SoapFaultDetail</code>.
33   *
34   * @author Arjen Poutsma
35   * @since 1.0.0
36   */
37  class AxiomSoapFaultDetail extends AxiomSoapElement implements SoapFaultDetail {
38  
39      public AxiomSoapFaultDetail(SOAPFaultDetail axiomFaultDetail, SOAPFactory axiomFactory) {
40          super(axiomFaultDetail, axiomFactory);
41      }
42  
43      public SoapFaultDetailElement addFaultDetailElement(QName name) {
44          try {
45              OMElement element = getAxiomFactory().createOMElement(name, getAxiomFaultDetail());
46              return new AxiomSoapFaultDetailElement(element, getAxiomFactory());
47          }
48          catch (OMException ex) {
49              throw new AxiomSoapFaultException(ex);
50          }
51  
52      }
53  
54      public Iterator<SoapFaultDetailElement> getDetailEntries() {
55          return new AxiomSoapFaultDetailElementIterator(getAxiomFaultDetail().getChildElements());
56      }
57  
58      public Result getResult() {
59          return new AxiomResult(getAxiomFaultDetail(), getAxiomFactory());
60      }
61  
62      protected SOAPFaultDetail getAxiomFaultDetail() {
63          return (SOAPFaultDetail) getAxiomElement();
64      }
65  
66      private class AxiomSoapFaultDetailElementIterator implements Iterator<SoapFaultDetailElement> {
67  
68          private final Iterator<OMElement> axiomIterator;
69  
70          private AxiomSoapFaultDetailElementIterator(Iterator<OMElement> axiomIterator) {
71              this.axiomIterator = axiomIterator;
72          }
73  
74          public boolean hasNext() {
75              return axiomIterator.hasNext();
76          }
77  
78          public SoapFaultDetailElement next() {
79              try {
80                  OMElement axiomElement = axiomIterator.next();
81                  return new AxiomSoapFaultDetailElement(axiomElement, getAxiomFactory());
82              }
83              catch (OMException ex) {
84                  throw new AxiomSoapFaultException(ex);
85              }
86  
87          }
88  
89          public void remove() {
90              axiomIterator.remove();
91          }
92      }
93  
94  }