1 18 package org.apache.activemq.console.filter; 19 20 import javax.management.ObjectInstance ; 21 import javax.management.ObjectName ; 22 import javax.management.AttributeList ; 23 import javax.management.Attribute ; 24 import java.util.Map ; 25 import java.util.Iterator ; 26 import java.util.regex.Pattern ; 27 import java.lang.reflect.Method ; 28 29 public class MBeansRegExQueryFilter extends RegExQueryFilter { 30 34 public MBeansRegExQueryFilter(QueryFilter next) { 35 super(next); 36 } 37 38 47 protected boolean matches(Object data, Map regex) throws Exception { 48 50 try { 52 Method method = this.getClass().getDeclaredMethod("matches", new Class [] {data.getClass(), Map .class}); 53 return ((Boolean )method.invoke(this, new Object [] {data, regex})).booleanValue(); 54 } catch (NoSuchMethodException e) { 55 return false; 56 } 57 } 58 59 65 protected boolean matches(ObjectInstance data, Map regex) { 66 return matches(data.getObjectName(), regex); 67 } 68 69 75 protected boolean matches(ObjectName data, Map regex) { 76 for (Iterator i=regex.keySet().iterator(); i.hasNext();) { 77 String key = (String )i.next(); 78 String target = data.getKeyProperty(key); 79 80 if (target != null && !((Pattern )regex.get(key)).matcher(target).matches()) { 82 return false; 83 } 84 } 85 return true; 86 } 87 88 94 protected boolean matches(AttributeList data, Map regex) { 95 for (Iterator i=regex.keySet().iterator(); i.hasNext();) { 96 String key = (String )i.next(); 97 98 for (Iterator j=data.iterator(); j.hasNext();) { 100 Attribute attrib = (Attribute )j.next(); 101 102 if (attrib.getName().equals(MBeansAttributeQueryFilter.KEY_OBJECT_NAME_ATTRIBUTE)) { 104 String target = ((ObjectName )attrib.getValue()).getKeyProperty(key); 105 106 if (target == null || !((Pattern )regex.get(key)).matcher(target).matches()) { 107 return false; 108 } else { 109 break; 111 } 112 113 } else if (attrib.getName().equals(key)) { 115 if (!((Pattern )regex.get(key)).matcher(attrib.getValue().toString()).matches()) { 116 return false; 117 } else { 118 break; 120 } 121 122 } else { 124 return false; 125 } 126 } 127 } 128 return true; 129 } 130 } 131 | Popular Tags |