1 22 package org.jboss.mx.util; 23 24 import java.util.Hashtable ; 25 import java.util.Iterator ; 26 import java.util.regex.Matcher ; 27 import java.util.regex.Pattern ; 28 import java.util.regex.PatternSyntaxException ; 29 import javax.management.ObjectName ; 30 31 36 public class ObjectNameMatch 37 { 38 44 public static boolean match(ObjectName n0, ObjectName n1) 45 { 46 boolean match = n0.equals(n1); 47 if( match == true ) 48 return true; 49 50 String d0 = n0.getDomain(); 52 String d1 = n1.getDomain(); 53 int star0 = d0.indexOf('*'); 54 int star1 = d1.indexOf('*'); 55 56 if( star0 >= 0 ) 57 { 58 if( star1 >= 0 ) 59 { 60 match = d0.equals(d1); 61 } 62 else 63 { 64 try 65 { 66 Pattern domainRE = Pattern.compile(d0); 67 Matcher m = domainRE.matcher(d1); 68 match = m.matches(); 69 } 70 catch(PatternSyntaxException e) 71 { 72 } 73 } 74 } 75 else if( star1 >= 0 ) 76 { 77 if( star0 >= 0 ) 78 { 79 match = d0.equals(d1); 80 } 81 else 82 { 83 try 84 { 85 Pattern domainRE = Pattern.compile(d1); 86 Matcher m = domainRE.matcher(d0); 87 match = m.matches(); 88 } 89 catch(PatternSyntaxException e) 90 { 91 } 92 } 93 } 94 else 95 { 96 match = d0.equals(d1); 97 } 98 99 if( match == false ) 100 return false; 101 102 if( n0.isPropertyPattern() ) 104 { 105 Hashtable props0 = n0.getKeyPropertyList(); 106 Hashtable props1 = n1.getKeyPropertyList(); 107 Iterator iter = props0.keySet().iterator(); 108 while( match == true && iter.hasNext() ) 109 { 110 String key = (String ) iter.next(); 111 String value = (String ) props0.get(key); 112 match &= value.equals(props1.get(key)); 113 } 114 } 115 else if( n1.isPropertyPattern() ) 116 { 117 Hashtable props0 = n0.getKeyPropertyList(); 118 Hashtable props1 = n1.getKeyPropertyList(); 119 Iterator iter = props1.keySet().iterator(); 120 while( iter.hasNext() ) 121 { 122 String key = (String ) iter.next(); 123 String value = (String ) props1.get(key); 124 match &= value.equals(props0.get(key)); 125 } 126 } 127 128 return match; 129 } 130 131 } 132 | Popular Tags |