01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.search.engine;
19:
20: import java.util.HashMap;
21:
22: import de.finix.contelligent.core.ContelligentImpl;
23: import de.finix.contelligent.xml.elements.IndexBuilderFilterElement;
24:
25: public class FilterEngine {
26:
27: HashMap filterClasses = new HashMap();
28:
29: /**
30: *
31: */
32: private FilterEngine() {
33: super ();
34: }
35:
36: private static FilterEngine instance = new FilterEngine();
37:
38: private static final String DEFAULT_FQN_PREFIX = "de.finix.contelligent.search.filters.";
39:
40: public static FilterEngine getInstance() {
41: return instance;
42: }
43:
44: public CrawlerFilter getFilterInstance(
45: IndexBuilderFilterElement element) throws FilterException {
46:
47: try {
48: String impl = element.getImpl();
49:
50: if (impl.startsWith("filter:")) {
51: impl = DEFAULT_FQN_PREFIX
52: + impl.substring("filter:".length());
53: }
54:
55: Class cls = getFilterClass(impl);
56: return (CrawlerFilter) cls.newInstance();
57: } catch (ClassNotFoundException e) {
58: throw new FilterException("Filter Class Not Found '"
59: + element.getImpl() + "'", e);
60: } catch (InstantiationException e) {
61: throw new FilterException(
62: "Filter Class could not be instanciated '"
63: + element.getImpl() + "'", e);
64: } catch (IllegalAccessException e) {
65: throw new FilterException(
66: "Filter Class could not be accessed '"
67: + element.getImpl() + "'", e);
68: }
69:
70: }
71:
72: /**
73: * @param class1
74: * @return
75: * @throws ClassNotFoundException
76: */
77: private Class getFilterClass(String impl)
78: throws ClassNotFoundException {
79: Class cls = ContelligentImpl.class.getClassLoader().loadClass(
80: impl);
81: return cls;
82: }
83:
84: }
|