View Javadoc
1   package ch.qos.logback.core.model.processor;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import ch.qos.logback.core.model.Model;
7   import ch.qos.logback.core.spi.FilterReply;
8   
9   public class ChainedModelFilter implements ModelFilter {
10  
11      List<ModelFilter> modelFilters = new ArrayList<>();
12  
13      public ChainedModelFilter() {
14      }
15  
16      static public ChainedModelFilter newInstance() {
17          return new ChainedModelFilter();
18      }
19  
20      public ChainedModelFilter allow(Class<? extends Model> allowedType) {
21          modelFilters.add(new AllowModelFilter(allowedType));
22          return this;
23      }
24  
25      public ChainedModelFilter deny(Class<? extends Model> allowedType) {
26          modelFilters.add(new DenyModelFilter(allowedType));
27          return this;
28      }
29  
30      public ChainedModelFilter denyAll() {
31          modelFilters.add(new DenyAllModelFilter());
32          return this;
33      }
34  
35      public ChainedModelFilter allowAll() {
36          modelFilters.add(new AllowAllModelFilter());
37          return this;
38      }
39  
40      @Override
41      public FilterReply decide(Model model) {
42  
43          for (ModelFilter modelFilter : modelFilters) {
44              FilterReply reply = modelFilter.decide(model);
45  
46              switch (reply) {
47              case ACCEPT:
48              case DENY:
49                  return reply;
50              case NEUTRAL:
51                  // next
52              }
53          }
54          return FilterReply.NEUTRAL;
55      }
56  
57  }