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