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