KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jboss.mx.remoting.event;
2
3 import java.io.Serializable JavaDoc;
4 import javax.management.BadAttributeValueExpException JavaDoc;
5 import javax.management.BadBinaryOpValueExpException JavaDoc;
6 import javax.management.BadStringOperationException JavaDoc;
7 import javax.management.InvalidApplicationException JavaDoc;
8 import javax.management.MBeanServer JavaDoc;
9 import javax.management.ObjectName JavaDoc;
10 import javax.management.QueryExp JavaDoc;
11
12 /**
13  * CompositeQueryExp is a composite QueryExp that allows multiple QueryExp implementations to be
14  * chained together (a little easier than trying to use Query class).
15  *
16  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
17  * @version $Revision: 30251 $
18  */

19 public class CompositeQueryExp implements QueryExp JavaDoc, Serializable JavaDoc
20 {
21    static final long serialVersionUID = 6918797787135545210L;
22
23    public static final int AND = 0;
24    public static final int OR = 1;
25
26    private int operator;
27    private QueryExp JavaDoc exps[];
28
29    /**
30     * create a composite QueryExp with the default <tt>AND</tt> operator
31     *
32     * @param exp
33     */

34    public CompositeQueryExp(QueryExp JavaDoc exp[])
35    {
36       this(exp, AND);
37    }
38
39    public CompositeQueryExp(QueryExp JavaDoc exp[], int operator)
40    {
41       this.exps = exp;
42       this.operator = operator;
43    }
44
45    public boolean apply(ObjectName JavaDoc objectName) throws BadStringOperationException JavaDoc, BadBinaryOpValueExpException JavaDoc, BadAttributeValueExpException JavaDoc, InvalidApplicationException JavaDoc
46    {
47       for(int c = 0; c < exps.length; c++)
48       {
49          if(exps[c] != null)
50          {
51             boolean value = exps[c].apply(objectName);
52             if(value && operator == OR)
53             {
54                return true;
55             }
56             else if(!value && operator == AND)
57             {
58                return false;
59             }
60          }
61       }
62       return (operator == AND) ? true : false;
63    }
64
65    public void setMBeanServer(MBeanServer JavaDoc mBeanServer)
66    {
67       for(int c = 0; c < exps.length; c++)
68       {
69          if(exps[c] != null)
70          {
71             exps[c].setMBeanServer(mBeanServer);
72          }
73       }
74    }
75 }
76
Popular Tags