1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.eos.lucene;
17
18 import static net.sf.eos.config.ConfigurationKey.Type.CLASSNAME;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.lucene.search.Searcher;
23
24 import net.sf.eos.EosException;
25 import net.sf.eos.Supplier;
26 import net.sf.eos.config.Configuration;
27 import net.sf.eos.config.ConfigurationException;
28 import net.sf.eos.config.ConfigurationKey;
29 import net.sf.eos.config.Configured;
30 import net.sf.eos.config.FactoryMethod;
31
32 public abstract class SearcherSupplier extends Configured
33 implements Supplier<Searcher> {
34
35
36 private static final Log LOG =
37 LogFactory.getLog(SearcherSupplier.class.getName());
38
39
40
41 @SuppressWarnings("nls")
42 @ConfigurationKey(type=CLASSNAME,
43 description="Configuration key of the search supplier.")
44 public final static String SEARCHER_SUPPLIER_IMPL_CONFIG_NAME =
45 "net.sf.eos.lucene.SearcherSupplier.impl";
46
47
48
49
50
51
52
53
54
55
56
57
58
59 @FactoryMethod(key=SEARCHER_SUPPLIER_IMPL_CONFIG_NAME,
60 implementation=IndexSearcherSupplier.class)
61 public final static SearcherSupplier newInstance(final Configuration config)
62 throws EosException {
63
64 final Thread t = Thread.currentThread();
65 ClassLoader classLoader = t.getContextClassLoader();
66 if (classLoader == null) {
67 classLoader = SearcherSupplier.class.getClassLoader();
68 }
69
70 final String clazzName =
71 config.get(SEARCHER_SUPPLIER_IMPL_CONFIG_NAME,
72 IndexSearcherSupplier.class.getName());
73
74 try {
75 final Class<? extends SearcherSupplier> clazz =
76 (Class<? extends SearcherSupplier>) Class
77 .forName(clazzName, true, classLoader);
78 try {
79
80 final SearcherSupplier factory = clazz.newInstance();
81 if (LOG.isDebugEnabled()) {
82 LOG.debug("SearcherSupplier instance: "
83 + factory.getClass().getName());
84 }
85 return factory;
86
87 } catch (final InstantiationException e) {
88 throw new EosException(e);
89 } catch (final IllegalAccessException e) {
90 throw new EosException(e);
91 }
92 } catch (final ClassNotFoundException e) {
93 throw new EosException(e);
94 }
95 }
96
97
98
99
100
101
102 public Searcher get() {
103 final Configuration conf = this.getConfiguration();
104 return get(conf);
105 }
106
107
108
109
110
111
112
113 public abstract Searcher get(final Configuration conf);
114 }