1 7 package org.jboss.mx.remoting.event; 8 9 import java.io.Serializable ; 10 import javax.management.BadAttributeValueExpException ; 11 import javax.management.BadBinaryOpValueExpException ; 12 import javax.management.BadStringOperationException ; 13 import javax.management.InvalidApplicationException ; 14 import javax.management.MBeanServer ; 15 import javax.management.ObjectName ; 16 import javax.management.QueryExp ; 17 18 37 public class ClassQueryExp implements QueryExp , Serializable 38 { 39 private static final long serialVersionUID = -4099952623687795850L; 40 41 public static final int AND = 1; 42 public static final int OR = 2; 43 44 String classes[]; 45 int operator; 46 transient MBeanServer mBeanServer; 47 48 53 public ClassQueryExp(Class cl[]) 54 { 55 this(cl, OR); 56 } 57 58 63 public ClassQueryExp(Class cl) 64 { 65 this(new Class []{cl}, AND); 66 } 67 68 public ClassQueryExp(Class cl, int operator) 69 { 70 this(new Class []{cl}, operator); 71 } 72 73 public ClassQueryExp(Class cl[], int operator) 74 { 75 this.classes = new String [cl.length]; 76 for(int c = 0; c < cl.length; c++) 77 { 78 this.classes[c] = cl[c].getName(); 79 } 80 this.operator = operator; 81 } 82 83 public boolean apply(ObjectName objectName) throws BadStringOperationException , BadBinaryOpValueExpException , BadAttributeValueExpException , InvalidApplicationException 84 { 85 try 86 { 87 for(int c = 0; c < classes.length; c++) 88 { 89 boolean value = mBeanServer.isInstanceOf(objectName, classes[c]); 90 if(value && operator == OR) 91 { 92 return true; 93 } 94 else if(!value && operator == AND) 95 { 96 return false; 97 } 98 } 99 return (operator == OR ? false : true); 100 } 101 catch(Exception ex) 102 { 103 return false; 104 } 105 } 106 107 112 public void setMBeanServer(MBeanServer mBeanServer) 113 { 114 this.mBeanServer = mBeanServer; 115 } 116 } 117 | Popular Tags |