1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.factories; |
12 | |
|
13 | |
import org.mule.api.processor.MessageProcessor; |
14 | |
import org.mule.api.processor.MessageProcessorBuilder; |
15 | |
import org.mule.api.transaction.TransactionConfig; |
16 | |
import org.mule.processor.TransactionalInterceptingMessageProcessor; |
17 | |
import org.mule.processor.chain.DefaultMessageProcessorChainBuilder; |
18 | |
|
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.springframework.beans.factory.FactoryBean; |
22 | |
|
23 | 0 | public class TransactionalMessageProcessorsFactoryBean implements FactoryBean |
24 | |
{ |
25 | |
|
26 | |
protected List messageProcessors; |
27 | |
protected TransactionConfig transactionConfig; |
28 | |
|
29 | |
public Class getObjectType() |
30 | |
{ |
31 | 0 | return MessageProcessor.class; |
32 | |
} |
33 | |
|
34 | |
public void setMessageProcessors(List messageProcessors) |
35 | |
{ |
36 | 0 | this.messageProcessors = messageProcessors; |
37 | 0 | } |
38 | |
|
39 | |
public Object getObject() throws Exception |
40 | |
{ |
41 | 0 | DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder(); |
42 | 0 | TransactionalInterceptingMessageProcessor txProcessor = |
43 | |
new TransactionalInterceptingMessageProcessor(transactionConfig); |
44 | 0 | builder.chain(txProcessor); |
45 | 0 | for (Object processor : messageProcessors) |
46 | |
{ |
47 | 0 | if (processor instanceof MessageProcessor) |
48 | |
{ |
49 | 0 | builder.chain((MessageProcessor) processor); |
50 | |
} |
51 | 0 | else if (processor instanceof MessageProcessorBuilder) |
52 | |
{ |
53 | 0 | builder.chain((MessageProcessorBuilder) processor); |
54 | |
} |
55 | |
else |
56 | |
{ |
57 | 0 | throw new IllegalArgumentException( |
58 | |
"MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured"); |
59 | |
} |
60 | |
} |
61 | 0 | return builder.build(); |
62 | |
} |
63 | |
|
64 | |
public boolean isSingleton() |
65 | |
{ |
66 | 0 | return false; |
67 | |
} |
68 | |
|
69 | |
public void setTransactionConfig(TransactionConfig transactionConfig) |
70 | |
{ |
71 | 0 | this.transactionConfig = transactionConfig; |
72 | 0 | } |
73 | |
} |