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