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