1
2
3
4
5
6
7
8
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.construct.FlowConstruct;
16 import org.mule.api.processor.MessageProcessor;
17
18 import org.springframework.beans.BeansException;
19 import org.springframework.beans.factory.FactoryBean;
20 import org.springframework.context.ApplicationContext;
21 import org.springframework.context.ApplicationContextAware;
22
23 public class FlowRefFactoryBean implements FactoryBean<MessageProcessor>, ApplicationContextAware
24 {
25 private String refName;
26 private ApplicationContext applicationContext;
27
28 public void setName(String name)
29 {
30 this.refName = name;
31 }
32
33 @Override
34 public MessageProcessor getObject() throws Exception
35 {
36 final MessageProcessor processor = ((MessageProcessor) applicationContext.getBean(refName));
37 if (processor instanceof FlowConstruct)
38 {
39
40 return new MessageProcessor()
41 {
42 public MuleEvent process(MuleEvent event) throws MuleException
43 {
44 return processor.process(event);
45 }
46 };
47 }
48 else
49 {
50 return processor;
51 }
52 }
53
54 @Override
55 public boolean isSingleton()
56 {
57 return false;
58 }
59
60 @Override
61 public Class<?> getObjectType()
62 {
63 return MessageProcessor.class;
64 }
65
66 @Override
67 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
68 {
69 this.applicationContext = applicationContext;
70 }
71 }