1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.core.adapter;
17
18 import org.apache.camel.Exchange;
19 import org.apache.camel.Expression;
20 import org.openehealth.ipf.commons.core.modules.api.Predicate;
21
22
23
24
25
26
27 public class PredicateAdapter extends AdapterSupport implements org.apache.camel.Predicate {
28
29 private final Predicate predicate;
30
31
32
33
34
35
36
37
38 public PredicateAdapter(Predicate predicate) {
39 this.predicate = predicate;
40 }
41
42 @Override
43 public PredicateAdapter input(Expression inputExpression) {
44 return (PredicateAdapter)super.input(inputExpression);
45 }
46
47 @Override
48 public PredicateAdapter params(Expression paramsExpression) {
49 return (PredicateAdapter)super.params(paramsExpression);
50 }
51
52 @Override
53 public PredicateAdapter staticParams(Object... params) {
54 return (PredicateAdapter)super.staticParams(params);
55 }
56
57
58
59
60
61
62
63
64
65
66
67 @Override
68 public boolean matches(Exchange exchange) {
69 Object input = adaptInput(exchange);
70 Object params = adaptParams(exchange);
71 if (params == null) {
72 return predicate.matches(input, (Object[])null);
73 } else if (params.getClass().isArray()) {
74 return predicate.matches(input, (Object[])params);
75 } else {
76 return predicate.matches(input, params);
77 }
78 }
79
80
81
82
83 public void assertMatches(String text, Exchange exchange) throws AssertionError {
84 if (!matches(exchange)) {
85 throw new AssertionError(text);
86 }
87
88 }
89
90 }