1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.processor; |
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.processor.InterceptingMessageProcessor; |
13 | |
import org.mule.api.processor.MessageProcessor; |
14 | |
import org.mule.api.routing.filter.FilterUnacceptedException; |
15 | |
import org.mule.config.i18n.CoreMessages; |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | 0 | public abstract class AbstractFilteringMessageProcessor extends AbstractInterceptingMessageProcessor |
23 | |
{ |
24 | |
|
25 | |
|
26 | |
|
27 | 0 | protected boolean throwOnUnaccepted = false; |
28 | |
protected boolean onUnacceptedFlowConstruct; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
protected MessageProcessor unacceptedMessageProcessor; |
35 | |
|
36 | |
public MuleEvent process(MuleEvent event) throws MuleException |
37 | |
{ |
38 | 0 | if (accept(event)) |
39 | |
{ |
40 | 0 | return processNext(event); |
41 | |
} |
42 | |
else |
43 | |
{ |
44 | 0 | return handleUnaccepted(event); |
45 | |
} |
46 | |
} |
47 | |
|
48 | |
protected abstract boolean accept(MuleEvent event); |
49 | |
|
50 | |
protected MuleEvent handleUnaccepted(MuleEvent event) throws MuleException |
51 | |
{ |
52 | 0 | if (unacceptedMessageProcessor != null) |
53 | |
{ |
54 | 0 | return unacceptedMessageProcessor.process(event); |
55 | |
} |
56 | 0 | else if (throwOnUnaccepted) |
57 | |
{ |
58 | 0 | throw filterUnacceptedException(event); |
59 | |
} |
60 | |
else |
61 | |
{ |
62 | 0 | return null; |
63 | |
} |
64 | |
} |
65 | |
|
66 | |
protected MuleException filterUnacceptedException(MuleEvent event) |
67 | |
{ |
68 | 0 | return new FilterUnacceptedException(CoreMessages.messageRejectedByFilter(), event); |
69 | |
} |
70 | |
|
71 | |
public MessageProcessor getUnacceptedMessageProcessor() |
72 | |
{ |
73 | 0 | return unacceptedMessageProcessor; |
74 | |
} |
75 | |
|
76 | |
public void setUnacceptedMessageProcessor(MessageProcessor unacceptedMessageProcessor) |
77 | |
{ |
78 | 0 | this.unacceptedMessageProcessor = unacceptedMessageProcessor; |
79 | 0 | if (unacceptedMessageProcessor instanceof FlowConstruct) |
80 | |
{ |
81 | 0 | onUnacceptedFlowConstruct = true; |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
public boolean isThrowOnUnaccepted() |
86 | |
{ |
87 | 0 | return throwOnUnaccepted; |
88 | |
} |
89 | |
|
90 | |
public void setThrowOnUnaccepted(boolean throwOnUnaccepted) |
91 | |
{ |
92 | 0 | this.throwOnUnaccepted = throwOnUnaccepted; |
93 | 0 | } |
94 | |
} |