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