01: /*
02: * $Id: CallableEntryPointResolver.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: public class CallableEntryPointResolver implements EntryPointResolver {
31: protected static final Method callableMethod;
32:
33: static {
34: try {
35: callableMethod = Callable.class.getMethod("onCall",
36: new Class[] { MuleEventContext.class });
37: } catch (NoSuchMethodException e) {
38: throw new MuleRuntimeException(
39: MessageFactory
40: .createStaticMessage("Panic! No onCall(MuleEventContext) method found in the Callable interface."));
41: }
42: }
43:
44: public InvocationResult invoke(Object component,
45: MuleEventContext context) throws Exception {
46: if (component instanceof Callable) {
47: Object result = ((Callable) component).onCall(context);
48: return new InvocationResult(result, callableMethod);
49: } else {
50: InvocationResult result = new InvocationResult(
51: InvocationResult.STATE_INVOKE_NOT_SUPPORTED);
52: result.setErrorMessage(ClassUtils.getClassName(getClass())
53: + ":"
54: + CoreMessages.objectDoesNotImplementInterface(
55: component, Callable.class).toString());
56: return result;
57: }
58: }
59:
60: public String toString() {
61: final StringBuffer sb = new StringBuffer();
62: sb.append("CallableEntryPointResolver");
63: sb.append("{}");
64: return sb.toString();
65: }
66: }
|