1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transaction.lookup; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.impl.container.JndiContextHelper; |
15 | |
import org.mule.umo.lifecycle.InitialisationException; |
16 | |
import org.mule.umo.manager.UMOTransactionManagerFactory; |
17 | |
import org.mule.util.StringUtils; |
18 | |
|
19 | |
import java.util.Map; |
20 | |
|
21 | |
import javax.naming.Context; |
22 | |
import javax.naming.NamingException; |
23 | |
import javax.transaction.TransactionManager; |
24 | |
|
25 | |
import org.apache.commons.logging.Log; |
26 | |
import org.apache.commons.logging.LogFactory; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class GenericTransactionManagerLookupFactory implements UMOTransactionManagerFactory |
38 | |
{ |
39 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
40 | |
|
41 | |
protected Context context; |
42 | |
|
43 | |
private Map environment; |
44 | |
|
45 | |
private TransactionManager txManager; |
46 | |
|
47 | |
private String jndiName; |
48 | |
|
49 | |
public String getJndiName() |
50 | |
{ |
51 | 0 | return jndiName; |
52 | |
} |
53 | |
|
54 | |
public void setJndiName(final String jndiName) |
55 | |
{ |
56 | 0 | this.jndiName = jndiName; |
57 | 0 | } |
58 | |
|
59 | |
public TransactionManager getTxManager() |
60 | |
{ |
61 | 0 | return txManager; |
62 | |
} |
63 | |
|
64 | |
public void setTxManager(final TransactionManager txManager) |
65 | |
{ |
66 | 0 | this.txManager = txManager; |
67 | 0 | } |
68 | |
|
69 | |
public Map getEnvironment() |
70 | |
{ |
71 | 0 | return environment; |
72 | |
} |
73 | |
|
74 | |
public void setEnvironment(final Map environment) |
75 | |
{ |
76 | 0 | this.environment = environment; |
77 | 0 | } |
78 | |
|
79 | |
public Context getContext() |
80 | |
{ |
81 | 0 | return context; |
82 | |
} |
83 | |
|
84 | |
public void setContext(final Context context) |
85 | |
{ |
86 | 0 | this.context = context; |
87 | 0 | } |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public TransactionManager create() throws Exception |
93 | |
{ |
94 | |
|
95 | 0 | initialise(); |
96 | 0 | if (txManager == null) |
97 | |
{ |
98 | 0 | txManager = (TransactionManager) context.lookup(jndiName); |
99 | |
} |
100 | |
|
101 | 0 | return txManager; |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public void initialise() throws InitialisationException |
118 | |
{ |
119 | 0 | if (txManager == null && StringUtils.isEmpty(StringUtils.trim(jndiName))) |
120 | |
{ |
121 | 0 | throw new InitialisationException(CoreMessages.propertiesNotSet("jndiName"), this); |
122 | |
} |
123 | |
|
124 | |
try |
125 | |
{ |
126 | 0 | if (context == null) |
127 | |
{ |
128 | 0 | context = JndiContextHelper.initialise(getEnvironment()); |
129 | |
} |
130 | |
} |
131 | 0 | catch (NamingException e) |
132 | |
{ |
133 | 0 | throw new InitialisationException(CoreMessages.failedToCreate("Jndi context"), |
134 | |
e, this); |
135 | 0 | } |
136 | 0 | } |
137 | |
} |