/* ===================================================================
* AbstractEatCommandController.java
*
* Created Sep 19, 2004 4:52:17 PM
*
* Copyright (c) 2004 Matt Magoffin (spamsqr@msqr.us)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
* ===================================================================
* $Id: AbstractEatCommandController.java 28 2009-05-04 01:19:45Z msqr $
* ===================================================================
*/
package magoffin.matt.ieat.web;
import java.lang.reflect.Constructor;
import javax.servlet.http.HttpServletRequest;
import magoffin.matt.ieat.biz.DomainObjectFactory;
import magoffin.matt.ieat.biz.RecipeBiz;
import magoffin.matt.ieat.biz.RecipeSearchBiz;
import magoffin.matt.ieat.biz.UserBiz;
import magoffin.matt.util.StringUtil;
import magoffin.matt.xweb.util.MessagesSource;
import magoffin.matt.xweb.util.ServletRequestDataBinderTemplate;
import org.springframework.validation.DataBinder;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.mvc.AbstractCommandController;
/**
* Abstract base class for command controllers.
*
* @author Matt Magoffin (spamsqr@msqr.us)
* @version $Revision: 28 $ $Date: 2009-05-04 13:19:45 +1200 (Mon, 04 May 2009) $
*/
public abstract class AbstractEatCommandController extends AbstractCommandController {
/** The RecipeBiz. */
protected RecipeBiz recipeBiz = null;
/** The RecipeSearchBiz. */
protected RecipeSearchBiz recipeSearchBiz = null;
/** The UserBiz. */
protected UserBiz userBiz = null;
private String messagesSourceBeanName = "messageSource";
private String recipeBizBeanName = "recipeBiz";
private String recipeSearchBizBeanName = "recipeSearchBiz";
private String userBizBeanName = "userBiz";
private String domainObjectFactoryBeanName = "domainObjectFactory";
private ServletRequestDataBinderTemplate binderTemplate = null;
private String successView = null;
private String errorView = null;
private DomainObjectFactory domainObjectFactory = null;
private MessagesSource messagesSource = null;
/**
* Default constructor.
*/
public AbstractEatCommandController() {
super();
}
/**
* Construct with a command class.
*
* @param commandClass the command class
*/
public AbstractEatCommandController(Class> commandClass) {
super(commandClass);
}
/**
* Construct with a command class and name.
*
* @param commandClass the command class
* @param commandName the command name
*/
public AbstractEatCommandController(Class> commandClass, String commandName) {
super(commandClass, commandName);
}
@Override
protected void initApplicationContext() {
super.initApplicationContext();
if (recipeBiz == null) {
recipeBiz = (RecipeBiz)getApplicationContext()
.getBean(recipeBizBeanName);
}
if (recipeSearchBiz == null) {
recipeSearchBiz = (RecipeSearchBiz)getApplicationContext()
.getBean(recipeSearchBizBeanName);
}
if (userBiz == null) {
userBiz = (UserBiz)getApplicationContext()
.getBean(userBizBeanName);
}
if ( messagesSource == null ) {
messagesSource = (MessagesSource)getApplicationContext()
.getBean(messagesSourceBeanName);
}
if ( domainObjectFactory == null ) {
domainObjectFactory = (DomainObjectFactory)getApplicationContext()
.getBean(domainObjectFactoryBeanName);
}
String cmdName = StringUtil.trimToNull(getCommandName());
if ( cmdName == null || cmdName.equals("command") ) {
// default
setCommandName(WebConstants.DEFALUT_MODEL_OBJECT);
}
}
/**
* Create a DataBinder object based on the dataBinderClass property.
*
*
If the dataBinderClass property is set, this method will
* attempt to instantiate that class by calling a constructor with a method
* signature of ServletRequestDataBinder(Object,String,Map).
* The Object and String passed into the constructor are the standard
* command and command name objects normally passed to ServetRequestDataBinder
* implementations. The Map argument will be the dataBinderInitializerMap
* object configured in this controller instance.