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