1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.builders; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.config.i18n.CoreMessages; |
15 | |
import org.mule.impl.endpoint.MuleEndpoint; |
16 | |
import org.mule.impl.endpoint.MuleEndpointURI; |
17 | |
import org.mule.umo.UMOFilter; |
18 | |
import org.mule.umo.UMOTransactionConfig; |
19 | |
import org.mule.umo.endpoint.UMOEndpoint; |
20 | |
import org.mule.umo.lifecycle.InitialisationException; |
21 | |
import org.mule.umo.transformer.UMOTransformer; |
22 | |
import org.mule.util.MuleObjectHelper; |
23 | |
|
24 | |
import java.lang.reflect.Method; |
25 | |
import java.util.Map; |
26 | |
|
27 | |
import org.apache.commons.logging.Log; |
28 | |
import org.apache.commons.logging.LogFactory; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class EndpointReference |
39 | |
{ |
40 | |
|
41 | |
|
42 | |
|
43 | 0 | protected static final Log logger = LogFactory.getLog(EndpointReference.class); |
44 | |
|
45 | |
private String propertyName; |
46 | |
private String endpointName; |
47 | |
private String address; |
48 | |
private String transformer; |
49 | |
private String responseTransformer; |
50 | |
private String createConnector; |
51 | |
private Object object; |
52 | |
private Map properties; |
53 | |
private UMOFilter filter; |
54 | |
private UMOTransactionConfig transactionConfig; |
55 | |
|
56 | |
public EndpointReference(String propertyName, |
57 | |
String endpointName, |
58 | |
String address, |
59 | |
String transformer, |
60 | |
String responseTransformer, |
61 | |
String createConnector, |
62 | |
Object object) |
63 | 0 | { |
64 | 0 | this.propertyName = propertyName; |
65 | 0 | this.endpointName = endpointName; |
66 | 0 | this.address = address; |
67 | 0 | this.transformer = transformer; |
68 | 0 | this.responseTransformer = responseTransformer; |
69 | 0 | this.object = object; |
70 | 0 | this.createConnector = createConnector; |
71 | 0 | } |
72 | |
|
73 | |
public String getPropertyName() |
74 | |
{ |
75 | 0 | return propertyName; |
76 | |
} |
77 | |
|
78 | |
public String getEndpointName() |
79 | |
{ |
80 | 0 | return endpointName; |
81 | |
} |
82 | |
|
83 | |
public Object getObject() |
84 | |
{ |
85 | 0 | return object; |
86 | |
} |
87 | |
|
88 | |
public UMOTransactionConfig getTransactionConfig() |
89 | |
{ |
90 | 0 | return transactionConfig; |
91 | |
} |
92 | |
|
93 | |
public void setTransactionConfig(UMOTransactionConfig transactionConfig) |
94 | |
{ |
95 | 0 | this.transactionConfig = transactionConfig; |
96 | 0 | } |
97 | |
|
98 | |
public UMOFilter getFilter() |
99 | |
{ |
100 | 0 | return filter; |
101 | |
} |
102 | |
|
103 | |
public void setFilter(UMOFilter filter) |
104 | |
{ |
105 | 0 | this.filter = filter; |
106 | 0 | } |
107 | |
|
108 | |
public Map getProperties() |
109 | |
{ |
110 | 0 | return properties; |
111 | |
} |
112 | |
|
113 | |
public void setProperties(Map properties) |
114 | |
{ |
115 | 0 | this.properties = properties; |
116 | 0 | } |
117 | |
|
118 | |
public String getCreateConnector() |
119 | |
{ |
120 | 0 | return createConnector; |
121 | |
} |
122 | |
|
123 | |
public void setCreateConnector(String createConnector) |
124 | |
{ |
125 | 0 | this.createConnector = createConnector; |
126 | 0 | } |
127 | |
|
128 | |
public void resolveEndpoint() throws InitialisationException |
129 | |
{ |
130 | |
try |
131 | |
{ |
132 | 0 | MuleEndpoint ep = (MuleEndpoint) MuleManager.getInstance().lookupEndpoint(endpointName); |
133 | 0 | if (ep == null) |
134 | |
{ |
135 | 0 | throw new InitialisationException( |
136 | |
CoreMessages.objectNotRegisteredWithManager("Endpoint '" + endpointName + "'"), this); |
137 | |
} |
138 | 0 | if (address != null) |
139 | |
{ |
140 | 0 | if (logger.isDebugEnabled()) |
141 | |
{ |
142 | 0 | logger.debug("Overloading endpoint uri for: " + endpointName + " from " |
143 | |
+ ep.getEndpointURI().toString() + " to " + address); |
144 | |
} |
145 | 0 | ep.setEndpointURI(new MuleEndpointURI(address)); |
146 | |
} |
147 | 0 | if (createConnector != null) |
148 | |
{ |
149 | 0 | if (logger.isDebugEnabled()) |
150 | |
{ |
151 | 0 | logger.debug("Overloading createConnector property for endpoint: " + endpointName |
152 | |
+ " from " + ep.getCreateConnector() + " to " + createConnector); |
153 | |
} |
154 | 0 | ep.setCreateConnectorAsString(createConnector); |
155 | |
} |
156 | 0 | if (transformer != null) |
157 | |
{ |
158 | 0 | if (logger.isDebugEnabled()) |
159 | |
{ |
160 | 0 | logger.debug("Overloading Transformer for: " + endpointName + " from " |
161 | |
+ ep.getTransformer() + " to " + transformer); |
162 | |
} |
163 | 0 | UMOTransformer trans = MuleObjectHelper.getTransformer(transformer, " "); |
164 | 0 | ep.setTransformer(trans); |
165 | |
} |
166 | |
|
167 | 0 | if (responseTransformer != null) |
168 | |
{ |
169 | 0 | if (logger.isDebugEnabled()) |
170 | |
{ |
171 | 0 | logger.debug("Overloading responseTransformer for: " + endpointName + " from " |
172 | |
+ ep.getResponseTransformer() + " to " + responseTransformer); |
173 | |
} |
174 | 0 | UMOTransformer trans = MuleObjectHelper.getTransformer(responseTransformer, " "); |
175 | 0 | ep.setResponseTransformer(trans); |
176 | |
} |
177 | |
|
178 | 0 | if (filter != null) |
179 | |
{ |
180 | 0 | ep.setFilter(filter); |
181 | |
} |
182 | 0 | if (properties != null) |
183 | |
{ |
184 | 0 | ep.getProperties().putAll(properties); |
185 | |
} |
186 | 0 | if (transactionConfig != null) |
187 | |
{ |
188 | 0 | ep.setTransactionConfig(transactionConfig); |
189 | |
} |
190 | |
|
191 | 0 | ep.initialise(); |
192 | 0 | Method m = object.getClass().getMethod(propertyName, new Class[]{UMOEndpoint.class}); |
193 | 0 | if (m == null) |
194 | |
{ |
195 | 0 | throw new InitialisationException( |
196 | |
CoreMessages.methodWithParamsNotFoundOnObject(propertyName, |
197 | |
UMOEndpoint.class, object.getClass()), this); |
198 | |
} |
199 | |
|
200 | 0 | m.invoke(object, new Object[]{ep}); |
201 | |
} |
202 | 0 | catch (InitialisationException e) |
203 | |
{ |
204 | 0 | throw e; |
205 | |
} |
206 | 0 | catch (Exception e) |
207 | |
{ |
208 | 0 | throw new InitialisationException( |
209 | |
CoreMessages.cannotSetPropertyOnObjectWithParamType(propertyName, |
210 | |
object.getClass(), UMOEndpoint.class), e, this); |
211 | 0 | } |
212 | 0 | } |
213 | |
|
214 | |
public String toString() |
215 | |
{ |
216 | 0 | return "EndpointReference{" + "propertyName='" + propertyName + "'" + ", endpointName='" |
217 | |
+ endpointName + "'" + ", address='" + address + "'" + ", transformer='" + transformer + "'" |
218 | |
+ ", responseTransformer='" + responseTransformer + "'" + ", object=" + object |
219 | |
+ ", properties=" + properties + ", filter=" + filter + ", transactionConfig=" |
220 | |
+ transactionConfig + "}"; |
221 | |
} |
222 | |
} |