View Javadoc

1   /*
2    * Copyright 2009 University Corporation for Advanced Internet Development, Inc.
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.opensaml.ws.message.handler;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.opensaml.xml.util.LazyList;
25  import org.opensaml.xml.util.LazyMap;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  /**
30   * A basic implementation of {@link PhasedHandlerChain}.
31   */
32  public class BasicPhasedHandlerChain extends BasicHandlerChain implements PhasedHandlerChain {
33      
34      /** Class logger. */
35      private final Logger log = LoggerFactory.getLogger(BasicPhasedHandlerChain.class);
36      
37      /** The ordered list of phases to invoke. */
38      private List<String> phaseOrder;
39      
40      /** Map of phases to corresponding Handler chain. */
41      private Map<String, HandlerChain> phaseChains;
42  
43      /** Constructor. */
44      public BasicPhasedHandlerChain() {
45          super();
46          phaseOrder = new LazyList<String>();
47          phaseChains = new LazyMap<String, HandlerChain>();
48      }
49  
50      /** {@inheritDoc} */
51      public List<Handler> getHandlers() {
52          ArrayList<Handler> handlers = new ArrayList<Handler>();
53          for (String phaseName : getPhaseOrder()) {
54              HandlerChain phase = getPhaseChains().get(phaseName);
55              if (phase != null) {
56                  List<Handler> phaseHandlers = phase.getHandlers();
57                  if (!phaseHandlers.isEmpty()) {
58                      handlers.addAll(phaseHandlers);
59                  } else {
60                      log.info("Specified phase name '{}' exists in PhasedHandlerChain, but contains no handlers",
61                          phaseName);
62                  }
63              } else {
64                  log.warn("Specified phase name '{}' does not exist in PhasedHandlerChain: {}",
65                          phaseName, getPhaseChains().keySet());
66              }
67          }
68          return Collections.unmodifiableList(handlers);
69      }
70  
71      /** {@inheritDoc} */
72      public Map<String, HandlerChain> getPhaseChains() {
73          return phaseChains;
74      }
75  
76      /** {@inheritDoc} */
77      public List<String> getPhaseOrder() {
78          return phaseOrder;
79      }
80  
81      /** {@inheritDoc} */
82      public void setPhaseOrder(List<String> newPhaseOrder) {
83          phaseOrder = newPhaseOrder;
84      }
85  
86  }