1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.model; |
18 |
|
|
19 |
|
import java.util.ArrayList; |
20 |
|
import java.util.Collection; |
21 |
|
import java.util.List; |
22 |
|
|
23 |
|
import javax.xml.bind.annotation.XmlElement; |
24 |
|
import javax.xml.bind.annotation.XmlElementRef; |
25 |
|
import javax.xml.bind.annotation.XmlRootElement; |
26 |
|
import javax.xml.bind.annotation.XmlTransient; |
27 |
|
|
28 |
|
import org.apache.camel.Endpoint; |
29 |
|
import org.apache.camel.Exchange; |
30 |
|
import org.apache.camel.Expression; |
31 |
|
import org.apache.camel.Processor; |
32 |
|
import org.apache.camel.Route; |
33 |
|
import org.apache.camel.impl.RouteContext; |
34 |
|
import org.apache.camel.model.language.ExpressionType; |
35 |
|
import org.apache.camel.processor.Resequencer; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@XmlRootElement(name = "resequencer") |
41 |
|
public class ResequencerType extends ProcessorType { |
42 |
|
@XmlElementRef |
43 |
3 |
private List<InterceptorType> interceptors = new ArrayList<InterceptorType>(); |
44 |
|
@XmlElementRef |
45 |
3 |
private List<ExpressionType> expressions = new ArrayList<ExpressionType>(); |
46 |
|
@XmlElementRef |
47 |
3 |
private List<ProcessorType> outputs = new ArrayList<ProcessorType>(); |
48 |
|
@XmlTransient |
49 |
|
private List<Expression> expressionList; |
50 |
|
|
51 |
0 |
public ResequencerType() { |
52 |
0 |
} |
53 |
|
|
54 |
3 |
public ResequencerType(List<Expression> expressions) { |
55 |
3 |
this.expressionList = expressions; |
56 |
3 |
} |
57 |
|
|
58 |
|
@Override |
59 |
|
public String toString() { |
60 |
0 |
return "Resequencer[ " + getExpressions() + " -> " + getOutputs() + "]"; |
61 |
|
} |
62 |
|
|
63 |
|
public List<ExpressionType> getExpressions() { |
64 |
0 |
return expressions; |
65 |
|
} |
66 |
|
|
67 |
|
public List<InterceptorType> getInterceptors() { |
68 |
3 |
return interceptors; |
69 |
|
} |
70 |
|
|
71 |
|
public void setInterceptors(List<InterceptorType> interceptors) { |
72 |
0 |
this.interceptors = interceptors; |
73 |
0 |
} |
74 |
|
|
75 |
|
public List<ProcessorType> getOutputs() { |
76 |
6 |
return outputs; |
77 |
|
} |
78 |
|
|
79 |
|
public void setOutputs(List<ProcessorType> outputs) { |
80 |
0 |
this.outputs = outputs; |
81 |
0 |
} |
82 |
|
|
83 |
|
public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws Exception { |
84 |
3 |
Endpoint from = routeContext.getEndpoint(); |
85 |
3 |
final Processor processor = routeContext.createProcessor(this); |
86 |
3 |
final Resequencer resequencer = new Resequencer(from, processor, resolveExpressionList(routeContext)); |
87 |
|
|
88 |
3 |
Route route = new Route<Exchange>(from, resequencer) { |
89 |
|
@Override |
90 |
3 |
public String toString() { |
91 |
3 |
return "ResequencerRoute[" + getEndpoint() + " -> " + processor + "]"; |
92 |
|
} |
93 |
|
}; |
94 |
|
|
95 |
3 |
routes.add(route); |
96 |
3 |
} |
97 |
|
|
98 |
|
private List<Expression> resolveExpressionList(RouteContext routeContext) { |
99 |
3 |
if (expressionList == null) { |
100 |
0 |
expressionList = new ArrayList<Expression>(); |
101 |
0 |
for (ExpressionType expression : expressions) { |
102 |
0 |
expressionList.add(expression.createExpression(routeContext)); |
103 |
0 |
} |
104 |
|
} |
105 |
3 |
if (expressionList.isEmpty()) { |
106 |
0 |
throw new IllegalArgumentException("No expressions configured for: " + this); |
107 |
|
} |
108 |
3 |
return expressionList; |
109 |
|
} |
110 |
|
} |