1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.model.language; |
18 |
|
|
19 |
|
import javax.xml.bind.annotation.XmlAccessType; |
20 |
|
import javax.xml.bind.annotation.XmlAccessorType; |
21 |
|
import javax.xml.bind.annotation.XmlAttribute; |
22 |
|
import javax.xml.bind.annotation.XmlID; |
23 |
|
import javax.xml.bind.annotation.XmlTransient; |
24 |
|
import javax.xml.bind.annotation.XmlType; |
25 |
|
import javax.xml.bind.annotation.XmlValue; |
26 |
|
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; |
27 |
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
28 |
|
|
29 |
|
import org.apache.camel.CamelContext; |
30 |
|
import org.apache.camel.Exchange; |
31 |
|
import org.apache.camel.Expression; |
32 |
|
import org.apache.camel.Predicate; |
33 |
|
import org.apache.camel.impl.RouteContext; |
34 |
|
import org.apache.camel.spi.Language; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@XmlType(name = "expressionType") |
42 |
|
@XmlAccessorType(XmlAccessType.FIELD) |
43 |
|
public class ExpressionType { |
44 |
|
@XmlAttribute |
45 |
|
@XmlJavaTypeAdapter(CollapsedStringAdapter.class) |
46 |
|
@XmlID |
47 |
|
private String id; |
48 |
|
@XmlValue |
49 |
|
private String expression; |
50 |
|
@XmlTransient |
51 |
|
private Predicate predicate; |
52 |
|
@XmlTransient |
53 |
|
private Expression expressionValue; |
54 |
|
|
55 |
27 |
public ExpressionType() { |
56 |
27 |
} |
57 |
|
|
58 |
3 |
public ExpressionType(String expression) { |
59 |
3 |
this.expression = expression; |
60 |
3 |
} |
61 |
|
|
62 |
93 |
public ExpressionType(Predicate predicate) { |
63 |
93 |
this.predicate = predicate; |
64 |
93 |
} |
65 |
|
|
66 |
24 |
public ExpressionType(Expression expression) { |
67 |
24 |
this.expressionValue = expression; |
68 |
24 |
} |
69 |
|
|
70 |
|
@Override |
71 |
|
public String toString() { |
72 |
129 |
return getLanguage() + "Expression[" + getExpression() + "]"; |
73 |
|
} |
74 |
|
|
75 |
|
public String getLanguage() { |
76 |
0 |
return ""; |
77 |
|
} |
78 |
|
|
79 |
|
public Predicate<Exchange> createPredicate(RouteContext route) { |
80 |
93 |
if (predicate == null) { |
81 |
0 |
CamelContext camelContext = route.getCamelContext(); |
82 |
0 |
Language language = camelContext.resolveLanguage(getLanguage()); |
83 |
0 |
predicate = language.createPredicate(getExpression()); |
84 |
|
} |
85 |
93 |
return predicate; |
86 |
|
} |
87 |
|
|
88 |
|
public Expression createExpression(RouteContext routeContext) { |
89 |
24 |
if (expressionValue == null) { |
90 |
0 |
CamelContext camelContext = routeContext.getCamelContext(); |
91 |
0 |
Language language = camelContext.resolveLanguage(getLanguage()); |
92 |
0 |
expressionValue = language.createExpression(getExpression()); |
93 |
|
} |
94 |
24 |
return expressionValue; |
95 |
|
} |
96 |
|
|
97 |
|
public String getExpression() { |
98 |
147 |
return expression; |
99 |
|
} |
100 |
|
|
101 |
|
public void setExpression(String expression) { |
102 |
3 |
this.expression = expression; |
103 |
3 |
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
public String getId() { |
112 |
0 |
return id; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
public void setId(String value) { |
122 |
0 |
this.id = value; |
123 |
0 |
} |
124 |
|
} |