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 protected ExpressionConfig config = new ExpressionConfig();
26
27 public ExpressionMessageSplitter()
28 {
29 super();
30 }
31
32 public ExpressionMessageSplitter(ExpressionConfig config)
33 {
34 this.config = config;
35 setEvaluator(config.getEvaluator());
36 }
37
38 public String getCustomEvaluator()
39 {
40 return config.getCustomEvaluator();
41 }
42
43 public void setCustomEvaluator(String customEvaluator)
44 {
45 config.setCustomEvaluator(customEvaluator);
46 }
47
48 public String getEvaluator()
49 {
50 return config.getEvaluator();
51 }
52
53 public void setEvaluator(String evaluator)
54 {
55
56 if (evaluator.equals("xpath"))
57 {
58 evaluator = "xpath-node";
59 }
60 config.setEvaluator(evaluator);
61 }
62
63 public String getExpression()
64 {
65 return config.getExpression();
66 }
67
68 public void setExpression(String expression)
69 {
70 this.config.setExpression(expression);
71 }
72
73 @Override
74 public void initialise() throws InitialisationException
75 {
76 super.initialise();
77 config.validate(expressionManager);
78 }
79
80 @Override
81 protected List splitMessage(MuleMessage message)
82 {
83 List results = new ArrayList(4);
84 Object result = muleContext.getExpressionManager().evaluate(config.getFullExpression(expressionManager), message);
85 if (result instanceof List)
86 {
87 results.addAll((List)result);
88 }
89 else
90 {
91 results.add(result);
92 logger.warn("Splitter only returned a single result. If this is not expected, please check your split expression");
93 }
94 return results;
95 }
96 }