KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > remoting > event > CompositeEventFilter


1 package org.jboss.mx.remoting.event;
2
3 import javax.management.Notification JavaDoc;
4 import javax.management.NotificationFilter JavaDoc;
5
6 /**
7  * Composite-pattern based filter
8  *
9  * @author Jeff Haynie
10  * @version $Revision: 30251 $
11  */

12 public class CompositeEventFilter implements NotificationFilter JavaDoc
13 {
14    static final long serialVersionUID = -4670317046721324670L;
15    public static final int AND = 0;
16    public static final int OR = 1;
17
18    protected int operator = AND;
19    protected NotificationFilter JavaDoc filters[];
20
21    /**
22     * create a filter composite of filters using the specific operator
23     */

24    public CompositeEventFilter(NotificationFilter JavaDoc filters[], int operator)
25    {
26       this.filters = filters;
27       this.operator = operator;
28    }
29
30    /**
31     * create a filter composite of filters using the AND operator
32     */

33    public CompositeEventFilter(NotificationFilter JavaDoc filters[])
34    {
35       this(filters, AND);
36    }
37
38    public boolean isNotificationEnabled(Notification JavaDoc event)
39    {
40       Class JavaDoc cl = event.getClass();
41       for(int c = 0; c < filters.length; c++)
42       {
43          if(operator == AND)
44          {
45             if(filters[c] != null && filters[c].isNotificationEnabled(event) == false)
46             {
47                return false;
48             }
49          }
50          else
51          {
52             if(filters[c] != null && filters[c].isNotificationEnabled(event))
53             {
54                return true;
55             }
56          }
57       }
58       return (operator == AND ? true : false);
59    }
60 }
61
62
Popular Tags