* @return <code>false</code> so that processing continues
*/
public boolean execute(Context context) throws Exception {
// Is there a form bean associated with this ActionConfig?
ActionConfig actionConfig = (ActionConfig)
context.get(getActionConfigKey());
String name = actionConfig.getName();
if (name == null) {
context.remove(getActionFormKey());
return (false);
}
log.trace("Look up form-bean " + name);
// Look up the corresponding FormBeanConfig (if any)
FormBeanConfig formBeanConfig =
actionConfig.getModuleConfig().findFormBeanConfig(name);
if (formBeanConfig == null) {
log.warn("No FormBeanConfig found in module "
+ actionConfig.getModuleConfig().getPrefix()
+ " under name " + name);
context.remove(getActionFormKey());
return (false);
}
// Look up the session scope ActionForm instance (if any)
WebContext wcontext = (WebContext) context;
ActionForm instance = null;
if ("session".equals(actionConfig.getScope())) {
instance = (ActionForm)
wcontext.getSessionScope().get(actionConfig.getAttribute());
}
// Can we recycle the existing instance (if any)?
if (instance != null) {
log.trace("Found an instance in the session; test for reusability");
if (formBeanConfig.getDynamic()) {
String className =
((DynaBean) instance).getDynaClass().getName();
if (className.equals(formBeanConfig.getName())) {
wcontext.put
(getActionFormKey(), instance);
/* It should already be in session scope
if ("session".equals(actionConfig.getScope())) {
wcontext.getSessionScope().put
(actionConfig.getAttribute(), instance);
}
*/
log.debug("Using existing instance (dynamic)");
return (false);
}
} else {
try {
Class configClass =
ClassUtils.getApplicationClass
(formBeanConfig.getType());
if (configClass.isAssignableFrom(instance.getClass())) {
wcontext.put
(getActionFormKey(), instance);
/* It should already be in session scope
if ("session".equals(actionConfig.getScope())) {
wcontext.getSessionScope().put
(actionConfig.getAttribute(), instance);
}
*/
log.debug("Using existing instance (non-dynamic)");
return (false);
}
} catch (Exception e) {
log.debug("Error testing existing instance for reusability; just create a new instance", e);
}
}
}
log.trace("Make a new instance of: " + formBeanConfig);
// Create a new form bean instance
if (formBeanConfig.getDynamic()) {
ModuleConfig moduleConfig = (ModuleConfig)
wcontext.get(getModuleConfigKey());
DynaActionFormClass dynaClass =
DynaActionFormClass.createDynaActionFormClass(formBeanConfig);
instance = (ActionForm) dynaClass.newInstance();
((DynaActionForm) instance).initialize
((ActionMapping) actionConfig);
} else {
instance = (ActionForm)
ClassUtils.getApplicationInstance(formBeanConfig.getType());
}
// Configure and cache the new instance
ActionServlet servlet = (ActionServlet)
wcontext.get(getActionServletKey());
instance.setServlet(servlet);
wcontext.put(getActionFormKey(), instance);
if ("session".equals(actionConfig.getScope())) {
wcontext.getSessionScope().put
(actionConfig.getAttribute(), instance);
} else if ("request".equals(actionConfig.getScope())) {
wcontext.getRequestScope().put
(actionConfig.getAttribute(), instance);
}
return (false);
}