View Javadoc

1   /*
2    * $Id: OutboundEndpointFactoryBean.java 11079 2008-02-27 15:52:01Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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.builder.InterceptingChainMessageProcessorBuilder;
18  
19  import java.util.List;
20  
21  import org.springframework.beans.factory.FactoryBean;
22  
23  public class TransactionalMessageProcessorsFactoryBean implements FactoryBean
24  {
25  
26      protected List messageProcessors;
27      protected TransactionConfig transactionConfig;
28  
29      public Class getObjectType()
30      {
31          return MessageProcessor.class;
32      }
33  
34      public void setMessageProcessors(List messageProcessors)
35      {
36          this.messageProcessors = messageProcessors;
37      }
38  
39      public Object getObject() throws Exception
40      {
41          InterceptingChainMessageProcessorBuilder builder = new InterceptingChainMessageProcessorBuilder();
42          TransactionalInterceptingMessageProcessor txProcessor = 
43              new TransactionalInterceptingMessageProcessor(transactionConfig);
44          builder.chain(txProcessor);
45          for (Object processor : messageProcessors)
46          {
47              if (processor instanceof MessageProcessor)
48              {
49                  builder.chain((MessageProcessor) processor);
50              }
51              else if (processor instanceof MessageProcessorBuilder)
52              {
53                  builder.chain((MessageProcessorBuilder) processor);
54              }
55              else
56              {
57                  throw new IllegalArgumentException(
58                      "MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured");
59              }
60          }
61          return builder.build();
62      }
63  
64      public boolean isSingleton()
65      {
66          return false;
67      }
68  
69      public void setTransactionConfig(TransactionConfig transactionConfig)
70      {
71          this.transactionConfig = transactionConfig;
72      }
73  }