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 | |
|
21 | |
import java.lang.reflect.Method; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | public class CallableEntryPointResolver implements EntryPointResolver |
30 | |
{ |
31 | |
protected static final Method callableMethod; |
32 | |
|
33 | |
static |
34 | |
{ |
35 | |
try |
36 | |
{ |
37 | 0 | callableMethod = Callable.class.getMethod("onCall", new Class[] {MuleEventContext.class}); |
38 | |
} |
39 | 0 | catch (NoSuchMethodException e) |
40 | |
{ |
41 | 0 | throw new MuleRuntimeException( |
42 | |
MessageFactory.createStaticMessage("Panic! No onCall(MuleEventContext) method found in the Callable interface.")); |
43 | 0 | } |
44 | 0 | } |
45 | |
|
46 | |
public InvocationResult invoke(Object component, MuleEventContext context) throws Exception |
47 | |
{ |
48 | 0 | if (component instanceof Callable) |
49 | |
{ |
50 | 0 | Object result = ((Callable) component).onCall(context); |
51 | 0 | return new InvocationResult(this, result, callableMethod); |
52 | |
} |
53 | |
else |
54 | |
{ |
55 | 0 | InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED); |
56 | 0 | result.setErrorMessage(CoreMessages.objectDoesNotImplementInterface(component, Callable.class).toString()); |
57 | 0 | return result; |
58 | |
} |
59 | |
} |
60 | |
|
61 | |
@Override |
62 | |
public String toString() |
63 | |
{ |
64 | 0 | return "CallableEntryPointResolver{}"; |
65 | |
} |
66 | |
} |