Coverage Report - org.mule.model.resolvers.CallableEntryPointResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
CallableEntryPointResolver
62%
10/16
100%
2/2
2
 
 1  
 /*
 2  
  * $Id: CallableEntryPointResolver.java 10489 2008-01-23 17:53:38Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 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  
  * An entrypoint resolver that only allows Service objects that implmement the
 26  
  * Callable interface
 27  
  *
 28  
  * @see org.mule.api.lifecycle.Callable
 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  
 }