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 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
27 | |
|
28 | |
private String pattern; |
29 | |
|
30 | |
public SxcFilter() |
31 | |
{ |
32 | 0 | super(); |
33 | 0 | } |
34 | |
|
35 | |
public SxcFilter(String pattern) |
36 | 0 | { |
37 | 0 | this.pattern = pattern; |
38 | 0 | } |
39 | |
|
40 | |
public boolean accept(MuleMessage msg) |
41 | |
{ |
42 | 0 | Object accept = msg.getInvocationProperty(toString()); |
43 | |
|
44 | 0 | if (accept == null && SxcFilteringOutboundRouter.getCurrentMessage() == null) |
45 | |
{ |
46 | 0 | return false; |
47 | |
} |
48 | 0 | else if (accept == null) |
49 | |
{ |
50 | 0 | throw new UndefinedMatchException(); |
51 | |
} |
52 | |
|
53 | 0 | return (Boolean) accept; |
54 | |
} |
55 | |
|
56 | |
|
57 | |
public String getPattern() |
58 | |
{ |
59 | 0 | return pattern; |
60 | |
} |
61 | |
|
62 | |
|
63 | |
public void setPattern(String pattern) |
64 | |
{ |
65 | 0 | this.pattern = pattern; |
66 | 0 | } |
67 | |
|
68 | |
public void addEventHandler(SxcFilteringOutboundRouter router, XPathBuilder builder) |
69 | |
{ |
70 | 0 | builder.listen(pattern, new FilterEventHandler(router, this)); |
71 | 0 | } |
72 | |
|
73 | |
public boolean equals(Object obj) |
74 | |
{ |
75 | 0 | if (this == obj) return true; |
76 | 0 | if (obj == null || getClass() != obj.getClass()) return false; |
77 | |
|
78 | 0 | final SxcFilter other = (SxcFilter) obj; |
79 | 0 | return equal(pattern, other.pattern); |
80 | |
} |
81 | |
|
82 | |
public int hashCode() |
83 | |
{ |
84 | 0 | return hash(new Object[]{this.getClass(), pattern}); |
85 | |
} |
86 | |
} |
87 | |
|
88 | |
|