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