1 package org.jacorb.notification.util; 2 3 23 24 import org.jacorb.util.ObjectUtil; 25 26 29 30 public abstract class PatternWrapper 31 { 32 private static final RuntimeException REGEXP_NOT_AVAILABLE = new RuntimeException ( 33 "No RegExp Implementation available. " 34 + "The package java.util.regex is part of the JDK since v1.4 " 35 + "if you are running an older JDK you'll have to install " 36 + "gnu.regexp or jakarta.regexp to run this NotificationService. Please refer " 37 + "to the documentation for details."); 38 39 private static Class sDefaultInstance = null; 40 41 static 42 { 43 if (isClassAvailable("java.util.regex.Pattern")) 44 { 45 try 46 { 47 sDefaultInstance = ObjectUtil 48 .classForName("org.jacorb.notification.util.JDK14PatternWrapper"); 49 } catch (ClassNotFoundException e) 50 { 51 } 54 } 55 56 if (sDefaultInstance == null && isClassAvailable("org.apache.regexp.RE")) 57 { 58 try 59 { 60 sDefaultInstance = ObjectUtil 61 .classForName("org.jacorb.notification.util.JakartaRegexpPatternWrapper"); 62 } catch (ClassNotFoundException e) 63 { 64 } 67 } 68 69 if (sDefaultInstance == null && isClassAvailable("gnu.regexp.RE")) 70 { 71 try 72 { 73 sDefaultInstance = ObjectUtil 74 .classForName("org.jacorb.notification.util.GNUPatternWrapper"); 75 } catch (ClassNotFoundException e) 76 { 77 throw new RuntimeException (e.getMessage()); 79 } 80 } 81 82 if (sDefaultInstance == null) 83 { 84 throw REGEXP_NOT_AVAILABLE; 85 } 86 } 87 88 public static PatternWrapper init(String patternString) 89 { 90 try 91 { 92 PatternWrapper _wrapper; 93 _wrapper = (PatternWrapper) sDefaultInstance.newInstance(); 94 _wrapper.compile(patternString); 95 96 return _wrapper; 97 } catch (Exception e) 98 { 99 if (sDefaultInstance == null) 100 { 101 throw REGEXP_NOT_AVAILABLE; 102 } 103 104 throw new RuntimeException (e.getMessage()); 105 } 106 } 107 108 public abstract void compile(String pattern); 109 110 118 119 public abstract int match(String text); 120 121 private static boolean isClassAvailable(String name) 122 { 123 try 124 { 125 ObjectUtil.classForName(name); 126 127 return true; 128 } catch (ClassNotFoundException e) 129 { 130 } 132 133 return false; 134 } 135 } | Popular Tags |