View Javadoc

1   /*
2    * Copyright 2007 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.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  import javax.xml.soap.Node;
23  import javax.xml.soap.SOAPConstants;
24  import javax.xml.soap.SOAPHeader;
25  import javax.xml.soap.SOAPHeaderElement;
26  
27  import org.springframework.util.ObjectUtils;
28  import org.springframework.util.StringUtils;
29  import org.springframework.ws.soap.soap11.Soap11Header;
30  
31  /**
32   * SAAJ-specific implementation of the <code>Soap11Header</code> interface. Wraps a {@link javax.xml.soap.SOAPHeader}.
33   *
34   * @author Arjen Poutsma
35   * @since 1.0.0
36   */
37  class SaajSoap11Header extends SaajSoapHeader implements Soap11Header {
38  
39      SaajSoap11Header(SOAPHeader header) {
40          super(header);
41      }
42  
43      public Iterator examineHeaderElementsToProcess(String[] actors) {
44          List result = new ArrayList();
45          Iterator iterator = getImplementation().examineAllHeaderElements(getSaajHeader());
46          while (iterator.hasNext()) {
47              Node node = (Node) iterator.next();
48              if (node instanceof SOAPHeaderElement) {
49                  SOAPHeaderElement saajHeaderElement = (SOAPHeaderElement) node;
50                  String headerActor = saajHeaderElement.getActor();
51                  if (shouldProcess(headerActor, actors)) {
52                      result.add(saajHeaderElement);
53                  }
54              }
55          }
56          return new SaajSoapHeaderElementIterator(result.iterator());
57      }
58  
59      private boolean shouldProcess(String headerActor, String[] actors) {
60          if (!StringUtils.hasLength(headerActor)) {
61              return true;
62          }
63          if (SOAPConstants.URI_SOAP_ACTOR_NEXT.equals(headerActor)) {
64              return true;
65          }
66          if (!ObjectUtils.isEmpty(actors)) {
67              for (int i = 0; i < actors.length; i++) {
68                  if (actors[i].equals(headerActor)) {
69                      return true;
70                  }
71              }
72          }
73          return false;
74      }
75  }