KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > rule > filter > FilterFinder


1 /*______________________________________________________________________________
2  *
3  * Macker http://innig.net/macker/
4  *
5  * Copyright 2002 Paul Cantrell
6  *
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License version 2, as published by the
9  * Free Software Foundation. See the file LICENSE.html for more information.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the license for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
17  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
18  *______________________________________________________________________________
19  */

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 JavaDoc filterName)
29         throws NoSuchFilterException
30         {
31         Filter filter = (Filter) filterCache.get(filterName);
32         if(filter == null)
33             {
34             String JavaDoc 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 JavaDoc cnfe)
45                 { throwFilterConfigException(filterClassName, filterName, cnfe); }
46             catch(IllegalAccessException JavaDoc iae)
47                 { throwFilterConfigException(filterClassName, filterName, iae); }
48             catch(InstantiationException JavaDoc ie)
49                 { throwFilterConfigException(filterClassName, filterName, ie); }
50             catch(ClassCastException JavaDoc cce)
51                 { throwFilterConfigException(filterClassName, filterName, cce); }
52             }
53         return filter;
54         }
55     
56     private static void throwFilterConfigException(String JavaDoc filterClassName, String JavaDoc filterName, Exception JavaDoc 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 JavaDoc FILTER_CONF = "net.innig.macker.filter";
68     private static Map filterCache = new HashMap();
69     }
70
Popular Tags