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