1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.jms.jndi; |
8 | |
|
9 | |
import org.mule.api.MuleException; |
10 | |
import org.mule.api.lifecycle.InitialisationException; |
11 | |
|
12 | |
import java.util.Hashtable; |
13 | |
import java.util.Map; |
14 | |
|
15 | |
import javax.naming.Context; |
16 | |
import javax.naming.InitialContext; |
17 | |
import javax.naming.NamingException; |
18 | |
import javax.naming.spi.InitialContextFactory; |
19 | |
|
20 | |
import org.apache.commons.logging.Log; |
21 | |
import org.apache.commons.logging.LogFactory; |
22 | |
|
23 | 0 | public abstract class AbstractJndiNameResolver implements JndiNameResolver |
24 | |
{ |
25 | |
|
26 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
27 | |
|
28 | |
private String jndiProviderUrl; |
29 | |
private String jndiInitialFactory; |
30 | |
private Map jndiProviderProperties; |
31 | |
|
32 | |
|
33 | 0 | private InitialContextFactory contextFactory = new InitialContextFactory() |
34 | 0 | { |
35 | |
public Context getInitialContext(Hashtable<?, ?> hashtable) throws NamingException |
36 | |
{ |
37 | 0 | return new InitialContext(hashtable); |
38 | |
} |
39 | |
}; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
protected Context createInitialContext() throws NamingException |
49 | |
{ |
50 | 0 | return contextFactory.getInitialContext(getContextProperties()); |
51 | |
} |
52 | |
|
53 | |
protected Hashtable getContextProperties() |
54 | |
{ |
55 | 0 | if ((jndiInitialFactory == null) && (jndiProviderProperties == null |
56 | |
|| !jndiProviderProperties.containsKey(Context.INITIAL_CONTEXT_FACTORY))) |
57 | |
{ |
58 | 0 | throw new IllegalArgumentException("Undefined value for jndiInitialFactory property"); |
59 | |
} |
60 | |
|
61 | 0 | Hashtable<String, Object> props = new Hashtable<String, Object>(); |
62 | |
|
63 | 0 | if (jndiInitialFactory != null) |
64 | |
{ |
65 | 0 | props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory); |
66 | |
} |
67 | |
|
68 | 0 | if (jndiProviderUrl != null) |
69 | |
{ |
70 | 0 | props.put(Context.PROVIDER_URL, jndiProviderUrl); |
71 | |
} |
72 | |
|
73 | 0 | if (jndiProviderProperties != null) |
74 | |
{ |
75 | 0 | props.putAll(jndiProviderProperties); |
76 | |
} |
77 | |
|
78 | 0 | return props; |
79 | |
} |
80 | |
|
81 | |
public String getJndiProviderUrl() |
82 | |
{ |
83 | 0 | return jndiProviderUrl; |
84 | |
} |
85 | |
|
86 | |
public void setJndiProviderUrl(String jndiProviderUrl) |
87 | |
{ |
88 | 0 | this.jndiProviderUrl = jndiProviderUrl; |
89 | 0 | } |
90 | |
|
91 | |
public String getJndiInitialFactory() |
92 | |
{ |
93 | 0 | return jndiInitialFactory; |
94 | |
} |
95 | |
|
96 | |
public void setJndiInitialFactory(String jndiInitialFactory) |
97 | |
{ |
98 | 0 | this.jndiInitialFactory = jndiInitialFactory; |
99 | 0 | } |
100 | |
|
101 | |
public Map getJndiProviderProperties() |
102 | |
{ |
103 | 0 | return jndiProviderProperties; |
104 | |
} |
105 | |
|
106 | |
public void setJndiProviderProperties(Map jndiProviderProperties) |
107 | |
{ |
108 | 0 | this.jndiProviderProperties = jndiProviderProperties; |
109 | 0 | } |
110 | |
|
111 | |
public InitialContextFactory getContextFactory() |
112 | |
{ |
113 | 0 | return contextFactory; |
114 | |
} |
115 | |
|
116 | |
public void setContextFactory(InitialContextFactory contextFactory) |
117 | |
{ |
118 | 0 | if (contextFactory == null) |
119 | |
{ |
120 | 0 | throw new IllegalArgumentException("Context factory cannot be null"); |
121 | |
} |
122 | |
|
123 | 0 | this.contextFactory = contextFactory; |
124 | 0 | } |
125 | |
|
126 | |
public void dispose() |
127 | |
{ |
128 | |
|
129 | 0 | } |
130 | |
|
131 | |
public void initialise() throws InitialisationException |
132 | |
{ |
133 | |
|
134 | 0 | } |
135 | |
|
136 | |
public void start() throws MuleException |
137 | |
{ |
138 | |
|
139 | 0 | } |
140 | |
|
141 | |
public void stop() throws MuleException |
142 | |
{ |
143 | |
|
144 | 0 | } |
145 | |
} |