View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.classic.spi;
11  
12  import java.util.concurrent.CopyOnWriteArrayList;
13  
14  import org.slf4j.Marker;
15  
16  import ch.qos.logback.classic.Level;
17  import ch.qos.logback.classic.Logger;
18  import ch.qos.logback.classic.turbo.TurboFilter;
19  import ch.qos.logback.core.spi.FilterReply;
20  
21  /**
22   * Implementation of TurboFilterAttachable.
23   * 
24   * @author Ceki Gülcü
25   */
26  final public class TurboFilterList extends CopyOnWriteArrayList<TurboFilter> {
27  
28    private static final long serialVersionUID = 1L;
29  
30    /**
31     * Loop through the filters in the chain. As soon as a filter decides on
32     * ACCEPT or DENY, then that value is returned. If all of the filters return
33     * NEUTRAL, then NEUTRAL is returned.
34     */
35    public final FilterReply getTurboFilterChainDecision(final Marker marker,
36        final Logger logger, final Level level, final String format,
37        final Object[] params, final Throwable t) {
38      
39      
40      final int size = size();
41  //    if (size == 0) {
42  //      return FilterReply.NEUTRAL;
43  //    }
44      if (size == 1) {
45        try {
46          TurboFilter tf = get(0);
47          return tf.decide(marker, logger, level, format, params, t);
48        } catch (IndexOutOfBoundsException iobe) {
49          return FilterReply.NEUTRAL;
50        }
51      }
52      
53      Object[] tfa = toArray();
54      final int len = tfa.length;
55      for (int i = 0; i < len; i++) {
56      //for (TurboFilter tf : this) {
57        final TurboFilter tf = (TurboFilter) tfa[i];
58        final FilterReply r = tf.decide(marker, logger, level, format, params, t);
59        if (r == FilterReply.DENY || r == FilterReply.ACCEPT) {
60          return r;
61        }
62      }
63      return FilterReply.NEUTRAL;
64    }
65  
66    // public boolean remove(TurboFilter turboFilter) {
67    // return tfList.remove(turboFilter);
68    // }
69    //
70    // public TurboFilter remove(int index) {
71    // return tfList.remove(index);
72    // }
73    //
74    // final public int size() {
75    // return tfList.size();
76    // }
77  
78  }