1 16 package org.springframework.webflow.action; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.springframework.beans.factory.BeanInitializationException; 21 import org.springframework.beans.factory.InitializingBean; 22 import org.springframework.util.ClassUtils; 23 import org.springframework.webflow.core.collection.AttributeMap; 24 import org.springframework.webflow.execution.Action; 25 import org.springframework.webflow.execution.Event; 26 import org.springframework.webflow.execution.RequestContext; 27 import org.springframework.webflow.execution.support.EventFactorySupport; 28 29 43 public abstract class AbstractAction implements Action, InitializingBean { 44 45 48 protected final Log logger = LogFactory.getLog(getClass()); 49 50 54 public EventFactorySupport getEventFactorySupport() { 55 return new EventFactorySupport(); 56 } 57 58 public void afterPropertiesSet() throws Exception { 59 try { 60 initAction(); 61 } 62 catch (Exception ex) { 63 throw new BeanInitializationException("Initialization of this Action failed: " + ex.getMessage(), ex); 64 } 65 } 66 67 75 protected void initAction() throws Exception { 76 } 77 78 81 protected Event success() { 82 return getEventFactorySupport().success(this); 83 } 84 85 90 protected Event success(Object result) { 91 return getEventFactorySupport().success(this, result); 92 } 93 94 97 protected Event error() { 98 return getEventFactorySupport().error(this); 99 } 100 101 106 protected Event error(Exception e) { 107 return getEventFactorySupport().error(this, e); 108 } 109 110 113 protected Event yes() { 114 return getEventFactorySupport().yes(this); 115 } 116 117 120 protected Event no() { 121 return getEventFactorySupport().no(this); 122 } 123 124 129 protected Event result(boolean booleanResult) { 130 return getEventFactorySupport().event(this, booleanResult); 131 } 132 133 153 protected Event result(String eventId) { 154 return getEventFactorySupport().event(this, eventId); 155 } 156 157 181 protected Event result(String eventId, AttributeMap resultAttributes) { 182 return getEventFactorySupport().event(this, eventId, resultAttributes); 183 } 184 185 193 protected Event result(String eventId, String resultAttributeName, Object resultAttributeValue) { 194 return getEventFactorySupport().event(this, eventId, resultAttributeName, resultAttributeValue); 195 } 196 197 public final Event execute(RequestContext context) throws Exception { 198 if (logger.isDebugEnabled()) { 199 logger.debug("Action '" + getActionNameForLogging() + "' beginning execution"); 200 } 201 Event result = doPreExecute(context); 202 if (result == null) { 203 result = doExecute(context); 204 if (logger.isDebugEnabled()) { 205 if (result != null) { 206 logger.debug("Action '" + getActionNameForLogging() + "' completed execution; result is '" + result.getId() + "'"); 207 } 208 else { 209 logger.debug("Action '" + getActionNameForLogging() + "' completed execution; result is [null]"); 210 } 211 } 212 doPostExecute(context); 213 } 214 else { 215 if (logger.isInfoEnabled()) { 216 logger.info("Action execution disallowed; pre-execution result is '" + result.getId() + "'"); 217 } 218 } 219 return result; 220 } 221 222 224 229 protected String getActionNameForLogging() { 230 return ClassUtils.getShortName(getClass()); 231 } 232 233 251 protected Event doPreExecute(RequestContext context) throws Exception { 252 return null; 253 } 254 255 264 protected abstract Event doExecute(RequestContext context) throws Exception ; 265 266 277 protected void doPostExecute(RequestContext context) throws Exception { 278 } 279 } | Popular Tags |