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 public class CallableEntryPointResolver implements EntryPointResolver
31 {
32 protected static final Method callableMethod;
33
34 static
35 {
36 try
37 {
38 callableMethod = Callable.class.getMethod("onCall", new Class[] {MuleEventContext.class});
39 }
40 catch (NoSuchMethodException e)
41 {
42 throw new MuleRuntimeException(
43 MessageFactory.createStaticMessage("Panic! No onCall(MuleEventContext) method found in the Callable interface."));
44 }
45 }
46
47
48 public InvocationResult invoke(Object component, MuleEventContext context) throws Exception
49 {
50 if (component instanceof Callable)
51 {
52 Object result = ((Callable) component).onCall(context);
53 return new InvocationResult(result, callableMethod);
54 }
55 else
56 {
57 InvocationResult result = new InvocationResult(InvocationResult.STATE_INVOKE_NOT_SUPPORTED);
58 result.setErrorMessage(ClassUtils.getClassName(getClass()) + ":" +
59 CoreMessages.objectDoesNotImplementInterface(component, Callable.class).toString());
60 return result;
61 }
62 }
63
64
65 public String toString()
66 {
67 final StringBuffer sb = new StringBuffer();
68 sb.append("CallableEntryPointResolver");
69 sb.append("{}");
70 return sb.toString();
71 }
72 }