1 23 24 package com.sun.enterprise.admin.common; 25 26 import com.sun.enterprise.admin.util.IPatternMatcher; 28 import com.sun.enterprise.admin.util.RegExpMatcher; 29 import com.sun.enterprise.admin.util.GeneralPatternMatcher; 30 import com.sun.enterprise.admin.util.Logger; 31 32 import com.sun.enterprise.admin.util.SOMLocalStringsManager; 34 35 public class CombinedPatternMatcher implements IPatternMatcher 36 { 37 private String mPattern = null; 38 private String mTestString = null; 39 private IPatternMatcher mRealMatcher = null; 40 41 private static SOMLocalStringsManager localizedStrMgr = 43 SOMLocalStringsManager.getManager( CombinedPatternMatcher.class ); 44 45 53 54 public CombinedPatternMatcher(String patternString, String testString) 55 { 56 if (patternString == null || testString == null) 57 { 58 String msg = localizedStrMgr.getString( "admin.common.combinedpattermatcher_null_arg" ); 59 throw new IllegalArgumentException ( msg ); 60 } 61 mPattern = patternString; 62 mTestString = testString; 63 if (isJDK14()) 64 { 65 mPattern = translateFromJMXToJDK14(patternString); 67 mRealMatcher = new RegExpMatcher(mPattern, testString); 68 } 69 else 70 { 71 mRealMatcher = new GeneralPatternMatcher(patternString, testString); 73 } 74 } 75 76 public boolean matches() 77 { 78 return ( mRealMatcher.matches() ); 79 } 80 81 public boolean isJDK14() 82 { 83 String javaSpecVersion = System.getProperty("java.specification.version"); 84 85 return ( javaSpecVersion.startsWith("1.4") ); 86 } 87 88 private String translateFromJMXToJDK14(String aString) 89 { 90 String dotEscpapedString = escapeDots(aString); 91 String starReplacedString = insertDotBeforeStar(dotEscpapedString); 92 String qmReplacedString = insertDotBeforeQM(starReplacedString); 93 return ( qmReplacedString ); 94 } 95 96 private String escapeDots(String aString) 97 { 98 char escape = Tokens.kEscapeChar; 99 char dot = Tokens.kDelimiterChar; 100 return ( insertCharBefore(aString, escape, dot) ); 101 } 102 private String insertDotBeforeStar(String aString) 103 { 104 char dot = Tokens.kDelimiterChar; 105 char star = Tokens.kWildCardChar; 106 107 return ( insertCharBefore(aString, dot, star) ); 108 } 109 private String insertDotBeforeQM(String aString) 110 { 111 char dot = Tokens.kDelimiterChar; 112 char qm = ObjectNames.kSingleMatchChar; 113 114 return ( insertCharBefore(aString, dot, qm) ); 115 } 116 private String insertCharBefore(String aString, char insChar, char beforeChar) 117 { 118 StringBuffer destBuffer = new StringBuffer (); 119 char[] srcArray = aString.toCharArray(); 120 for (int i = 0 ; i < srcArray.length ; i++) 121 { 122 char ch = srcArray[i]; 123 if (ch == beforeChar) 124 { 125 destBuffer.append(insChar); 126 } 127 destBuffer.append(ch); 128 } 129 return ( destBuffer.toString() ); 130 } 131 } 132 | Popular Tags |