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.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  import javax.xml.soap.SOAPConstants;
23  import javax.xml.soap.SOAPHeader;
24  import javax.xml.soap.SOAPHeaderElement;
25  
26  import org.springframework.util.ObjectUtils;
27  import org.springframework.util.StringUtils;
28  import org.springframework.ws.soap.SoapHeaderElement;
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<SoapHeaderElement> examineHeaderElementsToProcess(String[] actors) {
44          List<SOAPHeaderElement> result = new ArrayList<SOAPHeaderElement>();
45          Iterator<SOAPHeaderElement> iterator = getImplementation().examineAllHeaderElements(getSaajHeader());
46          while (iterator.hasNext()) {
47              SOAPHeaderElement saajHeaderElement = iterator.next();
48              String headerActor = saajHeaderElement.getActor();
49              if (shouldProcess(headerActor, actors)) {
50                  result.add(saajHeaderElement);
51              }
52          }
53          return new SaajSoapHeaderElementIterator(result.iterator());
54      }
55  
56      private boolean shouldProcess(String headerActor, String[] actors) {
57          if (!StringUtils.hasLength(headerActor)) {
58              return true;
59          }
60          if (SOAPConstants.URI_SOAP_ACTOR_NEXT.equals(headerActor)) {
61              return true;
62          }
63          if (!ObjectUtils.isEmpty(actors)) {
64              for (String actor : actors) {
65                  if (actor.equals(headerActor)) {
66                      return true;
67                  }
68              }
69          }
70          return false;
71      }
72  }