1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.germinus.easyconf;
17
18 import javax.naming.InitialContext;
19 import javax.naming.NamingException;
20
21 import org.apache.commons.configuration.Configuration;
22 import org.apache.commons.configuration.JNDIConfiguration;
23
24 /***
25 * Represents the URL to a JNDI tree as specified in a properties file
26 * TODO: Add support for ASP applications
27 * @author Jorge Ferrer
28 * @version $Revision: 1.2 $
29 *
30 */
31 public class JndiURL {
32 private static final String JNDI_PREFIX = Conventions.JNDI_PREFIX;
33 private static InitialContext ctx = null;
34 private String jndiPrefix;
35 private String companyId;
36 private String componentName;
37
38 public JndiURL(String jndiPath, String companyId, String componentName) {
39 this.jndiPrefix = jndiPrefix.substring(JNDI_PREFIX.length());
40 this.companyId = companyId;
41 this.componentName = componentName;
42 }
43
44 private synchronized InitialContext getContext() throws NamingException {
45 if (ctx == null) {
46 ctx = new InitialContext();
47 }
48 return ctx;
49 }
50
51 public static boolean isJndi(String sourcePath) {
52 return sourcePath.startsWith(JNDI_PREFIX);
53 }
54
55 public String getPrefix() {
56 return jndiPrefix;
57 }
58
59 public Configuration getConfiguration() {
60 try {
61 return new JNDIConfiguration(getPrefix());
62 } catch (NamingException e) {
63 throw new ConfigurationException("Error loading JNDI configuration for "
64 + getPrefix());
65 }
66 }
67
68
69 }