1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.model.resolvers; |
12 | |
|
13 | |
import org.mule.api.MuleEventContext; |
14 | |
import org.mule.api.MuleRuntimeException; |
15 | |
import org.mule.api.lifecycle.Callable; |
16 | |
import org.mule.api.model.EntryPointResolver; |
17 | |
import org.mule.api.model.InvocationResult; |
18 | |
import org.mule.config.i18n.CoreMessages; |
19 | |
import org.mule.config.i18n.MessageFactory; |
20 | |
import org.mule.util.ClassUtils; |
21 | |
|
22 | |
import java.lang.reflect.Method; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 72 | public class CallableEntryPointResolver implements EntryPointResolver |
31 | |
{ |
32 | |
protected static final Method callableMethod; |
33 | |
|
34 | |
static |
35 | |
{ |
36 | |
try |
37 | |
{ |
38 | 2 | callableMethod = Callable.class.getMethod("onCall", new Class[] {MuleEventContext.class}); |
39 | |
} |
40 | 0 | catch (NoSuchMethodException e) |
41 | |
{ |
42 | 0 | throw new MuleRuntimeException( |
43 | |
MessageFactory.createStaticMessage("Panic! No onCall(MuleEventContext) method found in the Callable interface.")); |
44 | 2 | } |
45 | 2 | } |
46 | |
|
47 | |
|
48 | |
public InvocationResult invoke(Object component, MuleEventContext context) throws Exception |
49 | |
{ |
50 | 28 | if (component instanceof Callable) |
51 | |
{ |
52 | 4 | Object result = ((Callable) component).onCall(context); |
53 | 4 | return new InvocationResult(result, callableMethod); |
54 | |
} |
55 | |
else |
56 | |
{ |
57 | 24 | InvocationResult result = new InvocationResult(InvocationResult.STATE_INVOKE_NOT_SUPPORTED); |
58 | 24 | result.setErrorMessage(ClassUtils.getClassName(getClass()) + ":" + |
59 | |
CoreMessages.objectDoesNotImplementInterface(component, Callable.class).toString()); |
60 | 24 | return result; |
61 | |
} |
62 | |
} |
63 | |
|
64 | |
|
65 | |
public String toString() |
66 | |
{ |
67 | 0 | final StringBuffer sb = new StringBuffer(); |
68 | 0 | sb.append("CallableEntryPointResolver"); |
69 | 0 | sb.append("{}"); |
70 | 0 | return sb.toString(); |
71 | |
} |
72 | |
} |