1 16 package org.springframework.webflow.action; 17 18 import org.springframework.util.Assert; 19 import org.springframework.webflow.execution.Event; 20 import org.springframework.webflow.execution.RequestContext; 21 import org.springframework.webflow.util.DispatchMethodInvoker; 22 23 73 public class MultiAction extends AbstractAction { 74 75 79 private DispatchMethodInvoker methodInvoker; 80 81 84 private MethodResolver methodResolver = new DefaultMultiActionMethodResolver(); 85 86 93 protected MultiAction() { 94 setTarget(this); 95 } 96 97 106 public MultiAction(Object target) { 107 setTarget(target); 108 } 109 110 114 protected final void setTarget(Object target) { 115 methodInvoker = new DispatchMethodInvoker(target, new Class [] { RequestContext.class } ); 116 } 117 118 121 public MethodResolver getMethodResolver() { 122 return methodResolver; 123 } 124 125 130 public void setMethodResolver(MethodResolver methodResolver) { 131 this.methodResolver = methodResolver; 132 } 133 134 protected final Event doExecute(RequestContext context) throws Exception { 135 String method = getMethodResolver().resolveMethod(context); 136 Object obj = methodInvoker.invoke(method, new Object [] { context }); 137 if (obj != null) { 138 Assert.isInstanceOf(Event.class, obj, 139 "The '" + method + "' action execution method on target object '" + 140 methodInvoker.getTarget() + "' did not return an Event object but '" + 141 obj + "' of type " + obj.getClass().getName() + " -- " + 142 "Programmer error; make sure the method signature conforms to " + 143 "'public Event ${method}(RequestContext context) throws Exception;'."); 144 } 145 return (Event)obj; 146 } 147 148 155 public interface MethodResolver { 156 157 163 public String resolveMethod(RequestContext context); 164 } 165 } | Popular Tags |