1 20 21 package net.innig.macker.rule.filter; 22 23 import net.innig.util.*; 24 import java.util.*; 25 26 public abstract class FilterFinder 27 { 28 public static Filter findFilter(String filterName) 29 throws NoSuchFilterException 30 { 31 Filter filter = (Filter) filterCache.get(filterName); 32 if(filter == null) 33 { 34 String filterClassName = 35 Conf.getMergedProperties(FILTER_CONF, FilterFinder.class.getClassLoader()) 36 .getProperty(filterName); 37 if(filterClassName == null) 38 throw new NoSuchFilterException(filterName); 39 try { 40 filterCache.put( 41 filterName, 42 filter = (Filter) Class.forName(filterClassName).newInstance()); 43 } 44 catch(ClassNotFoundException cnfe) 45 { throwFilterConfigException(filterClassName, filterName, cnfe); } 46 catch(IllegalAccessException iae) 47 { throwFilterConfigException(filterClassName, filterName, iae); } 48 catch(InstantiationException ie) 49 { throwFilterConfigException(filterClassName, filterName, ie); } 50 catch(ClassCastException cce) 51 { throwFilterConfigException(filterClassName, filterName, cce); } 52 } 53 return filter; 54 } 55 56 private static void throwFilterConfigException(String filterClassName, String filterName, Exception source) 57 { 58 throw new CorruptConfigurationException( 59 FILTER_CONF, 60 "Unable to use class " + filterClassName 61 + " specified for filter \"" + filterName 62 + "\": " + source); 63 } 64 65 private FilterFinder() { } 66 67 private static final String FILTER_CONF = "net.innig.macker.filter"; 68 private static Map filterCache = new HashMap(); 69 } 70 | Popular Tags |