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