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.ConfigurationBuilder; |
15 | |
import org.mule.config.ConfigurationException; |
16 | |
import org.mule.config.MuleConfiguration; |
17 | |
import org.mule.config.MuleDtdResolver; |
18 | |
import org.mule.config.MuleProperties; |
19 | |
import org.mule.config.PoolingProfile; |
20 | |
import org.mule.config.QueueProfile; |
21 | |
import org.mule.config.ReaderResource; |
22 | |
import org.mule.config.ThreadingProfile; |
23 | |
import org.mule.config.converters.ConnectorConverter; |
24 | |
import org.mule.config.converters.EndpointConverter; |
25 | |
import org.mule.config.converters.EndpointURIConverter; |
26 | |
import org.mule.config.converters.TransactionFactoryConverter; |
27 | |
import org.mule.config.converters.TransformerConverter; |
28 | |
import org.mule.config.i18n.CoreMessages; |
29 | |
import org.mule.config.pool.CommonsPoolFactory; |
30 | |
import org.mule.impl.DefaultLifecycleAdapter; |
31 | |
import org.mule.impl.MuleDescriptor; |
32 | |
import org.mule.impl.MuleTransactionConfig; |
33 | |
import org.mule.impl.endpoint.MuleEndpoint; |
34 | |
import org.mule.impl.model.ModelFactory; |
35 | |
import org.mule.impl.model.resolvers.DynamicEntryPointResolver; |
36 | |
import org.mule.impl.security.MuleSecurityManager; |
37 | |
import org.mule.interceptors.InterceptorStack; |
38 | |
import org.mule.providers.AbstractConnector; |
39 | |
import org.mule.providers.ConnectionStrategy; |
40 | |
import org.mule.routing.LoggingCatchAllStrategy; |
41 | |
import org.mule.routing.inbound.InboundRouterCollection; |
42 | |
import org.mule.routing.nested.NestedRouter; |
43 | |
import org.mule.routing.nested.NestedRouterCollection; |
44 | |
import org.mule.routing.outbound.OutboundRouterCollection; |
45 | |
import org.mule.routing.response.ResponseRouterCollection; |
46 | |
import org.mule.transaction.constraints.BatchConstraint; |
47 | |
import org.mule.umo.UMODescriptor; |
48 | |
import org.mule.umo.UMOEncryptionStrategy; |
49 | |
import org.mule.umo.UMOInterceptor; |
50 | |
import org.mule.umo.UMOInterceptorStack; |
51 | |
import org.mule.umo.UMOTransactionFactory; |
52 | |
import org.mule.umo.endpoint.UMOEndpoint; |
53 | |
import org.mule.umo.endpoint.UMOEndpointURI; |
54 | |
import org.mule.umo.lifecycle.InitialisationException; |
55 | |
import org.mule.umo.manager.ContainerException; |
56 | |
import org.mule.umo.manager.UMOAgent; |
57 | |
import org.mule.umo.manager.UMOContainerContext; |
58 | |
import org.mule.umo.manager.UMOManager; |
59 | |
import org.mule.umo.manager.UMOTransactionManagerFactory; |
60 | |
import org.mule.umo.model.UMOModel; |
61 | |
import org.mule.umo.provider.UMOConnector; |
62 | |
import org.mule.umo.routing.UMOInboundRouterCollection; |
63 | |
import org.mule.umo.routing.UMONestedRouterCollection; |
64 | |
import org.mule.umo.routing.UMOOutboundRouter; |
65 | |
import org.mule.umo.routing.UMOOutboundRouterCollection; |
66 | |
import org.mule.umo.routing.UMOResponseRouterCollection; |
67 | |
import org.mule.umo.security.UMOEndpointSecurityFilter; |
68 | |
import org.mule.umo.security.UMOSecurityManager; |
69 | |
import org.mule.umo.security.UMOSecurityProvider; |
70 | |
import org.mule.umo.transformer.UMOTransformer; |
71 | |
import org.mule.util.ArrayUtils; |
72 | |
import org.mule.util.ClassUtils; |
73 | |
import org.mule.util.IOUtils; |
74 | |
import org.mule.util.PropertiesUtils; |
75 | |
import org.mule.util.StringUtils; |
76 | |
import org.mule.util.queue.EventFilePersistenceStrategy; |
77 | |
|
78 | |
import java.beans.ExceptionListener; |
79 | |
import java.io.IOException; |
80 | |
import java.io.InputStream; |
81 | |
import java.io.InputStreamReader; |
82 | |
import java.util.ArrayList; |
83 | |
import java.util.HashMap; |
84 | |
import java.util.Iterator; |
85 | |
import java.util.List; |
86 | |
import java.util.Map; |
87 | |
import java.util.Properties; |
88 | |
|
89 | |
import org.apache.commons.beanutils.ConvertUtils; |
90 | |
import org.apache.commons.digester.AbstractObjectCreationFactory; |
91 | |
import org.apache.commons.digester.Digester; |
92 | |
import org.apache.commons.digester.ObjectCreateRule; |
93 | |
import org.apache.commons.digester.Rule; |
94 | |
import org.apache.commons.digester.SetNextRule; |
95 | |
import org.apache.commons.digester.SetPropertiesRule; |
96 | |
import org.xml.sax.Attributes; |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | 0 | public class MuleXmlConfigurationBuilder extends AbstractDigesterConfiguration |
104 | |
implements ConfigurationBuilder |
105 | |
{ |
106 | 0 | public static final String DEFAULT_ENTRY_POINT_RESOLVER = DynamicEntryPointResolver.class.getName(); |
107 | 0 | public static final String DEFAULT_LIFECYCLE_ADAPTER = DefaultLifecycleAdapter.class.getName(); |
108 | 0 | public static final String DEFAULT_ENDPOINT = MuleEndpoint.class.getName(); |
109 | 0 | public static final String DEFAULT_TRANSACTION_CONFIG = MuleTransactionConfig.class.getName(); |
110 | 0 | public static final String DEFAULT_DESCRIPTOR = MuleDescriptor.class.getName(); |
111 | 0 | public static final String DEFAULT_SECURITY_MANAGER = MuleSecurityManager.class.getName(); |
112 | 0 | public static final String DEFAULT_OUTBOUND_ROUTER_COLLECTION = OutboundRouterCollection.class.getName(); |
113 | 0 | public static final String DEFAULT_INBOUND_ROUTER_COLLECTION = InboundRouterCollection.class.getName(); |
114 | 0 | public static final String DEFAULT_NESTED_ROUTER_COLLECTION = NestedRouterCollection.class.getName(); |
115 | 0 | public static final String DEFAULT_RESPONSE_ROUTER_COLLECTION = ResponseRouterCollection.class.getName(); |
116 | 0 | public static final String DEFAULT_NESTED_ROUTER = NestedRouter.class.getName(); |
117 | 0 | public static final String DEFAULT_CATCH_ALL_STRATEGY = LoggingCatchAllStrategy.class.getName(); |
118 | 0 | public static final String DEFAULT_POOL_FACTORY = CommonsPoolFactory.class.getName(); |
119 | 0 | public static final String THREADING_PROFILE = ThreadingProfile.class.getName(); |
120 | 0 | public static final String POOLING_PROFILE = PoolingProfile.class.getName(); |
121 | 0 | public static final String QUEUE_PROFILE = QueueProfile.class.getName(); |
122 | |
|
123 | 0 | public static final String PERSISTENCE_STRATEGY_INTERFACE = EventFilePersistenceStrategy.class.getName(); |
124 | 0 | public static final String INBOUND_MESSAGE_ROUTER_INTERFACE = UMOInboundRouterCollection.class.getName(); |
125 | 0 | public static final String NESTED_MESSAGE_ROUTER_INTERFACE = UMONestedRouterCollection.class.getName(); |
126 | 0 | public static final String RESPONSE_MESSAGE_ROUTER_INTERFACE = UMOResponseRouterCollection.class.getName(); |
127 | 0 | public static final String OUTBOUND_MESSAGE_ROUTER_INTERFACE = UMOOutboundRouterCollection.class.getName(); |
128 | 0 | public static final String TRANSFORMER_INTERFACE = UMOTransformer.class.getName(); |
129 | 0 | public static final String TRANSACTION_MANAGER_FACTORY_INTERFACE = UMOTransactionManagerFactory.class.getName(); |
130 | 0 | public static final String SECURITY_PROVIDER_INTERFACE = UMOSecurityProvider.class.getName(); |
131 | 0 | public static final String ENCRYPTION_STRATEGY_INTERFACE = UMOEncryptionStrategy.class.getName(); |
132 | 0 | public static final String ENDPOINT_SECURITY_FILTER_INTERFACE = UMOEndpointSecurityFilter.class.getName(); |
133 | 0 | public static final String AGENT_INTERFACE = UMOAgent.class.getName(); |
134 | 0 | public static final String TRANSACTION_FACTORY_INTERFACE = UMOTransactionFactory.class.getName(); |
135 | 0 | public static final String TRANSACTION_CONSTRAINT_INTERFACE = BatchConstraint.class.getName(); |
136 | 0 | public static final String CONNECTOR_INTERFACE = UMOConnector.class.getName(); |
137 | 0 | public static final String INTERCEPTOR_INTERFACE = UMOInterceptor.class.getName(); |
138 | 0 | public static final String ROUTER_INTERFACE = UMOOutboundRouter.class.getName(); |
139 | 0 | public static final String EXCEPTION_STRATEGY_INTERFACE = ExceptionListener.class.getName(); |
140 | 0 | public static final String CONNECTION_STRATEGY_INTERFACE = ConnectionStrategy.class.getName(); |
141 | |
|
142 | |
protected UMOManager manager; |
143 | |
|
144 | 0 | private final List transformerReferences = new ArrayList(); |
145 | 0 | private final List endpointReferences = new ArrayList(); |
146 | |
|
147 | |
public MuleXmlConfigurationBuilder() throws ConfigurationException |
148 | |
{ |
149 | 0 | super(System.getProperty(MuleProperties.XML_VALIDATE_SYSTEM_PROPERTY, "true") |
150 | |
.equalsIgnoreCase("true"), System.getProperty(MuleProperties.XML_DTD_SYSTEM_PROPERTY, |
151 | |
MuleDtdResolver.DEFAULT_MULE_DTD)); |
152 | |
|
153 | 0 | ConvertUtils.register(new EndpointConverter(), UMOEndpoint.class); |
154 | 0 | ConvertUtils.register(new TransformerConverter(), UMOTransformer.class); |
155 | 0 | ConvertUtils.register(new ConnectorConverter(), UMOConnector.class); |
156 | 0 | ConvertUtils.register(new TransactionFactoryConverter(), UMOTransactionFactory.class); |
157 | 0 | ConvertUtils.register(new EndpointURIConverter(), UMOEndpointURI.class); |
158 | |
|
159 | 0 | String path = getRootName(); |
160 | 0 | addManagerRules(digester, path); |
161 | 0 | addServerPropertiesRules(path + "/environment-properties", "addProperties", 0); |
162 | 0 | addContainerContextRules(path + "/container-context", "setContainerContext", 0); |
163 | |
|
164 | 0 | addMuleConfigurationRules(digester, path); |
165 | 0 | addTransformerRules(digester, path); |
166 | 0 | addSecurityManagerRules(digester, path); |
167 | 0 | addTransactionManagerRules(digester, path); |
168 | 0 | addGlobalEndpointRules(digester, path); |
169 | 0 | addEndpointIdentifierRules(digester, path); |
170 | 0 | addInterceptorStackRules(digester, path); |
171 | 0 | addConnectorRules(digester, path); |
172 | 0 | addAgentRules(digester, path); |
173 | |
|
174 | 0 | addModelRules(digester, path); |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | 0 | } |
181 | |
|
182 | |
public String getRootName() |
183 | |
{ |
184 | 0 | return "mule-configuration"; |
185 | |
} |
186 | |
|
187 | |
public UMOManager configure(String configResources) throws ConfigurationException |
188 | |
{ |
189 | 0 | return configure(configResources, null); |
190 | |
} |
191 | |
|
192 | |
public UMOManager configure(String configResources, String startupPropertiesFile) |
193 | |
throws ConfigurationException |
194 | |
{ |
195 | |
try |
196 | |
{ |
197 | 0 | String[] resources = StringUtils.splitAndTrim(configResources, ","); |
198 | 0 | if (logger.isDebugEnabled()) |
199 | |
{ |
200 | 0 | logger.debug("There is/are " + resources.length + " configuration resource(s): " + ArrayUtils.toString(resources)); |
201 | |
} |
202 | 0 | MuleManager.getConfiguration().setConfigResources(resources); |
203 | 0 | ReaderResource[] readers = new ReaderResource[resources.length]; |
204 | |
String resource; |
205 | 0 | for (int i = 0; i < resources.length; i++) |
206 | |
{ |
207 | 0 | resource = resources[i]; |
208 | 0 | readers[i] = new ReaderResource(resource, |
209 | |
new InputStreamReader(loadResource(resource), configEncoding)); |
210 | |
} |
211 | |
|
212 | |
|
213 | 0 | if (startupPropertiesFile != null) |
214 | |
{ |
215 | 0 | return configure(readers, PropertiesUtils.loadProperties(startupPropertiesFile, getClass())); |
216 | |
} |
217 | |
else |
218 | 0 | return configure(readers, null); |
219 | |
|
220 | |
} |
221 | 0 | catch (Exception e) |
222 | |
{ |
223 | 0 | throw new ConfigurationException(e); |
224 | |
} |
225 | |
} |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
protected InputStream loadResource(String configResource) throws ConfigurationException |
231 | |
{ |
232 | |
try |
233 | |
{ |
234 | 0 | InputStream input = IOUtils.getResourceAsStream(configResource, getClass()); |
235 | 0 | if (input == null) |
236 | |
{ |
237 | 0 | throw new ConfigurationException(CoreMessages.cannotLoadFromClasspath(configResource)); |
238 | |
} |
239 | 0 | return input; |
240 | |
} |
241 | 0 | catch (IOException e) |
242 | |
{ |
243 | 0 | throw new ConfigurationException(CoreMessages.cannotLoadFromClasspath(configResource), e); |
244 | |
} |
245 | |
} |
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
public UMOManager configure(ReaderResource[] configResources) throws ConfigurationException |
252 | |
{ |
253 | 0 | return configure(configResources, null); |
254 | |
} |
255 | |
|
256 | |
public UMOManager configure(ReaderResource[] configResources, Properties startupProperties) |
257 | |
throws ConfigurationException |
258 | |
{ |
259 | 0 | if (startupProperties != null) |
260 | |
{ |
261 | 0 | ((MuleManager)MuleManager.getInstance()).addProperties(startupProperties); |
262 | |
} |
263 | |
|
264 | 0 | manager = (MuleManager)process(configResources); |
265 | 0 | if (manager == null) |
266 | |
{ |
267 | 0 | throw new ConfigurationException( |
268 | |
CoreMessages.failedToCreateManagerInstance("Are you using a correct configuration builder?")); |
269 | |
} |
270 | |
try |
271 | |
{ |
272 | 0 | setContainerProperties(); |
273 | 0 | setTransformers(); |
274 | 0 | setGlobalEndpoints(); |
275 | 0 | if (System.getProperty(MuleProperties.MULE_START_AFTER_CONFIG_SYSTEM_PROPERTY, "true") |
276 | |
.equalsIgnoreCase("true")) |
277 | |
{ |
278 | 0 | manager.start(); |
279 | |
} |
280 | |
} |
281 | 0 | catch (Exception e) |
282 | |
{ |
283 | 0 | throw new ConfigurationException(CoreMessages.objectFailedToInitialise("MuleManager"), e); |
284 | 0 | } |
285 | 0 | return manager; |
286 | |
} |
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
public boolean isConfigured() |
294 | |
{ |
295 | 0 | return manager != null; |
296 | |
} |
297 | |
|
298 | |
protected void setContainerProperties() throws ContainerException |
299 | |
{ |
300 | 0 | UMOContainerContext ctx = manager.getContainerContext(); |
301 | |
try |
302 | |
{ |
303 | 0 | for (Iterator iterator = containerReferences.iterator(); iterator.hasNext();) |
304 | |
{ |
305 | 0 | ContainerReference reference = (ContainerReference)iterator.next(); |
306 | 0 | reference.resolveReference(ctx); |
307 | |
} |
308 | |
} |
309 | |
finally |
310 | |
{ |
311 | 0 | containerReferences.clear(); |
312 | 0 | } |
313 | 0 | } |
314 | |
|
315 | |
protected void setTransformers() throws InitialisationException |
316 | |
{ |
317 | |
try |
318 | |
{ |
319 | 0 | for (Iterator iterator = transformerReferences.iterator(); iterator.hasNext();) |
320 | |
{ |
321 | 0 | TransformerReference reference = (TransformerReference)iterator.next(); |
322 | 0 | reference.resolveTransformer(); |
323 | |
} |
324 | |
} |
325 | |
finally |
326 | |
{ |
327 | 0 | transformerReferences.clear(); |
328 | 0 | } |
329 | 0 | } |
330 | |
|
331 | |
protected void setGlobalEndpoints() throws InitialisationException |
332 | |
{ |
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | 0 | UMOManager manager = MuleManager.getInstance(); |
338 | |
|
339 | |
|
340 | |
|
341 | 0 | Map endpoints = new HashMap(manager.getEndpoints()); |
342 | 0 | for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();) |
343 | |
{ |
344 | 0 | UMOEndpoint ep = (UMOEndpoint)iterator.next(); |
345 | 0 | ep.initialise(); |
346 | 0 | manager.unregisterEndpoint(ep.getName()); |
347 | 0 | manager.registerEndpoint(ep); |
348 | |
} |
349 | |
|
350 | |
try |
351 | |
{ |
352 | 0 | for (Iterator iterator = endpointReferences.iterator(); iterator.hasNext();) |
353 | |
{ |
354 | 0 | EndpointReference reference = (EndpointReference)iterator.next(); |
355 | 0 | reference.resolveEndpoint(); |
356 | |
} |
357 | |
} |
358 | |
finally |
359 | |
{ |
360 | 0 | endpointReferences.clear(); |
361 | 0 | } |
362 | 0 | } |
363 | |
|
364 | |
protected void addManagerRules(Digester digester, String path) |
365 | |
{ |
366 | 0 | digester.addFactoryCreate(path, new AbstractObjectCreationFactory() |
367 | |
{ |
368 | 0 | public Object createObject(Attributes attributes) throws Exception |
369 | |
{ |
370 | 0 | manager = MuleManager.getInstance(); |
371 | 0 | return manager; |
372 | |
} |
373 | |
}); |
374 | 0 | digester.addSetProperties(path); |
375 | 0 | } |
376 | |
|
377 | |
protected void addMuleConfigurationRules(Digester digester, String path) |
378 | |
{ |
379 | 0 | digester.addSetProperties(path); |
380 | |
|
381 | 0 | path += "/mule-environment-properties"; |
382 | 0 | digester.addObjectCreate(path, MuleConfiguration.class); |
383 | 0 | addSetPropertiesRule(path, digester); |
384 | |
|
385 | |
|
386 | 0 | addPoolingProfileRules(digester, path); |
387 | |
|
388 | |
|
389 | 0 | addQueueProfileRules(digester, path); |
390 | |
|
391 | |
|
392 | 0 | digester.addObjectCreate(path + "/threading-profile", THREADING_PROFILE); |
393 | 0 | SetPropertiesRule threadingRule = new SetPropertiesRule(); |
394 | 0 | threadingRule.addAlias("poolExhaustedAction", "poolExhaustedActionString"); |
395 | 0 | digester.addRule(path + "/threading-profile", threadingRule); |
396 | 0 | digester.addRule(path + "/threading-profile", new Rule() |
397 | |
{ |
398 | |
private String id; |
399 | |
|
400 | |
public void begin(String s, String s1, Attributes attributes) throws Exception |
401 | |
{ |
402 | 0 | id = attributes.getValue("id"); |
403 | 0 | } |
404 | |
|
405 | 0 | public void end(String s, String s1) throws Exception |
406 | |
{ |
407 | 0 | ThreadingProfile tp = (ThreadingProfile)digester.peek(); |
408 | 0 | MuleConfiguration cfg = (MuleConfiguration)digester.peek(1); |
409 | |
|
410 | 0 | if ("default".equals(id)) |
411 | |
{ |
412 | 0 | cfg.setDefaultThreadingProfile(tp); |
413 | 0 | cfg.setMessageDispatcherThreadingProfile(tp); |
414 | 0 | cfg.setMessageReceiverThreadingProfile(tp); |
415 | 0 | cfg.setComponentThreadingProfile(tp); |
416 | |
} |
417 | 0 | else if ("messageReceiver".equals(id) || "receiver".equals(id)) |
418 | |
{ |
419 | 0 | cfg.setMessageReceiverThreadingProfile(tp); |
420 | |
} |
421 | 0 | else if ("messageDispatcher".equals(id) || "dispatcher".equals(id)) |
422 | |
{ |
423 | 0 | cfg.setMessageDispatcherThreadingProfile(tp); |
424 | |
} |
425 | 0 | else if ("component".equals(id)) |
426 | |
{ |
427 | 0 | cfg.setComponentThreadingProfile(tp); |
428 | |
} |
429 | 0 | } |
430 | |
}); |
431 | |
|
432 | |
|
433 | 0 | digester.addObjectCreate(path + "/persistence-strategy", PERSISTENCE_STRATEGY_INTERFACE, "className"); |
434 | 0 | addMulePropertiesRule(path + "/persistence-strategy", digester); |
435 | 0 | digester.addSetNext(path + "/persistence-strategy", "setPersistenceStrategy"); |
436 | |
|
437 | |
|
438 | 0 | digester.addObjectCreate(path + "/connection-strategy", CONNECTION_STRATEGY_INTERFACE, "className"); |
439 | 0 | addMulePropertiesRule(path + "/connection-strategy", digester); |
440 | |
|
441 | |
|
442 | 0 | digester.addRule(path + "/connection-strategy", new SetNextRule("setConnectionStrategy") |
443 | |
{ |
444 | 0 | public void end(String s, String s1) throws Exception |
445 | |
{ |
446 | 0 | super.end(s, s1); |
447 | 0 | } |
448 | |
}); |
449 | |
|
450 | 0 | digester.addRule(path, new Rule() |
451 | |
{ |
452 | 0 | public void end(String s, String s1) throws Exception |
453 | |
{ |
454 | 0 | MuleManager.setConfiguration((MuleConfiguration)digester.peek()); |
455 | 0 | } |
456 | |
}); |
457 | 0 | } |
458 | |
|
459 | |
protected void addSecurityManagerRules(Digester digester, String path) throws ConfigurationException |
460 | |
{ |
461 | |
|
462 | 0 | path += "/security-manager"; |
463 | 0 | addObjectCreateOrGetFromContainer(path, DEFAULT_SECURITY_MANAGER, "className", "ref", false); |
464 | |
|
465 | |
|
466 | 0 | digester.addObjectCreate(path + "/security-provider", SECURITY_PROVIDER_INTERFACE, "className"); |
467 | 0 | addSetPropertiesRule(path + "/security-provider", digester); |
468 | 0 | addMulePropertiesRule(path + "/security-provider", digester); |
469 | 0 | digester.addSetNext(path + "/security-provider", "addProvider"); |
470 | |
|
471 | |
|
472 | 0 | digester.addObjectCreate(path + "/encryption-strategy", ENCRYPTION_STRATEGY_INTERFACE, "className"); |
473 | 0 | addSetPropertiesRule(path + "/encryption-strategy", digester); |
474 | 0 | addMulePropertiesRule(path + "/encryption-strategy", digester); |
475 | 0 | digester.addRule(path + "/encryption-strategy", new Rule() |
476 | |
{ |
477 | |
private String name; |
478 | |
|
479 | |
public void begin(String endpointName, String endpointName1, Attributes attributes) |
480 | |
throws Exception |
481 | |
{ |
482 | 0 | name = attributes.getValue("name"); |
483 | 0 | } |
484 | |
|
485 | 0 | public void end(String endpointName, String endpointName1) throws Exception |
486 | |
{ |
487 | 0 | UMOEncryptionStrategy s = (UMOEncryptionStrategy)digester.peek(); |
488 | 0 | ((UMOSecurityManager)digester.peek(1)).addEncryptionStrategy(name, s); |
489 | 0 | } |
490 | |
}); |
491 | 0 | digester.addSetNext(path, "setSecurityManager"); |
492 | |
|
493 | 0 | } |
494 | |
|
495 | |
protected void addTransformerRules(Digester digester, String path) throws ConfigurationException |
496 | |
{ |
497 | |
|
498 | 0 | path += "/transformers/transformer"; |
499 | 0 | addObjectCreateOrGetFromContainer(path, TRANSFORMER_INTERFACE, "className", "ref", true); |
500 | |
|
501 | 0 | addSetPropertiesRule(path, digester); |
502 | |
|
503 | 0 | addMulePropertiesRule(path, digester); |
504 | 0 | digester.addSetRoot(path, "registerTransformer"); |
505 | 0 | } |
506 | |
|
507 | |
protected void addGlobalEndpointRules(Digester digester, String path) throws ConfigurationException |
508 | |
{ |
509 | |
|
510 | 0 | path += "/global-endpoints"; |
511 | 0 | addEndpointRules(digester, path, "registerEndpoint"); |
512 | 0 | } |
513 | |
|
514 | |
protected void addEndpointIdentifierRules(Digester digester, String path) throws ConfigurationException |
515 | |
{ |
516 | |
|
517 | 0 | path += "/endpoint-identifiers/endpoint-identifier"; |
518 | 0 | digester.addRule(path, new Rule() |
519 | |
{ |
520 | 0 | private PlaceholderProcessor processor = new PlaceholderProcessor(); |
521 | |
|
522 | 0 | public void begin(String s, String s1, Attributes attributes) throws Exception |
523 | |
{ |
524 | 0 | attributes = processor.processAttributes(attributes, s1); |
525 | 0 | String name = attributes.getValue("name"); |
526 | 0 | String value = attributes.getValue("value"); |
527 | 0 | ((UMOManager)digester.getRoot()).registerEndpointIdentifier(name, value); |
528 | 0 | } |
529 | |
}); |
530 | 0 | } |
531 | |
|
532 | |
protected void addTransactionManagerRules(Digester digester, String path) throws ConfigurationException |
533 | |
{ |
534 | |
|
535 | 0 | path += "/transaction-manager"; |
536 | 0 | addObjectCreateOrGetFromContainer(path, TRANSACTION_MANAGER_FACTORY_INTERFACE, "factory", "ref", true); |
537 | 0 | addMulePropertiesRule(path, digester); |
538 | |
|
539 | 0 | digester.addSetRoot(path, "setTransactionManager"); |
540 | 0 | digester.addRule(path, new Rule() |
541 | |
{ |
542 | 0 | public void end(String s, String s1) throws Exception |
543 | |
{ |
544 | 0 | UMOTransactionManagerFactory txFactory = (UMOTransactionManagerFactory)digester.pop(); |
545 | 0 | digester.push(txFactory.create()); |
546 | 0 | } |
547 | |
}); |
548 | 0 | } |
549 | |
|
550 | |
protected void addAgentRules(Digester digester, String path) throws ConfigurationException |
551 | |
{ |
552 | |
|
553 | 0 | path += "/agents/agent"; |
554 | 0 | addObjectCreateOrGetFromContainer(path, AGENT_INTERFACE, "className", "ref", true); |
555 | 0 | addSetPropertiesRule(path, digester); |
556 | |
|
557 | 0 | addMulePropertiesRule(path, digester); |
558 | |
|
559 | 0 | digester.addSetRoot(path, "registerAgent"); |
560 | 0 | } |
561 | |
|
562 | |
protected void addConnectorRules(Digester digester, String path) throws ConfigurationException |
563 | |
{ |
564 | |
|
565 | 0 | path += "/connector"; |
566 | 0 | addObjectCreateOrGetFromContainer(path, CONNECTOR_INTERFACE, "className", "ref", true); |
567 | |
|
568 | 0 | addSetPropertiesRule(path, digester); |
569 | |
|
570 | 0 | addMulePropertiesRule(path, digester); |
571 | |
|
572 | 0 | digester.addRule(path + "/threading-profile", new Rule() |
573 | |
{ |
574 | |
private String id; |
575 | |
|
576 | |
public void begin(String s, String s1, Attributes attributes) throws Exception |
577 | |
{ |
578 | |
|
579 | 0 | MuleConfiguration cfg = MuleManager.getConfiguration(); |
580 | 0 | id = attributes.getValue("id"); |
581 | 0 | if ("default".equals(id)) |
582 | |
{ |
583 | 0 | digester.push(cfg.getDefaultThreadingProfile()); |
584 | |
} |
585 | 0 | else if ("receiver".equals(id)) |
586 | |
{ |
587 | 0 | digester.push(cfg.getMessageReceiverThreadingProfile()); |
588 | |
} |
589 | 0 | else if ("dispatcher".equals(id)) |
590 | |
{ |
591 | 0 | digester.push(cfg.getMessageDispatcherThreadingProfile()); |
592 | |
} |
593 | |
|
594 | 0 | } |
595 | |
|
596 | 0 | public void end(String s, String s1) throws Exception |
597 | |
{ |
598 | 0 | ThreadingProfile tp = (ThreadingProfile)digester.pop(); |
599 | 0 | AbstractConnector cnn = (AbstractConnector)digester.peek(); |
600 | |
|
601 | 0 | if ("default".equals(id)) |
602 | |
{ |
603 | 0 | cnn.setReceiverThreadingProfile(tp); |
604 | 0 | cnn.setDispatcherThreadingProfile(tp); |
605 | |
} |
606 | 0 | else if ("receiver".equals(id)) |
607 | |
{ |
608 | 0 | cnn.setReceiverThreadingProfile(tp); |
609 | |
} |
610 | 0 | else if ("dispatcher".equals(id)) |
611 | |
{ |
612 | 0 | cnn.setDispatcherThreadingProfile(tp); |
613 | |
} |
614 | 0 | } |
615 | |
}); |
616 | |
|
617 | 0 | SetPropertiesRule threadingRule = new SetPropertiesRule(); |
618 | 0 | threadingRule.addAlias("setPoolExhaustedAction", "setPoolExhaustedActionString"); |
619 | 0 | digester.addRule(path + "/threading-profile", threadingRule); |
620 | |
|
621 | |
|
622 | 0 | digester.addObjectCreate(path + "/connection-strategy", CONNECTION_STRATEGY_INTERFACE, "className"); |
623 | 0 | addMulePropertiesRule(path + "/connection-strategy", digester); |
624 | 0 | digester.addSetNext(path + "/connection-strategy", "setConnectionStrategy"); |
625 | |
|
626 | 0 | addExceptionStrategyRules(digester, path); |
627 | |
|
628 | |
|
629 | 0 | digester.addSetRoot(path, "registerConnector"); |
630 | 0 | } |
631 | |
|
632 | |
protected void addInterceptorStackRules(Digester digester, String path) throws ConfigurationException |
633 | |
{ |
634 | |
|
635 | 0 | path += "/interceptor-stack"; |
636 | 0 | digester.addRule(path + "/interceptor", new ObjectCreateRule(INTERCEPTOR_INTERFACE, "className") |
637 | |
{ |
638 | 0 | public void end(String s, String s1) throws Exception |
639 | |
{ |
640 | |
|
641 | 0 | } |
642 | |
}); |
643 | |
|
644 | 0 | digester.addRule(path, new Rule() |
645 | |
{ |
646 | |
public void begin(String s, String s1, Attributes attributes) throws Exception |
647 | |
{ |
648 | 0 | digester.push(attributes.getValue("name")); |
649 | 0 | } |
650 | |
|
651 | 0 | public void end(String s, String s1) throws Exception |
652 | |
{ |
653 | 0 | List list = new ArrayList(); |
654 | 0 | Object obj = digester.peek(); |
655 | 0 | while (obj instanceof UMOInterceptor) |
656 | |
{ |
657 | 0 | list.add(0, digester.pop()); |
658 | 0 | obj = digester.peek(); |
659 | |
} |
660 | 0 | InterceptorStack stack = new InterceptorStack(); |
661 | 0 | stack.setInterceptors(list); |
662 | 0 | manager.registerInterceptorStack(digester.pop().toString(), stack); |
663 | 0 | } |
664 | |
}); |
665 | |
|
666 | 0 | addMulePropertiesRule(path + "/interceptor", digester); |
667 | 0 | } |
668 | |
|
669 | |
protected void addModelRules(Digester digester, String path) throws ConfigurationException |
670 | |
{ |
671 | |
|
672 | 0 | path += "/model"; |
673 | |
|
674 | 0 | digester.addRule(path, new Rule() |
675 | |
{ |
676 | 0 | public void begin(String string, String string1, Attributes attributes) throws Exception |
677 | |
{ |
678 | |
UMOModel model; |
679 | 0 | String modelType = attributes.getValue("type"); |
680 | 0 | String modelName = attributes.getValue("name"); |
681 | 0 | if (modelType == null) |
682 | |
{ |
683 | 0 | modelType = MuleManager.getConfiguration().getModelType(); |
684 | |
} |
685 | 0 | if (modelType.equalsIgnoreCase("custom")) |
686 | |
{ |
687 | 0 | String className = attributes.getValue("className"); |
688 | 0 | if (className == null) |
689 | |
{ |
690 | 0 | throw new IllegalArgumentException( |
691 | |
"Cannot use 'custom' model type without setting the 'className' for the model"); |
692 | |
} |
693 | |
else |
694 | |
{ |
695 | 0 | model = (UMOModel)ClassUtils.instanciateClass(className, ClassUtils.NO_ARGS, |
696 | |
getClass()); |
697 | |
} |
698 | |
} |
699 | 0 | else if (modelType.equalsIgnoreCase("inherited")) |
700 | |
{ |
701 | 0 | Map models = MuleManager.getInstance().getModels(); |
702 | 0 | if(models.size()==0) |
703 | |
{ |
704 | 0 | throw new IllegalArgumentException("When using model inheritance there must be one model registered with Mule"); |
705 | |
} |
706 | 0 | model = (UMOModel)models.get(modelName); |
707 | 0 | if(model == null) |
708 | |
{ |
709 | 0 | throw new IllegalArgumentException("Cannot inherit from model '" + modelName + "'. No such model registered"); |
710 | |
} |
711 | |
} |
712 | |
else |
713 | |
{ |
714 | 0 | model = ModelFactory.createModel(modelType); |
715 | |
} |
716 | |
|
717 | 0 | digester.push(model); |
718 | 0 | } |
719 | |
}); |
720 | |
|
721 | 0 | addSetPropertiesRule(path, digester); |
722 | |
|
723 | 0 | digester.addSetRoot(path, "registerModel"); |
724 | |
|
725 | |
|
726 | 0 | digester.addObjectCreate(path + "/entry-point-resolver", DEFAULT_ENTRY_POINT_RESOLVER, "className"); |
727 | 0 | addSetPropertiesRule(path + "/entry-point-resolver", digester); |
728 | |
|
729 | 0 | digester.addSetNext(path + "/entry-point-resolver", "setEntryPointResolver"); |
730 | |
|
731 | |
|
732 | 0 | digester.addObjectCreate(path + "/component-lifecycle-adapter-factory", DEFAULT_LIFECYCLE_ADAPTER, |
733 | |
"className"); |
734 | 0 | addSetPropertiesRule(path, digester); |
735 | 0 | digester.addSetNext(path + "/component-lifecycle-adapter-factory", "setLifecycleAdapterFactory"); |
736 | |
|
737 | |
|
738 | 0 | addPoolingProfileRules(digester, path); |
739 | |
|
740 | |
|
741 | 0 | addExceptionStrategyRules(digester, path); |
742 | |
|
743 | |
|
744 | 0 | addMuleDescriptorRules(digester, path); |
745 | 0 | } |
746 | |
|
747 | |
protected void addMuleDescriptorRules(Digester digester, String path) throws ConfigurationException |
748 | |
{ |
749 | |
|
750 | 0 | path += "/mule-descriptor"; |
751 | 0 | addObjectCreateOrGetFromContainer(path, DEFAULT_DESCRIPTOR, "className", "ref", "container", false); |
752 | |
|
753 | 0 | addSetPropertiesRule(path, digester); |
754 | |
|
755 | |
|
756 | 0 | addMessageRouterRules(digester, path, "inbound"); |
757 | 0 | addMessageRouterRules(digester, path, "outbound"); |
758 | 0 | addMessageRouterRules(digester, path, "nested"); |
759 | 0 | addMessageRouterRules(digester, path, "response"); |
760 | |
|
761 | |
|
762 | 0 | addThreadingProfileRules(digester, path, "component"); |
763 | |
|
764 | |
|
765 | 0 | addPoolingProfileRules(digester, path); |
766 | |
|
767 | |
|
768 | 0 | addQueueProfileRules(digester, path); |
769 | |
|
770 | |
|
771 | 0 | digester.addRule(path + "/interceptor", new Rule() |
772 | |
{ |
773 | |
public void begin(String string, String string1, Attributes attributes) throws Exception |
774 | |
{ |
775 | 0 | String value = attributes.getValue("name"); |
776 | 0 | if (value == null) |
777 | |
{ |
778 | 0 | value = attributes.getValue("className"); |
779 | |
} |
780 | 0 | UMOManager man = (UMOManager)digester.getRoot(); |
781 | 0 | UMOInterceptorStack interceptorStack = man.lookupInterceptorStack(value); |
782 | 0 | MuleDescriptor temp = (MuleDescriptor)digester.peek(); |
783 | 0 | if (interceptorStack != null) |
784 | |
{ |
785 | 0 | temp.addInterceptor(interceptorStack); |
786 | |
} |
787 | |
else |
788 | |
{ |
789 | |
|
790 | |
|
791 | 0 | Class clazz = digester.getClassLoader().loadClass(value); |
792 | 0 | Object instance = clazz.newInstance(); |
793 | 0 | temp.addInterceptor((UMOInterceptor)instance); |
794 | 0 | digester.push(instance); |
795 | |
} |
796 | 0 | } |
797 | |
|
798 | 0 | public void end(String s, String s1) throws Exception |
799 | |
{ |
800 | 0 | if (digester.peek() instanceof UMOInterceptor) |
801 | |
{ |
802 | 0 | digester.pop(); |
803 | |
} |
804 | 0 | } |
805 | |
}); |
806 | |
|
807 | 0 | addMulePropertiesRule(path + "/interceptor", digester); |
808 | |
|
809 | |
|
810 | 0 | addExceptionStrategyRules(digester, path); |
811 | |
|
812 | 0 | addMulePropertiesRule(path, digester, "setProperties"); |
813 | 0 | digester.addSetNext(path + "/properties", "setProperties"); |
814 | |
|
815 | |
|
816 | 0 | digester.addRule(path, new Rule() |
817 | |
{ |
818 | 0 | public void end(String s, String s1) throws Exception |
819 | |
{ |
820 | 0 | UMODescriptor descriptor = (UMODescriptor)digester.peek(); |
821 | 0 | Object obj = digester.peek(1); |
822 | 0 | final UMOModel model = (UMOModel)obj; |
823 | 0 | descriptor.setModelName(model.getName()); |
824 | 0 | model.registerComponent(descriptor); |
825 | 0 | } |
826 | |
}); |
827 | 0 | } |
828 | |
|
829 | |
protected void addThreadingProfileRules(Digester digester, String path, final String type) |
830 | |
{ |
831 | |
|
832 | 0 | digester.addRule(path + "/threading-profile", new Rule() |
833 | |
{ |
834 | |
public void begin(String s, String s1, Attributes attributes) throws Exception |
835 | |
{ |
836 | |
|
837 | 0 | MuleConfiguration cfg = MuleManager.getConfiguration(); |
838 | 0 | if ("component".equals(type)) |
839 | |
{ |
840 | 0 | digester.push(cfg.getComponentThreadingProfile()); |
841 | |
} |
842 | 0 | else if ("messageReceiver".equals(type)) |
843 | |
{ |
844 | 0 | digester.push(cfg.getComponentThreadingProfile()); |
845 | |
} |
846 | 0 | else if ("messageDispatcher".equals(type)) |
847 | |
{ |
848 | 0 | digester.push(cfg.getComponentThreadingProfile()); |
849 | |
} |
850 | |
else |
851 | |
{ |
852 | 0 | digester.push(cfg.getDefaultThreadingProfile()); |
853 | |
} |
854 | 0 | } |
855 | |
|
856 | 0 | public void end(String s, String s1) throws Exception |
857 | |
{ |
858 | 0 | digester.pop(); |
859 | 0 | } |
860 | |
}); |
861 | |
|
862 | 0 | SetPropertiesRule threadingRule = new SetPropertiesRule(); |
863 | 0 | threadingRule.addAlias("setPoolExhaustedAction", "setPoolExhaustedActionString"); |
864 | 0 | digester.addRule(path + "/threading-profile", threadingRule); |
865 | 0 | digester.addSetNext(path + "/threading-profile", "setThreadingProfile"); |
866 | 0 | } |
867 | |
|
868 | |
protected void addPoolingProfileRules(Digester digester, String path) |
869 | |
{ |
870 | |
|
871 | 0 | digester.addRule(path + "/pooling-profile", new Rule() |
872 | |
{ |
873 | |
public void begin(String s, String s1, Attributes attributes) throws Exception |
874 | |
{ |
875 | |
|
876 | 0 | MuleConfiguration cfg = MuleManager.getConfiguration(); |
877 | 0 | digester.push(cfg.getPoolingProfile()); |
878 | 0 | } |
879 | |
|
880 | 0 | public void end(String s, String s1) throws Exception |
881 | |
{ |
882 | 0 | digester.pop(); |
883 | 0 | } |
884 | |
}); |
885 | |
|
886 | 0 | SetPropertiesRule rule = new SetPropertiesRule(); |
887 | 0 | rule.addAlias("exhaustedAction", "exhaustedActionString"); |
888 | 0 | rule.addAlias("initialisationPolicy", "initialisationPolicyString"); |
889 | 0 | digester.addRule(path + "/pooling-profile", rule); |
890 | 0 | digester.addSetNext(path + "/pooling-profile", "setPoolingProfile"); |
891 | 0 | } |
892 | |
|
893 | |
protected void addQueueProfileRules(Digester digester, String path) |
894 | |
{ |
895 | 0 | digester.addObjectCreate(path + "/queue-profile", QUEUE_PROFILE); |
896 | 0 | addSetPropertiesRule(path + "/queue-profile", digester); |
897 | 0 | digester.addSetNext(path + "/queue-profile", "setQueueProfile"); |
898 | 0 | } |
899 | |
|
900 | |
protected void addMessageRouterRules(Digester digester, String path, String type) |
901 | |
throws ConfigurationException |
902 | |
{ |
903 | |
String defaultRouter; |
904 | |
String setMethod; |
905 | 0 | if ("inbound".equals(type)) |
906 | |
{ |
907 | 0 | defaultRouter = DEFAULT_INBOUND_ROUTER_COLLECTION; |
908 | 0 | setMethod = "setInboundRouter"; |
909 | 0 | path += "/inbound-router"; |
910 | |
|
911 | 0 | addEndpointRules(digester, path, "addEndpoint"); |
912 | 0 | addGlobalReferenceEndpointRules(digester, path, "addEndpoint"); |
913 | |
} |
914 | 0 | else if ("response".equals(type)) |
915 | |
{ |
916 | 0 | defaultRouter = DEFAULT_RESPONSE_ROUTER_COLLECTION; |
917 | 0 | setMethod = "setResponseRouter"; |
918 | 0 | path += "/response-router"; |
919 | |
|
920 | |
|
921 | 0 | addEndpointRules(digester, path, "addEndpoint"); |
922 | 0 | addGlobalReferenceEndpointRules(digester, path, "addEndpoint"); |
923 | |
} |
924 | 0 | else if ("nested".equals(type)) { |
925 | 0 | defaultRouter = DEFAULT_NESTED_ROUTER_COLLECTION; |
926 | 0 | setMethod = "setNestedRouter"; |
927 | 0 | path += "/nested-router"; |
928 | |
|
929 | |
} |
930 | |
else |
931 | |
{ |
932 | 0 | defaultRouter = DEFAULT_OUTBOUND_ROUTER_COLLECTION; |
933 | 0 | setMethod = "setOutboundRouter"; |
934 | 0 | path += "/outbound-router"; |
935 | |
} |
936 | 0 | digester.addObjectCreate(path, defaultRouter, "className"); |
937 | 0 | addSetPropertiesRule(path, digester); |
938 | |
|
939 | |
|
940 | 0 | digester.addObjectCreate(path + "/catch-all-strategy", DEFAULT_CATCH_ALL_STRATEGY, "className"); |
941 | 0 | addSetPropertiesRule(path + "/catch-all-strategy", digester); |
942 | |
|
943 | |
|
944 | 0 | addEndpointRules(digester, path + "/catch-all-strategy", "setEndpoint"); |
945 | 0 | addGlobalReferenceEndpointRules(digester, path + "/catch-all-strategy", "setEndpoint"); |
946 | |
|
947 | 0 | addMulePropertiesRule(path + "/catch-all-strategy", digester); |
948 | 0 | digester.addSetNext(path + "/catch-all-strategy", "setCatchAllStrategy"); |
949 | |
|
950 | |
|
951 | 0 | addRouterRules(digester, path, type); |
952 | |
|
953 | |
|
954 | 0 | digester.addSetNext(path, setMethod); |
955 | 0 | } |
956 | |
|
957 | |
protected void addRouterRules(Digester digester, String path, final String type) |
958 | |
throws ConfigurationException |
959 | |
{ |
960 | 0 | if("nested".equals(type)) |
961 | |
{ |
962 | 0 | path += "/binding"; |
963 | 0 | digester.addObjectCreate(path, DEFAULT_NESTED_ROUTER); |
964 | |
|
965 | |
|
966 | 0 | } else if ("inbound".equals(type)) |
967 | |
{ |
968 | 0 | path += "/router"; |
969 | 0 | digester.addObjectCreate(path, INBOUND_MESSAGE_ROUTER_INTERFACE, "className"); |
970 | |
} |
971 | 0 | else if ("response".equals(type)) |
972 | |
{ |
973 | 0 | path += "/router"; |
974 | 0 | digester.addObjectCreate(path, RESPONSE_MESSAGE_ROUTER_INTERFACE, "className"); |
975 | |
} |
976 | |
else |
977 | |
{ |
978 | 0 | path += "/router"; |
979 | 0 | digester.addObjectCreate(path, OUTBOUND_MESSAGE_ROUTER_INTERFACE, "className"); |
980 | |
} |
981 | |
|
982 | 0 | addSetPropertiesRule(path, digester, new String[]{"enableCorrelation", "propertyExtractor"}, |
983 | |
new String[]{"enableCorrelationAsString", "propertyExtractorAsString"}); |
984 | 0 | addMulePropertiesRule(path, digester); |
985 | 0 | if ("outbound".equals(type)) |
986 | |
{ |
987 | 0 | addEndpointRules(digester, path, "addEndpoint"); |
988 | 0 | addReplyToRules(digester, path); |
989 | 0 | addGlobalReferenceEndpointRules(digester, path, "addEndpoint"); |
990 | 0 | addTransactionConfigRules(path, digester); |
991 | |
} |
992 | 0 | else if("nested".equals(type)) |
993 | |
{ |
994 | |
|
995 | |
|
996 | 0 | addEndpointRules(digester, path, "setEndpoint"); |
997 | 0 | addGlobalReferenceEndpointRules(digester, path, "setEndpoint"); |
998 | |
} |
999 | 0 | addFilterRules(digester, path); |
1000 | |
|
1001 | |
|
1002 | 0 | digester.addSetNext(path, "addRouter"); |
1003 | 0 | } |
1004 | |
|
1005 | |
protected void addReplyToRules(Digester digester, String path) throws ConfigurationException |
1006 | |
{ |
1007 | |
|
1008 | 0 | path += "/reply-to"; |
1009 | 0 | digester.addRule(path, new Rule() |
1010 | |
{ |
1011 | 0 | public void begin(String s, String s1, Attributes attributes) throws Exception |
1012 | |
{ |
1013 | 0 | String replyTo = attributes.getValue("address"); |
1014 | 0 | ((UMOOutboundRouter)digester.peek()).setReplyTo(replyTo); |
1015 | 0 | } |
1016 | |
}); |
1017 | 0 | } |
1018 | |
|
1019 | |
protected void addEndpointRules(Digester digester, String path, String method) |
1020 | |
throws ConfigurationException |
1021 | |
{ |
1022 | |
|
1023 | 0 | path += "/endpoint"; |
1024 | 0 | addObjectCreateOrGetFromContainer(path, DEFAULT_ENDPOINT, "className", "ref", false); |
1025 | 0 | addCommonEndpointRules(digester, path, method); |
1026 | 0 | } |
1027 | |
|
1028 | |
protected void addGlobalReferenceEndpointRules(Digester digester, String path, final String method) |
1029 | |
throws ConfigurationException |
1030 | |
{ |
1031 | |
|
1032 | 0 | path += "/global-endpoint"; |
1033 | 0 | digester.addRule(path, new Rule() |
1034 | |
{ |
1035 | |
public void begin(String s, String s1, Attributes attributes) throws Exception |
1036 | |
{ |
1037 | 0 | String name = attributes.getValue("name"); |
1038 | 0 | String address = attributes.getValue("address"); |
1039 | 0 | String trans = attributes.getValue("transformers"); |
1040 | 0 | String responseTrans = attributes.getValue("responseTransformers"); |
1041 | 0 | String createConnector = attributes.getValue("createConnector"); |
1042 | 0 | EndpointReference ref = new EndpointReference(method, name, address, trans, responseTrans, |
1043 | |
createConnector, digester.peek()); |
1044 | |
|
1045 | |
|
1046 | 0 | digester.push(ref); |
1047 | 0 | } |
1048 | |
|
1049 | 0 | public void end(String endpointName, String endpointName1) throws Exception |
1050 | |
{ |
1051 | 0 | endpointReferences.add(digester.pop()); |
1052 | 0 | } |
1053 | |
}); |
1054 | 0 | addCommonEndpointRules(digester, path, null); |
1055 | 0 | } |
1056 | |
|
1057 | |
protected void addCommonEndpointRules(Digester digester, String path, String method) |
1058 | |
throws ConfigurationException |
1059 | |
{ |
1060 | 0 | addSetPropertiesRule(path, digester, new String[]{"address", "transformers", "responseTransformers", |
1061 | |
"createConnector"}, new String[]{"endpointURI", "transformer", "responseTransformer", |
1062 | |
"createConnectorAsString"}); |
1063 | |
|
1064 | 0 | addMulePropertiesRule(path, digester, "setProperties"); |
1065 | 0 | addTransactionConfigRules(path, digester); |
1066 | |
|
1067 | 0 | addFilterRules(digester, path); |
1068 | 0 | if (method != null) |
1069 | |
{ |
1070 | 0 | digester.addSetNext(path, method); |
1071 | |
} |
1072 | |
|
1073 | |
|
1074 | 0 | digester.addObjectCreate(path + "/security-filter", ENDPOINT_SECURITY_FILTER_INTERFACE, "className"); |
1075 | |
|
1076 | 0 | addMulePropertiesRule(path + "/security-filter", digester); |
1077 | 0 | digester.addSetNext(path + "/security-filter", "setSecurityFilter"); |
1078 | 0 | } |
1079 | |
|
1080 | |
protected void addTransactionConfigRules(String path, Digester digester) |
1081 | |
{ |
1082 | 0 | digester.addObjectCreate(path + "/transaction", DEFAULT_TRANSACTION_CONFIG); |
1083 | 0 | addSetPropertiesRule(path + "/transaction", digester, new String[]{"action"}, |
1084 | |
new String[]{"actionAsString"}); |
1085 | |
|
1086 | 0 | digester.addObjectCreate(path + "/transaction/constraint", TRANSACTION_CONSTRAINT_INTERFACE, |
1087 | |
"className"); |
1088 | 0 | addSetPropertiesRule(path + "/transaction/constraint", digester); |
1089 | |
|
1090 | 0 | digester.addSetNext(path + "/transaction/constraint", "setConstraint"); |
1091 | 0 | digester.addSetNext(path + "/transaction", "setTransactionConfig"); |
1092 | 0 | } |
1093 | |
|
1094 | |
protected void addExceptionStrategyRules(Digester digester, String path) throws ConfigurationException |
1095 | |
{ |
1096 | 0 | path += "/exception-strategy"; |
1097 | 0 | digester.addObjectCreate(path, EXCEPTION_STRATEGY_INTERFACE, "className"); |
1098 | 0 | addMulePropertiesRule(path, digester); |
1099 | |
|
1100 | |
|
1101 | 0 | addEndpointRules(digester, path, "addEndpoint"); |
1102 | 0 | addGlobalReferenceEndpointRules(digester, path, "addEndpoint"); |
1103 | 0 | digester.addSetNext(path, "setExceptionListener"); |
1104 | 0 | } |
1105 | |
|
1106 | |
protected void addSetPropertiesRule(String path, Digester digester, String[] s1, String[] s2) |
1107 | |
{ |
1108 | 0 | digester.addRule(path, new ExtendedMuleSetPropertiesRule(s1, s2)); |
1109 | 0 | } |
1110 | |
|
1111 | |
protected void addSetPropertiesRule(String path, Digester digester) |
1112 | |
{ |
1113 | 0 | digester.addRule(path, new ExtendedMuleSetPropertiesRule()); |
1114 | 0 | } |
1115 | |
|
1116 | |
private void addTransformerReference(String propName, String transName, Object object) |
1117 | |
{ |
1118 | 0 | transformerReferences.add(new TransformerReference(propName, transName, object)); |
1119 | 0 | } |
1120 | |
|
1121 | |
private void addEndpointReference(String propName, String endpointName, Object object) |
1122 | |
{ |
1123 | 0 | endpointReferences.add(new EndpointReference(propName, endpointName, null, null, null, null, object)); |
1124 | 0 | } |
1125 | |
|
1126 | |
|
1127 | |
|
1128 | |
|
1129 | |
|
1130 | |
|
1131 | |
|
1132 | |
|
1133 | |
public class ExtendedMuleSetPropertiesRule extends MuleSetPropertiesRule |
1134 | |
{ |
1135 | |
public ExtendedMuleSetPropertiesRule() |
1136 | 0 | { |
1137 | 0 | super(); |
1138 | 0 | } |
1139 | |
|
1140 | |
public ExtendedMuleSetPropertiesRule(PlaceholderProcessor processor) |
1141 | 0 | { |
1142 | 0 | super(processor); |
1143 | 0 | } |
1144 | |
|
1145 | |
public ExtendedMuleSetPropertiesRule(String[] strings, String[] strings1) |
1146 | 0 | { |
1147 | 0 | super(strings, strings1); |
1148 | 0 | } |
1149 | |
|
1150 | |
public ExtendedMuleSetPropertiesRule(String[] strings, |
1151 | |
String[] strings1, |
1152 | |
PlaceholderProcessor processor) |
1153 | 0 | { |
1154 | 0 | super(strings, strings1, processor); |
1155 | 0 | } |
1156 | |
|
1157 | |
public void begin(String s1, String s2, Attributes attributes) throws Exception |
1158 | |
{ |
1159 | 0 | attributes = processor.processAttributes(attributes, s2); |
1160 | |
|
1161 | |
|
1162 | 0 | String transformerNames = attributes.getValue("transformer"); |
1163 | 0 | if (transformerNames != null) |
1164 | |
{ |
1165 | 0 | addTransformerReference("transformer", transformerNames, digester.peek()); |
1166 | |
} |
1167 | 0 | transformerNames = attributes.getValue("transformers"); |
1168 | 0 | if (transformerNames != null) |
1169 | |
{ |
1170 | 0 | addTransformerReference("transformer", transformerNames, digester.peek()); |
1171 | |
} |
1172 | |
|
1173 | 0 | transformerNames = attributes.getValue("responseTransformers"); |
1174 | 0 | if (transformerNames != null) |
1175 | |
{ |
1176 | 0 | addTransformerReference("responseTransformer", transformerNames, digester.peek()); |
1177 | |
} |
1178 | |
|
1179 | |
|
1180 | |
|
1181 | |
|
1182 | |
|
1183 | |
|
1184 | |
|
1185 | 0 | transformerNames = attributes.getValue("inboundTransformer"); |
1186 | 0 | if (transformerNames != null) |
1187 | |
{ |
1188 | 0 | addTransformerReference("inboundTransformer", transformerNames, digester.peek()); |
1189 | |
} |
1190 | |
|
1191 | 0 | transformerNames = attributes.getValue("outboundTransformer"); |
1192 | 0 | if (transformerNames != null) |
1193 | |
{ |
1194 | 0 | addTransformerReference("outboundTransformer", transformerNames, digester.peek()); |
1195 | |
} |
1196 | |
|
1197 | 0 | transformerNames = attributes.getValue("responseTransformer"); |
1198 | 0 | if (transformerNames != null) |
1199 | |
{ |
1200 | 0 | addTransformerReference("responseTransformer", transformerNames, digester.peek()); |
1201 | |
} |
1202 | |
|
1203 | |
|
1204 | |
|
1205 | |
|
1206 | 0 | String endpoint = attributes.getValue("inboundEndpoint"); |
1207 | 0 | if (endpoint != null) |
1208 | |
{ |
1209 | 0 | Object o = manager.getEndpoints().get(endpoint); |
1210 | 0 | if (o != null) |
1211 | |
{ |
1212 | 0 | addEndpointReference("setInboundEndpoint", endpoint, digester.peek()); |
1213 | |
} |
1214 | |
} |
1215 | |
|
1216 | 0 | endpoint = attributes.getValue("outboundEndpoint"); |
1217 | 0 | if (endpoint != null) |
1218 | |
{ |
1219 | 0 | Object o = manager.getEndpoints().get(endpoint); |
1220 | 0 | if (o != null) |
1221 | |
{ |
1222 | 0 | addEndpointReference("setOutboundEndpoint", endpoint, digester.peek()); |
1223 | |
} |
1224 | |
} |
1225 | 0 | super.begin(attributes); |
1226 | 0 | } |
1227 | |
} |
1228 | |
|
1229 | |
protected void addObjectCreateOrGetFromContainer(final String path, |
1230 | |
String defaultImpl, |
1231 | |
final String classAttrib, |
1232 | |
final String refAttrib, |
1233 | |
final boolean classRefRequired) |
1234 | |
{ |
1235 | 0 | digester.addRule(path, new ObjectGetOrCreateRule(defaultImpl, classAttrib, refAttrib, classAttrib, |
1236 | |
classRefRequired, "getContainerContext")); |
1237 | 0 | } |
1238 | |
|
1239 | |
protected void addObjectCreateOrGetFromContainer(final String path, |
1240 | |
String defaultImpl, |
1241 | |
final String classAttrib, |
1242 | |
final String refAttrib, |
1243 | |
final String containerAttrib, |
1244 | |
final boolean classRefRequired) |
1245 | |
{ |
1246 | 0 | digester.addRule(path, new ObjectGetOrCreateRule(defaultImpl, classAttrib, refAttrib, |
1247 | |
containerAttrib, classAttrib, classRefRequired, "getContainerContext")); |
1248 | 0 | } |
1249 | |
} |