1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers;
12
13 import org.mule.config.i18n.CoreMessages;
14 import org.mule.umo.lifecycle.InitialisationException;
15
16 import java.util.Hashtable;
17 import java.util.Map;
18
19 import javax.naming.Context;
20 import javax.naming.InitialContext;
21 import javax.naming.NamingException;
22
23
24
25
26
27 public abstract class AbstractJndiConnector extends AbstractConnector
28 {
29 protected String jndiInitialFactory;
30
31 protected String jndiUrlPkgPrefixes;
32
33 protected String jndiProviderUrl;
34
35 protected Context jndiContext;
36
37 protected Map jndiProviderProperties = null;
38
39 protected void initJndiContext() throws InitialisationException
40 {
41 if (null == jndiContext)
42 {
43 Hashtable props = new Hashtable();
44
45 if (null != jndiInitialFactory)
46 {
47 props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory);
48 }
49
50 if (jndiProviderUrl != null)
51 {
52 props.put(Context.PROVIDER_URL, jndiProviderUrl);
53 }
54
55 if (jndiUrlPkgPrefixes != null)
56 {
57 props.put(Context.URL_PKG_PREFIXES, jndiUrlPkgPrefixes);
58 }
59
60 if (jndiProviderProperties != null)
61 {
62 props.putAll(jndiProviderProperties);
63 }
64 try
65 {
66 jndiContext = new InitialContext(props);
67 }
68 catch (NamingException e)
69 {
70 throw new InitialisationException(e, this);
71 }
72 }
73 }
74
75 public Context getJndiContext(String jndiProviderUrl) throws InitialisationException
76 {
77 try
78 {
79 setJndiProviderUrl(jndiProviderUrl);
80
81 initJndiContext();
82 }
83 catch (Exception e)
84 {
85 throw new InitialisationException(
86 CoreMessages.failedToCreate("AbstractJndiConnector"), e, this);
87 }
88
89 return jndiContext;
90 }
91
92 public Context getJndiContext()
93 {
94
95 return jndiContext;
96 }
97
98 public void setJndiContext(Context jndiContext)
99 {
100 this.jndiContext = jndiContext;
101 }
102
103 public void setJndiInitialFactory(String jndiInitialFactory)
104 {
105 this.jndiInitialFactory = jndiInitialFactory;
106 }
107
108 public String getJndiInitialFactory()
109 {
110 return jndiInitialFactory;
111 }
112
113 public void setJndiUrlPkgPrefixes(String jndiUrlPkgPrefixes)
114 {
115 this.jndiUrlPkgPrefixes = jndiUrlPkgPrefixes;
116 }
117
118 public String getJndiUrlPkgPrefixes()
119 {
120 return jndiUrlPkgPrefixes;
121 }
122
123 public String getJndiProviderUrl()
124 {
125 return jndiProviderUrl;
126 }
127
128 public void setJndiProviderUrl(String jndiProviderUrl)
129 {
130 this.jndiProviderUrl = jndiProviderUrl;
131 }
132
133 public Map getJndiProviderProperties()
134 {
135 return jndiProviderProperties;
136 }
137
138 public void setJndiProviderProperties(Map jndiProviderProperties)
139 {
140 this.jndiProviderProperties = jndiProviderProperties;
141 }
142 }