1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.eos.entity;
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
23 import java.util.Locale;
24
25 import net.sf.eos.EosException;
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
31
32
33
34
35
36 public abstract class CommonNameResolver extends Configured {
37
38
39 private static final Log LOG =
40 LogFactory.getLog(CommonNameResolver.class.getName());
41
42
43
44 @SuppressWarnings("nls")
45 @ConfigurationKey(type=CLASSNAME,
46 description="Resolver remaps an entity ID to a "
47 + "common name (human readable).")
48 public final static String COMMON_NAME_RESOLVER_IMPL_CONFIG_NAME =
49 "net.sf.eos.entity.CommonNameResolver.impl";
50
51
52
53
54
55
56
57
58
59
60 @FactoryMethod(key=COMMON_NAME_RESOLVER_IMPL_CONFIG_NAME)
61 public final static CommonNameResolver 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 =
68 AbstractDictionaryBasedEntityRecognizer.class.getClassLoader();
69 }
70
71 final String clazzName = config.get(COMMON_NAME_RESOLVER_IMPL_CONFIG_NAME);
72
73 try {
74 final Class<? extends CommonNameResolver> clazz =
75 (Class<? extends CommonNameResolver>)
76 Class.forName(clazzName, true, classLoader);
77 try {
78
79 final CommonNameResolver instance = clazz.newInstance();
80 if (LOG.isDebugEnabled()) {
81 LOG.debug("CommonNameResolver instance: "
82 + instance.getClass().getName());
83 }
84 instance.configure(config);
85 return instance;
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
103
104 public String resolveCommonName(final String id) throws EosException {
105 final Locale locale = Locale.getDefault();
106 return resolveCommonName(id, locale);
107 }
108
109
110
111
112
113
114
115
116
117 public abstract String resolveCommonName(final String id,
118 final Locale locale) throws EosException;
119 }