1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.expression; |
8 | |
|
9 | |
import org.mule.RequestContext; |
10 | |
import org.mule.api.MuleContext; |
11 | |
import org.mule.api.MuleEventContext; |
12 | |
import org.mule.api.MuleMessage; |
13 | |
import org.mule.api.MuleRuntimeException; |
14 | |
import org.mule.api.context.MuleContextAware; |
15 | |
import org.mule.api.expression.ExpressionEvaluator; |
16 | |
import org.mule.api.service.Service; |
17 | |
import org.mule.config.i18n.CoreMessages; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class MuleContextExpressionEvaluator implements ExpressionEvaluator, MuleContextAware |
34 | |
{ |
35 | |
public static final String NAME = "context"; |
36 | |
|
37 | |
protected MuleContext muleContext; |
38 | |
|
39 | |
public void setMuleContext(MuleContext context) |
40 | |
{ |
41 | 0 | this.muleContext = context; |
42 | 0 | } |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public Object evaluate(String expression, MuleMessage message) |
52 | |
{ |
53 | 0 | if (expression.equals("serviceName")) |
54 | |
{ |
55 | 0 | return getEventContext().getFlowConstruct().getName(); |
56 | |
} |
57 | 0 | else if (expression.equals("modelName")) |
58 | |
{ |
59 | 0 | if (getEventContext().getFlowConstruct() instanceof Service) |
60 | |
{ |
61 | 0 | return ((Service) getEventContext().getFlowConstruct()).getModel().getName(); |
62 | |
} |
63 | |
else |
64 | |
{ |
65 | 0 | throw new UnsupportedOperationException("The 'modelName' function can only be used with Service"); |
66 | |
} |
67 | |
} |
68 | 0 | else if (expression.equals("inboundEndpoint")) |
69 | |
{ |
70 | 0 | return getEventContext().getEndpointURI(); |
71 | |
} |
72 | 0 | else if (expression.equals("serverId")) |
73 | |
{ |
74 | 0 | return getMuleContext().getConfiguration().getId(); |
75 | |
} |
76 | 0 | else if (expression.equals("clusterId")) |
77 | |
{ |
78 | 0 | return getMuleContext().getConfiguration().getClusterId(); |
79 | |
} |
80 | 0 | else if (expression.equals("domainId")) |
81 | |
{ |
82 | 0 | return getMuleContext().getConfiguration().getDomainId(); |
83 | |
} |
84 | 0 | else if (expression.equals("workingDir")) |
85 | |
{ |
86 | 0 | return getMuleContext().getConfiguration().getWorkingDirectory(); |
87 | |
} |
88 | 0 | else if (expression.equals("homeDir")) |
89 | |
{ |
90 | 0 | return getMuleContext().getConfiguration().getMuleHomeDirectory(); |
91 | |
} |
92 | |
else |
93 | |
{ |
94 | 0 | throw new IllegalArgumentException(expression); |
95 | |
} |
96 | |
} |
97 | |
|
98 | |
protected MuleContext getMuleContext() |
99 | |
{ |
100 | 0 | return muleContext; |
101 | |
} |
102 | |
|
103 | |
protected MuleEventContext getEventContext() |
104 | |
{ |
105 | 0 | if(RequestContext.getEventContext()==null) |
106 | |
{ |
107 | 0 | throw new MuleRuntimeException(CoreMessages.objectIsNull("MuleEventContext")); |
108 | |
} |
109 | |
else |
110 | |
{ |
111 | 0 | return RequestContext.getEventContext(); |
112 | |
} |
113 | |
} |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public String getName() |
121 | |
{ |
122 | 0 | return NAME; |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public void setName(String name) |
131 | |
{ |
132 | 0 | throw new UnsupportedOperationException(); |
133 | |
} |
134 | |
} |