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