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