1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.cxf.config; |
8 | |
|
9 | |
import org.mule.api.MuleEvent; |
10 | |
import org.mule.api.MuleException; |
11 | |
import org.mule.api.construct.FlowConstruct; |
12 | |
import org.mule.api.construct.FlowConstructAware; |
13 | |
import org.mule.api.lifecycle.Disposable; |
14 | |
import org.mule.api.lifecycle.Initialisable; |
15 | |
import org.mule.api.lifecycle.InitialisationException; |
16 | |
import org.mule.api.lifecycle.Lifecycle; |
17 | |
import org.mule.api.lifecycle.Startable; |
18 | |
import org.mule.api.lifecycle.Stoppable; |
19 | |
import org.mule.api.processor.InterceptingMessageProcessor; |
20 | |
import org.mule.api.processor.MessageProcessor; |
21 | |
import org.mule.api.processor.MessageProcessorBuilder; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class FlowConfiguringMessageProcessor implements FlowConstructAware, Lifecycle, InterceptingMessageProcessor |
28 | |
{ |
29 | |
|
30 | |
private MessageProcessorBuilder builder; |
31 | |
private MessageProcessor messageProcessor; |
32 | |
private MessageProcessor listener; |
33 | |
|
34 | |
public FlowConfiguringMessageProcessor(MessageProcessorBuilder builder) |
35 | 0 | { |
36 | 0 | this.builder = builder; |
37 | 0 | } |
38 | |
|
39 | |
public void setListener(MessageProcessor listener) |
40 | |
{ |
41 | 0 | this.listener = listener; |
42 | 0 | } |
43 | |
|
44 | |
public MuleEvent process(MuleEvent event) throws MuleException |
45 | |
{ |
46 | 0 | return messageProcessor.process(event); |
47 | |
} |
48 | |
|
49 | |
public void start() throws MuleException |
50 | |
{ |
51 | 0 | if (messageProcessor instanceof Startable) |
52 | |
{ |
53 | 0 | ((Startable) messageProcessor).start(); |
54 | |
} |
55 | 0 | } |
56 | |
|
57 | |
public void setFlowConstruct(FlowConstruct flowConstruct) |
58 | |
{ |
59 | 0 | if (builder instanceof FlowConstructAware) |
60 | |
{ |
61 | 0 | ((FlowConstructAware) builder).setFlowConstruct(flowConstruct); |
62 | |
} |
63 | 0 | } |
64 | |
|
65 | |
public void dispose() |
66 | |
{ |
67 | 0 | if (messageProcessor instanceof Disposable) |
68 | |
{ |
69 | 0 | ((Disposable) messageProcessor).dispose(); |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
public void stop() throws MuleException |
74 | |
{ |
75 | 0 | if (messageProcessor instanceof Stoppable) |
76 | |
{ |
77 | 0 | ((Stoppable) messageProcessor).stop(); |
78 | |
} |
79 | 0 | } |
80 | |
|
81 | |
public void initialise() throws InitialisationException |
82 | |
{ |
83 | 0 | if (builder instanceof Initialisable) |
84 | |
{ |
85 | 0 | ((Initialisable) builder).initialise(); |
86 | |
} |
87 | |
|
88 | |
try |
89 | |
{ |
90 | 0 | messageProcessor = builder.build(); |
91 | |
} |
92 | 0 | catch (Exception e) |
93 | |
{ |
94 | 0 | throw new InitialisationException(e, this); |
95 | 0 | } |
96 | |
|
97 | 0 | if (messageProcessor instanceof Initialisable) |
98 | |
{ |
99 | 0 | ((Initialisable) messageProcessor).initialise(); |
100 | |
} |
101 | |
|
102 | 0 | if (messageProcessor instanceof InterceptingMessageProcessor && listener != null) |
103 | |
{ |
104 | 0 | ((InterceptingMessageProcessor) messageProcessor).setListener(listener); |
105 | |
} |
106 | 0 | } |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public MessageProcessor getWrappedMessageProcessor() |
112 | |
{ |
113 | 0 | return messageProcessor; |
114 | |
} |
115 | |
|
116 | |
public MessageProcessorBuilder getMessageProcessorBuilder() |
117 | |
{ |
118 | 0 | return builder; |
119 | |
} |
120 | |
|
121 | |
} |