1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing.outbound; |
12 | |
|
13 | |
import org.mule.api.MuleMessage; |
14 | |
import org.mule.api.lifecycle.InitialisationException; |
15 | |
import org.mule.expression.ExpressionConfig; |
16 | |
|
17 | |
import java.util.ArrayList; |
18 | |
import java.util.List; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class ExpressionMessageSplitter extends AbstractRoundRobinMessageSplitter |
24 | |
{ |
25 | 0 | protected ExpressionConfig config = new ExpressionConfig(); |
26 | |
|
27 | |
public ExpressionMessageSplitter() |
28 | |
{ |
29 | 0 | super(); |
30 | 0 | } |
31 | |
|
32 | |
public ExpressionMessageSplitter(ExpressionConfig config) |
33 | 0 | { |
34 | 0 | this.config = config; |
35 | 0 | setEvaluator(config.getEvaluator()); |
36 | 0 | } |
37 | |
|
38 | |
public String getCustomEvaluator() |
39 | |
{ |
40 | 0 | return config.getCustomEvaluator(); |
41 | |
} |
42 | |
|
43 | |
public void setCustomEvaluator(String customEvaluator) |
44 | |
{ |
45 | 0 | config.setCustomEvaluator(customEvaluator); |
46 | 0 | } |
47 | |
|
48 | |
public String getEvaluator() |
49 | |
{ |
50 | 0 | return config.getEvaluator(); |
51 | |
} |
52 | |
|
53 | |
public void setEvaluator(String evaluator) |
54 | |
{ |
55 | |
|
56 | 0 | if (evaluator.equals("xpath")) |
57 | |
{ |
58 | 0 | evaluator = "xpath-node"; |
59 | |
} |
60 | 0 | config.setEvaluator(evaluator); |
61 | 0 | } |
62 | |
|
63 | |
public String getExpression() |
64 | |
{ |
65 | 0 | return config.getExpression(); |
66 | |
} |
67 | |
|
68 | |
public void setExpression(String expression) |
69 | |
{ |
70 | 0 | this.config.setExpression(expression); |
71 | 0 | } |
72 | |
|
73 | |
@Override |
74 | |
public void initialise() throws InitialisationException |
75 | |
{ |
76 | 0 | super.initialise(); |
77 | 0 | config.validate(expressionManager); |
78 | 0 | } |
79 | |
|
80 | |
@Override |
81 | |
protected List splitMessage(MuleMessage message) |
82 | |
{ |
83 | 0 | List results = new ArrayList(4); |
84 | 0 | Object result = muleContext.getExpressionManager().evaluate(config.getFullExpression(expressionManager), message); |
85 | 0 | if (result instanceof List) |
86 | |
{ |
87 | 0 | results.addAll((List)result); |
88 | |
} |
89 | |
else |
90 | |
{ |
91 | 0 | results.add(result); |
92 | 0 | logger.warn("Splitter only returned a single result. If this is not expected, please check your split expression"); |
93 | |
} |
94 | 0 | return results; |
95 | |
} |
96 | |
} |