1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util.expression; |
12 | |
|
13 | |
import org.mule.MuleServer; |
14 | |
import org.mule.config.i18n.CoreMessages; |
15 | |
import org.mule.endpoint.AbstractEndpointBuilder; |
16 | |
|
17 | |
import org.apache.commons.logging.Log; |
18 | |
import org.apache.commons.logging.LogFactory; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 1146 | public class EndpointInfoExpressionEvaluator implements ExpressionEvaluator |
27 | |
{ |
28 | |
public static final String NAME = "endpoint"; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 1146 | protected transient final Log logger = LogFactory.getLog(EndpointInfoExpressionEvaluator.class); |
34 | |
|
35 | |
public Object evaluate(String expression, Object message) |
36 | |
{ |
37 | 0 | int i = expression.indexOf("."); |
38 | |
String endpointName; |
39 | |
String property; |
40 | 0 | if(i > 0) |
41 | |
{ |
42 | 0 | endpointName = expression.substring(0, i); |
43 | 0 | property = expression.substring(i + 1); |
44 | |
} |
45 | |
else |
46 | |
{ |
47 | 0 | throw new IllegalArgumentException(CoreMessages.expressionMalformed(expression, getName()).getMessage()); |
48 | |
} |
49 | |
|
50 | 0 | AbstractEndpointBuilder eb = (AbstractEndpointBuilder)MuleServer.getMuleContext().getRegistry().lookupEndpointBuilder(endpointName); |
51 | 0 | if(eb!=null) |
52 | |
{ |
53 | |
|
54 | 0 | if(property.equalsIgnoreCase("address")) |
55 | |
{ |
56 | 0 | return eb.getEndpointBuilder().getEndpoint().getAddress(); |
57 | |
} |
58 | |
else |
59 | |
{ |
60 | 0 | throw new IllegalArgumentException(CoreMessages.expressionInvalidForProperty(property, expression).getMessage()); |
61 | |
} |
62 | |
} |
63 | |
else |
64 | |
{ |
65 | 0 | logger.warn("There is no endpoint registered with name: " + endpointName); |
66 | 0 | return null; |
67 | |
} |
68 | |
} |
69 | |
|
70 | |
|
71 | |
public String getName() |
72 | |
{ |
73 | 1146 | return NAME; |
74 | |
} |
75 | |
|
76 | |
|
77 | |
public void setName(String name) |
78 | |
{ |
79 | 0 | throw new UnsupportedOperationException("setName"); |
80 | |
} |
81 | |
} |