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 public abstract class AbstractFilteringMessageProcessor extends AbstractInterceptingMessageProcessor
23 {
24
25
26
27 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 if (accept(event))
39 {
40 return processNext(event);
41 }
42 else
43 {
44 return handleUnaccepted(event);
45 }
46 }
47
48 protected abstract boolean accept(MuleEvent event);
49
50 protected MuleEvent handleUnaccepted(MuleEvent event) throws MuleException
51 {
52 if (unacceptedMessageProcessor != null)
53 {
54 return unacceptedMessageProcessor.process(event);
55 }
56 else if (throwOnUnaccepted)
57 {
58 throw filterUnacceptedException(event);
59 }
60 else
61 {
62 return null;
63 }
64 }
65
66 protected MuleException filterUnacceptedException(MuleEvent event)
67 {
68 return new FilterUnacceptedException(CoreMessages.messageRejectedByFilter(), event);
69 }
70
71 public MessageProcessor getUnacceptedMessageProcessor()
72 {
73 return unacceptedMessageProcessor;
74 }
75
76 public void setUnacceptedMessageProcessor(MessageProcessor unacceptedMessageProcessor)
77 {
78 this.unacceptedMessageProcessor = unacceptedMessageProcessor;
79 if (unacceptedMessageProcessor instanceof FlowConstruct)
80 {
81 onUnacceptedFlowConstruct = true;
82 }
83 }
84
85 public boolean isThrowOnUnaccepted()
86 {
87 return throwOnUnaccepted;
88 }
89
90 public void setThrowOnUnaccepted(boolean throwOnUnaccepted)
91 {
92 this.throwOnUnaccepted = throwOnUnaccepted;
93 }
94 }