1 | |
package org.naftulin.configmgr.parsers; |
2 | |
|
3 | |
import java.net.URL; |
4 | |
import java.util.List; |
5 | |
import java.util.Properties; |
6 | |
|
7 | |
import javax.naming.InitialContext; |
8 | |
import javax.naming.NamingException; |
9 | |
|
10 | |
import org.naftulin.configmgr.ConfigurationManagementEntry; |
11 | |
import org.naftulin.configmgr.ConfigurationManagementEntryImpl; |
12 | |
import org.naftulin.configmgr.ConfigurationManagerException; |
13 | |
import org.naftulin.configmgr.ConfigurationType; |
14 | |
import org.naftulin.configmgr.content.NameValuePairImpl; |
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
public class JndiParserImpl extends AbstractJndiParser implements ConfigEntryParser { |
20 | |
private static final long serialVersionUID = 1L; |
21 | |
public JndiParserImpl(final String jndiName, final String initialContextFactory, final List<NameValuePairImpl> nameValuePairs) { |
22 | 5 | super(jndiName, initialContextFactory, nameValuePairs); |
23 | 5 | } |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public ConfigurationManagementEntry getConfigurationManagementEntry( |
34 | |
String key, URL fileUrl) throws ConfigurationManagerException { |
35 | 5 | ConfigurationManagementEntry entry = null; |
36 | |
|
37 | 5 | validateParameters(key); |
38 | |
|
39 | |
|
40 | 5 | final Properties props = new Properties(); |
41 | 5 | prepareJndiProperties(props); |
42 | |
|
43 | |
try { |
44 | 5 | InitialContext context = null; |
45 | 5 | context = getJndiContext(key, props, context); |
46 | |
|
47 | 5 | log.info("Initial context created for jndiName " + jndiName); |
48 | 5 | final Object content = context.lookup(jndiName); |
49 | 5 | final String fileName = "jndiName : " + jndiName; |
50 | |
|
51 | 5 | entry = new ConfigurationManagementEntryImpl(key, fileName, content, this, ConfigurationType.JNDI); |
52 | 5 | log.info("configuration management entry created for key " + key + " with jndi name " + jndiName); |
53 | 0 | } catch (NamingException e) { |
54 | 0 | log.error("Could not lookup jndi name: " + jndiName + " and other parameters from configuration " + key, e); |
55 | 0 | throw new ConfigurationManagerException("Could not lookup jndi name: " + jndiName + " and other parameters from configuration " + key, e); |
56 | |
} |
57 | |
|
58 | 5 | return entry; |
59 | |
} |
60 | |
|
61 | |
|
62 | |
|
63 | |
} |