View Javadoc

1   /*
2    * Copyright [2006] [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.saml2.metadata.provider;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.opensaml.xml.XMLObject;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  /**
27   * A filter that allows the composition of {@link MetadataFilter}s. Filters will be executed on the given metadata
28   * document in the order they were added to the chain.
29   */
30  public class MetadataFilterChain implements MetadataFilter {
31  
32      /** Class logger. */
33      private Logger log = LoggerFactory.getLogger(MetadataFilterChain.class);
34      
35      /** Registered filters. */
36      private ArrayList<MetadataFilter> filters;
37  
38      /**
39       * Constructor.
40       */
41      public MetadataFilterChain() {
42          filters = new ArrayList<MetadataFilter>();
43      }
44  
45      /** {@inheritDoc} */
46      public final void doFilter(XMLObject xmlObject) throws FilterException {
47          synchronized (filters) {
48              if(filters == null || filters.isEmpty()){
49                  log.debug("No filters configured, nothing to do");
50              }
51              for (MetadataFilter filter : filters) {
52                  log.debug("Applying filter {}", filter.getClass().getName());
53                  filter.doFilter(xmlObject);
54              }
55          }
56      }
57  
58      /**
59       * Gets the list of {@link MetadataFilter}s that make up this chain.
60       * 
61       * @return the filters that make up this chain
62       */
63      public List<MetadataFilter> getFilters() {
64          return filters;
65      }
66  
67      /**
68       * Sets the list of {@link MetadataFilter}s that make up this chain.
69       * 
70       * @param newFilters list of {@link MetadataFilter}s that make up this chain
71       */
72      public void setFilters(List<MetadataFilter> newFilters) {
73          filters.clear();
74  
75          if (newFilters != null) {
76              filters.addAll(newFilters);
77          }
78      }
79  }