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 import net.sf.eos.EosException;
20 import net.sf.eos.Supplier;
21 import net.sf.eos.config.Configuration;
22 import net.sf.eos.config.ConfigurationKey;
23 import net.sf.eos.config.FactoryMethod;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.lucene.analysis.Analyzer;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public abstract class AnalyzerSupplier implements Supplier<Analyzer> {
43
44
45 private static final Log LOG =
46 LogFactory.getLog(AnalyzerSupplier.class.getName());
47
48
49
50 @SuppressWarnings("nls")
51 @ConfigurationKey(type=CLASSNAME,
52 description="Configuration key of the Lucene analyzer "
53 + " factory.")
54 public final static String ANALYZER_PROVIDER_IMPL_CONFIG_NAME =
55 "net.sf.eos.lucene.AnalyzerProvider.impl";
56
57
58
59
60
61
62
63
64
65
66
67
68 @FactoryMethod(key=ANALYZER_PROVIDER_IMPL_CONFIG_NAME)
69 public final static AnalyzerSupplier newInstance(final Configuration config)
70 throws EosException {
71
72 final Thread t = Thread.currentThread();
73 ClassLoader classLoader = t.getContextClassLoader();
74 if (classLoader == null) {
75 classLoader = AnalyzerSupplier.class.getClassLoader();
76 }
77
78 final String clazzName =
79 config.get(ANALYZER_PROVIDER_IMPL_CONFIG_NAME,
80 WhitespaceAnalyzerSupplier.class.getName());
81
82 try {
83 final Class<? extends AnalyzerSupplier> clazz =
84 (Class<? extends AnalyzerSupplier>) Class
85 .forName(clazzName, true, classLoader);
86 try {
87
88 final AnalyzerSupplier factory = clazz.newInstance();
89 if (LOG.isDebugEnabled()) {
90 LOG.debug("AnalyzerProvider instance: "
91 + factory.getClass().getName());
92 }
93 return factory;
94
95 } catch (final InstantiationException e) {
96 throw new EosException(e);
97 } catch (final IllegalAccessException e) {
98 throw new EosException(e);
99 }
100 } catch (final ClassNotFoundException e) {
101 throw new EosException(e);
102 }
103 }
104
105
106
107
108
109 public abstract Analyzer get();
110 }