View Javadoc

1   /*
2    * $Id$
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 java.util.Collection;
14  
15  import org.mule.api.processor.MessageProcessor;
16  import org.mule.routing.AbstractSelectiveRouter;
17  import org.mule.routing.MessageProcessorFilterPair;
18  import org.springframework.beans.factory.FactoryBean;
19  
20  public abstract class AbstractSelectiveRouterFactoryBean implements FactoryBean
21  {
22      private MessageProcessor defaultProcessor;
23      private Collection<MessageProcessorFilterPair> conditionalMessageProcessors;
24  
25      public AbstractSelectiveRouterFactoryBean()
26      {
27          super();
28      }
29  
30      public void setDefaultRoute(MessageProcessorFilterPair conditionalProcessor)
31      {
32          defaultProcessor = conditionalProcessor.getMessageProcessor();
33      }
34  
35      public void setRoutes(Collection<MessageProcessorFilterPair> conditionalMessageProcessors)
36      {
37          this.conditionalMessageProcessors = conditionalMessageProcessors;
38      }
39  
40      public Object getObject() throws Exception
41      {
42          final AbstractSelectiveRouter router = newAbstractSelectiveRouter();
43          router.setDefaultRoute(defaultProcessor);
44  
45          for (final MessageProcessorFilterPair mpfp : conditionalMessageProcessors)
46          {
47              router.addRoute(mpfp.getMessageProcessor(), mpfp.getFilter());
48          }
49  
50          return router;
51      }
52  
53      protected abstract AbstractSelectiveRouter newAbstractSelectiveRouter();
54  
55      public boolean isSingleton()
56      {
57          return true;
58      }
59  
60  }