View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.factories;
8   
9   import java.util.Collection;
10  
11  import org.mule.api.processor.MessageProcessor;
12  import org.mule.routing.AbstractSelectiveRouter;
13  import org.mule.routing.MessageProcessorFilterPair;
14  import org.springframework.beans.factory.FactoryBean;
15  
16  public abstract class AbstractSelectiveRouterFactoryBean implements FactoryBean
17  {
18      private MessageProcessor defaultProcessor;
19      private Collection<MessageProcessorFilterPair> conditionalMessageProcessors;
20  
21      public AbstractSelectiveRouterFactoryBean()
22      {
23          super();
24      }
25  
26      public void setDefaultRoute(MessageProcessorFilterPair conditionalProcessor)
27      {
28          defaultProcessor = conditionalProcessor.getMessageProcessor();
29      }
30  
31      public void setRoutes(Collection<MessageProcessorFilterPair> conditionalMessageProcessors)
32      {
33          this.conditionalMessageProcessors = conditionalMessageProcessors;
34      }
35  
36      public Object getObject() throws Exception
37      {
38          final AbstractSelectiveRouter router = newAbstractSelectiveRouter();
39          router.setDefaultRoute(defaultProcessor);
40  
41          for (final MessageProcessorFilterPair mpfp : conditionalMessageProcessors)
42          {
43              router.addRoute(mpfp.getMessageProcessor(), mpfp.getFilter());
44          }
45  
46          return router;
47      }
48  
49      protected abstract AbstractSelectiveRouter newAbstractSelectiveRouter();
50  
51      public boolean isSingleton()
52      {
53          return true;
54      }
55  
56  }