1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.module.ognl.expression; |
11 | |
|
12 | |
import org.mule.api.MuleMessage; |
13 | |
import org.mule.api.expression.ExpressionEvaluator; |
14 | |
import org.mule.api.expression.ExpressionRuntimeException; |
15 | |
import org.mule.api.lifecycle.Disposable; |
16 | |
import org.mule.config.i18n.CoreMessages; |
17 | |
|
18 | |
import java.util.Map; |
19 | |
import java.util.concurrent.ConcurrentHashMap; |
20 | |
|
21 | |
import ognl.Ognl; |
22 | |
import ognl.OgnlException; |
23 | |
import org.apache.commons.logging.Log; |
24 | |
import org.apache.commons.logging.LogFactory; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | public class OgnlExpressionEvaluator implements ExpressionEvaluator, Disposable |
30 | |
{ |
31 | 0 | Map<String, Object> expressions = new ConcurrentHashMap<String, Object>(4); |
32 | |
|
33 | |
public static final String NAME = "ognl"; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | protected transient final Log logger = LogFactory.getLog(OgnlExpressionEvaluator.class); |
39 | |
|
40 | |
public Object evaluate(String expression, MuleMessage message) |
41 | |
{ |
42 | 0 | Object o = expressions.get(expression); |
43 | 0 | if(o==null) |
44 | |
{ |
45 | |
try |
46 | |
{ |
47 | 0 | o = Ognl.parseExpression(expression); |
48 | 0 | expressions.put(expression, o); |
49 | |
} |
50 | 0 | catch (OgnlException e) |
51 | |
{ |
52 | 0 | throw new ExpressionRuntimeException(CoreMessages.expressionMalformed(expression, NAME), e); |
53 | 0 | } |
54 | |
} |
55 | |
|
56 | |
try |
57 | |
{ |
58 | 0 | return Ognl.getValue(o, message.getPayload()); |
59 | |
} |
60 | 0 | catch (OgnlException e) |
61 | |
{ |
62 | |
|
63 | 0 | logger.warn(e.getMessage(), e); |
64 | 0 | return null; |
65 | |
} |
66 | |
|
67 | |
} |
68 | |
|
69 | |
public void setName(String name) |
70 | |
{ |
71 | 0 | throw new UnsupportedOperationException("setName"); |
72 | |
} |
73 | |
|
74 | |
public String getName() |
75 | |
{ |
76 | 0 | return NAME; |
77 | |
} |
78 | |
|
79 | |
public void dispose() |
80 | |
{ |
81 | 0 | expressions.clear(); |
82 | 0 | } |
83 | |
} |