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