return (null);
}
// Look up the form bean configuration information to use
String name = mapping.getName();
FormBeanConfig config = moduleConfig.findFormBeanConfig(name);
if (config == null) {
return (null);
}
// Look up any existing form bean instance
if (log.isDebugEnabled()) {
log.debug(
" Looking for ActionForm bean instance in scope '"
+ mapping.getScope()
+ "' under attribute key '"
+ attribute
+ "'");
}
ActionForm instance = null;
HttpSession session = null;
if ("request".equals(mapping.getScope())) {
instance = (ActionForm) request.getAttribute(attribute);
} else {
session = request.getSession();
instance = (ActionForm) session.getAttribute(attribute);
}
// Can we recycle the existing form bean instance (if there is one)?
if (instance != null) {
if (config.getDynamic()) {
String className = ((DynaBean) instance).getDynaClass().getName();
if (className.equals(config.getName())) {
if (log.isDebugEnabled()) {
log.debug(
" Recycling existing DynaActionForm instance "
+ "of type '"
+ className
+ "'");
log.trace(" --> " + instance);
}
return (instance);
}
} else {
try {
Class configClass = applicationClass(config.getType());
if (configClass.isAssignableFrom(instance.getClass())) {
if (log.isDebugEnabled()) {
log.debug(
" Recycling existing ActionForm instance "
+ "of class '"
+ instance.getClass().getName()
+ "'");
log.trace(" --> " + instance);
}
return (instance);
}
return (instance);
} catch (Throwable t) {
log.error(servlet.getInternal().getMessage("formBean", config.getType()), t);
return (null);
}
}
}
// Create and return a new form bean instance
if (config.getDynamic()) {
try {
DynaActionFormClass dynaClass =
DynaActionFormClass.createDynaActionFormClass(config);
instance = (ActionForm) dynaClass.newInstance();
((DynaActionForm) instance).initialize(mapping);
if (log.isDebugEnabled()) {
log.debug(
" Creating new DynaActionForm instance "
+ "of type '"
+ config.getType()
+ "'");
log.trace(" --> " + instance);
}
} catch (Throwable t) {
log.error(servlet.getInternal().getMessage("formBean", config.getType()), t);
return (null);
}
} else {
try {
instance = (ActionForm) applicationInstance(config.getType());
if (log.isDebugEnabled()) {
log.debug(
" Creating new ActionForm instance "
+ "of type '"
+ config.getType()
+ "'");
log.trace(" --> " + instance);
}
} catch (Throwable t) {
log.error(servlet.getInternal().getMessage("formBean", config.getType()), t);
return (null);
}
}
instance.setServlet(servlet);
return (instance);