View Javadoc

1   /*
2    * $Id: FlowRefFactoryBean.java 20320 2010-11-24 15:03:31Z dfeist $
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.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.processor.MessageProcessor;
16  
17  import org.springframework.beans.BeansException;
18  import org.springframework.beans.factory.FactoryBean;
19  import org.springframework.context.ApplicationContext;
20  import org.springframework.context.ApplicationContextAware;
21  
22  public class FlowRefFactoryBean implements FactoryBean<MessageProcessor>, ApplicationContextAware
23  {
24  
25      private String refName;;
26      private ApplicationContext applicationContext;
27  
28      public void setName(String name)
29      {
30          this.refName = name;
31      }
32  
33      public MessageProcessor getObject() throws Exception
34      {
35          // Create new message processor to decouple lifecycle
36          return new MessageProcessor()
37          {
38              public MuleEvent process(MuleEvent event) throws MuleException
39              {
40                  return ((MessageProcessor) applicationContext.getBean(refName)).process(event);
41              }
42          };
43      }
44  
45      public boolean isSingleton()
46      {
47          return false;
48      }
49  
50      public Class<?> getObjectType()
51      {
52          return MessageProcessor.class;
53      }
54  
55      public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
56      {
57          this.applicationContext = applicationContext;
58      }
59  }