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