1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl.container; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.umo.lifecycle.InitialisationException; |
15 | |
import org.mule.umo.manager.ContainerException; |
16 | |
import org.mule.umo.manager.ObjectNotFoundException; |
17 | |
import org.mule.util.ObjectUtils; |
18 | |
|
19 | |
import java.io.Reader; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
import javax.naming.Context; |
23 | |
import javax.naming.InitialContext; |
24 | |
import javax.naming.Name; |
25 | |
import javax.naming.NamingException; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class JndiContainerContext extends AbstractContainerContext |
33 | |
{ |
34 | |
protected volatile Context context; |
35 | |
private volatile Map environment; |
36 | |
|
37 | |
public JndiContainerContext() |
38 | |
{ |
39 | 6 | super("jndi"); |
40 | 6 | } |
41 | |
|
42 | |
protected JndiContainerContext(String name) |
43 | |
{ |
44 | 0 | super(name); |
45 | 0 | } |
46 | |
|
47 | |
public Map getEnvironment() |
48 | |
{ |
49 | 10 | return environment; |
50 | |
} |
51 | |
|
52 | |
public void setEnvironment(Map environment) |
53 | |
{ |
54 | 10 | this.environment = environment; |
55 | 10 | } |
56 | |
|
57 | |
public Context getContext() |
58 | |
{ |
59 | 12 | return context; |
60 | |
} |
61 | |
|
62 | |
public void setContext(InitialContext context) |
63 | |
{ |
64 | 4 | this.context = context; |
65 | 4 | } |
66 | |
|
67 | |
public Object getComponent(Object key) throws ObjectNotFoundException |
68 | |
{ |
69 | |
try |
70 | |
{ |
71 | 8 | if (key == null) |
72 | |
{ |
73 | 2 | throw new ObjectNotFoundException("null"); |
74 | |
} |
75 | 6 | if (key instanceof Name) |
76 | |
{ |
77 | 0 | return context.lookup((Name) key); |
78 | |
} |
79 | 6 | else if (key instanceof Class) |
80 | |
{ |
81 | 2 | return context.lookup(((Class) key).getName()); |
82 | |
} |
83 | |
else |
84 | |
{ |
85 | 4 | return context.lookup(key.toString()); |
86 | |
} |
87 | |
} |
88 | 2 | catch (NamingException e) |
89 | |
{ |
90 | 2 | throw new ObjectNotFoundException(ObjectUtils.toString(key, "null"), e); |
91 | |
} |
92 | |
} |
93 | |
|
94 | |
public void configure(Reader configuration) throws ContainerException |
95 | |
{ |
96 | 0 | throw new UnsupportedOperationException("configure(Reader)"); |
97 | |
} |
98 | |
|
99 | |
public void initialise() throws InitialisationException |
100 | |
{ |
101 | |
try |
102 | |
{ |
103 | 12 | if (context == null) |
104 | |
{ |
105 | 10 | context = JndiContextHelper.initialise(getEnvironment()); |
106 | |
} |
107 | |
} |
108 | 0 | catch (NamingException e) |
109 | |
{ |
110 | 0 | throw new InitialisationException(CoreMessages.failedToCreate("Jndi context"), e, this); |
111 | 12 | } |
112 | 12 | } |
113 | |
} |