1 16 package org.springframework.webflow.action; 17 18 import org.springframework.binding.convert.ConversionService; 19 import org.springframework.binding.convert.support.DefaultConversionService; 20 import org.springframework.binding.method.MethodInvoker; 21 import org.springframework.binding.method.MethodSignature; 22 import org.springframework.util.Assert; 23 import org.springframework.webflow.execution.Action; 24 import org.springframework.webflow.execution.Event; 25 import org.springframework.webflow.execution.RequestContext; 26 27 39 public abstract class AbstractBeanInvokingAction extends AbstractAction { 40 41 45 private MethodSignature methodSignature; 46 47 52 private MethodInvoker methodInvoker = new MethodInvoker(); 53 54 58 private ActionResultExposer methodResultExposer; 59 60 63 private ResultEventFactory resultEventFactory = new SuccessEventFactory(); 64 65 69 protected AbstractBeanInvokingAction(MethodSignature methodSignature) { 70 Assert.notNull(methodSignature, "The signature of the target method to invoke is required"); 71 this.methodSignature = methodSignature; 72 } 73 74 77 public MethodSignature getMethodSignature() { 78 return methodSignature; 79 } 80 81 85 public ActionResultExposer getMethodResultExposer() { 86 return methodResultExposer; 87 } 88 89 94 public void setMethodResultExposer(ActionResultExposer methodResultExposer) { 95 this.methodResultExposer = methodResultExposer; 96 } 97 98 101 protected ResultEventFactory getResultEventFactory() { 102 return resultEventFactory; 103 } 104 105 110 public void setResultEventFactory(ResultEventFactory resultEventFactory) { 111 this.resultEventFactory = resultEventFactory; 112 } 113 114 119 public void setConversionService(ConversionService conversionService) { 120 methodInvoker.setConversionService(conversionService); 121 } 122 123 126 protected MethodInvoker getMethodInvoker() { 127 return methodInvoker; 128 } 129 130 protected Event doExecute(RequestContext context) throws Exception { 131 Object bean = getBean(context); 132 Object returnValue = getMethodInvoker().invoke(methodSignature, bean, context); 133 if (methodResultExposer != null) { 134 methodResultExposer.exposeResult(returnValue, context); 135 } 136 return resultEventFactory.createResultEvent(bean, returnValue, context); 137 } 138 139 141 148 protected abstract Object getBean(RequestContext context) throws Exception ; 149 150 } | Popular Tags |