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