View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
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   * An entry-point resolver that only allows Service objects that implement the
21   * Callable interface
22   *
23   * @see org.mule.api.lifecycle.Callable
24   */
25  public class CallableEntryPointResolver implements EntryPointResolver
26  {
27      protected static final Method callableMethod;
28  
29      static
30      {
31          try
32          {
33              callableMethod = Callable.class.getMethod("onCall", new Class[] {MuleEventContext.class});
34          }
35          catch (NoSuchMethodException e)
36          {
37              throw new MuleRuntimeException(
38                      MessageFactory.createStaticMessage("Panic! No onCall(MuleEventContext) method found in the Callable interface."));
39          }
40      }
41  
42      public InvocationResult invoke(Object component, MuleEventContext context) throws Exception
43      {
44          if (component instanceof Callable)
45          {
46              Object result = ((Callable) component).onCall(context);
47              return new InvocationResult(this, result, callableMethod);
48          }
49          else
50          {
51              InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED);
52              result.setErrorMessage(CoreMessages.objectDoesNotImplementInterface(component, Callable.class).toString());
53              return result;
54          }
55      }
56  
57      @Override
58      public String toString()
59      {
60          return "CallableEntryPointResolver{}";
61      }
62  }