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