Keith Donald
2008-04-19 20:09:40 +00:00
parent dd8fffa18b
commit 91d0adc696
6 changed files with 43 additions and 10 deletions

View File

@@ -186,14 +186,6 @@ public abstract class AbstractAction implements Action, InitializingBean {
Event result = doPreExecute(context);
if (result == null) {
result = doExecute(context);
if (logger.isDebugEnabled()) {
if (result != null) {
logger.debug("Action '" + getActionNameForLogging() + "' completed execution; result is '"
+ result.getId() + "'");
} else {
logger.debug("Action '" + getActionNameForLogging() + "' completed execution; result is [null]");
}
}
doPostExecute(context);
} else {
if (logger.isInfoEnabled()) {

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.webflow.engine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.webflow.execution.Action;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;
@@ -28,6 +30,8 @@ import org.springframework.webflow.execution.RequestContext;
*/
public class ActionExecutor {
private static final Log logger = LogFactory.getLog(AnnotatedAction.class);
/**
* Private constructor to avoid instantiation.
*/
@@ -44,7 +48,14 @@ public class ActionExecutor {
*/
public static Event execute(Action action, RequestContext context) throws ActionExecutionException {
try {
return action.execute(context);
if (logger.isDebugEnabled()) {
logger.debug("Executing action " + getTargetAction(action));
}
Event event = action.execute(context);
if (logger.isDebugEnabled()) {
logger.debug("Action execution completed; result = " + event);
}
return event;
} catch (ActionExecutionException e) {
throw e;
} catch (Exception e) {
@@ -54,4 +65,12 @@ public class ActionExecutor {
.getAttributes(), e);
}
}
private static Action getTargetAction(Action action) {
if (action instanceof AnnotatedAction) {
return getTargetAction(((AnnotatedAction) action).getTargetAction());
} else {
return action;
}
}
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.webflow.engine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -36,6 +38,8 @@ import org.springframework.webflow.execution.RequestContext;
*/
public class AnnotatedAction extends AnnotatedObject implements Action {
private static final Log logger = LogFactory.getLog(AnnotatedAction.class);
// well known attributes
/**
@@ -138,10 +142,16 @@ public class AnnotatedAction extends AnnotatedObject implements Action {
public Event execute(RequestContext context) throws Exception {
try {
if (logger.isDebugEnabled()) {
logger.debug("Putting action execution attributes " + getAttributes());
}
context.getAttributes().putAll(getAttributes());
Event result = getTargetAction().execute(context);
return postProcessResult(result);
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Clearing action execution attributes " + getAttributes());
}
context.getAttributes().removeAll(getAttributes());
}
}
@@ -160,6 +170,10 @@ public class AnnotatedAction extends AnnotatedObject implements Action {
if (isNamed()) {
// qualify result event id with action name for a named action
String qualifiedId = getName() + "." + resultEvent.getId();
if (logger.isDebugEnabled()) {
logger.debug("Qualifying action result '" + resultEvent.getId() + "'; qualified result = '"
+ qualifiedId + "'");
}
resultEvent = new Event(resultEvent.getSource(), qualifiedId, resultEvent.getAttributes());
}
return resultEvent;

View File

@@ -98,6 +98,5 @@ public interface Action {
* <i>recoverable</i> exceptions should be caught within this method and an appropriate result outcome returned
* <i>or</i> be handled by the current state of the calling flow execution.
*/
// TODO consider changing the execute return value to a simple string for 2.0
public Event execute(RequestContext context) throws Exception;
}

View File

@@ -73,6 +73,10 @@ public class FormActionTests extends TestCase {
public static class TestBeanValidator implements Validator {
private boolean invoked;
public boolean getInvoked() {
return invoked;
}
public boolean supports(Class clazz) {
return TestBean.class.equals(clazz);
}

View File

@@ -5,6 +5,8 @@ import junit.framework.TestCase;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.validation.BindingResult;
import org.springframework.webflow.action.FormAction;
import org.springframework.webflow.action.FormActionTests.TestBeanValidator;
import org.springframework.webflow.definition.StateDefinition;
import org.springframework.webflow.engine.Flow;
import org.springframework.webflow.engine.builder.FlowAssembler;
@@ -313,9 +315,12 @@ public class XmlFlowModelBuilderTests extends TestCase {
}
}));
FlowExecution execution = factory.createFlowExecution(flow);
FormAction action = (FormAction) flow.getApplicationContext().getBean("formAction");
assertFalse(((TestBeanValidator) action.getValidator()).getInvoked());
execution.start(null, new MockExternalContext());
MockExternalContext context = new MockExternalContext();
context.setEventId("submit");
execution.resume(context);
assertTrue(((TestBeanValidator) action.getValidator()).getInvoked());
}
}