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