1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.sxc;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.api.routing.filter.Filter;
15
16 import com.envoisolutions.sxc.xpath.XPathBuilder;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21 import static org.mule.util.ClassUtils.equal;
22 import static org.mule.util.ClassUtils.hash;
23
24 public class SxcFilter implements Filter
25 {
26 protected transient Log logger = LogFactory.getLog(getClass());
27
28 private String pattern;
29
30 public SxcFilter()
31 {
32 super();
33 }
34
35 public SxcFilter(String pattern)
36 {
37 this.pattern = pattern;
38 }
39
40 public boolean accept(MuleMessage msg)
41 {
42 Object accept = msg.getInvocationProperty(toString());
43
44 if (accept == null && SxcFilteringOutboundRouter.getCurrentMessage() == null)
45 {
46 return false;
47 }
48 else if (accept == null)
49 {
50 throw new UndefinedMatchException();
51 }
52
53 return (Boolean) accept;
54 }
55
56
57 public String getPattern()
58 {
59 return pattern;
60 }
61
62
63 public void setPattern(String pattern)
64 {
65 this.pattern = pattern;
66 }
67
68 public void addEventHandler(SxcFilteringOutboundRouter router, XPathBuilder builder)
69 {
70 builder.listen(pattern, new FilterEventHandler(router, this));
71 }
72
73 public boolean equals(Object obj)
74 {
75 if (this == obj) return true;
76 if (obj == null || getClass() != obj.getClass()) return false;
77
78 final SxcFilter other = (SxcFilter) obj;
79 return equal(pattern, other.pattern);
80 }
81
82 public int hashCode()
83 {
84 return hash(new Object[]{this.getClass(), pattern});
85 }
86 }
87
88