📄 shoprequestaction.java
字号:
/*
* @author : Sujatha
* @Version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : ShopRequestAction.java
* Creation/Modification History :
*
* Sujatha 17-Jan-2003 Created
*
*/
package oracle.otnsamples.vsm.actions.profile;
// IO and servlet API
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oracle.otnsamples.util.MessageCache;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.actions.forms.ShopForm;
import oracle.otnsamples.vsm.services.Administration;
import oracle.otnsamples.vsm.services.AdministrationHome;
import oracle.otnsamples.vsm.services.CategoryException;
import oracle.otnsamples.vsm.services.ProfileManagement;
import oracle.otnsamples.vsm.services.ProfileManagementHome;
import oracle.otnsamples.vsm.services.ShopException;
import oracle.otnsamples.vsm.services.data.Category;
import oracle.otnsamples.vsm.services.data.Shop;
import oracle.otnsamples.vsm.services.data.ShopDetail;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
/**
* This action class is used to handle requests to set up shops in the mall.
*
* @author Sujatha
* @version 1.0
*/
public class ShopRequestAction extends DispatchAction {
/**
* This is the action called from the Struts framework to process a shop
* creation request
*
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
*/
public ActionForward createShop(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
ProfileManagementHome profileHome = null;
ProfileManagement profileBean = null;
ShopForm shop = (ShopForm) form;
ActionForward forward = mapping.findForward("success");
try {
profileHome =
(ProfileManagementHome) ServiceLocator.getLocator().getService("ProfileManagement");
profileBean = profileHome.create();
List shopDetails = new ArrayList(1);
shopDetails.add(new ShopDetail(
request.getLocale().getLanguage(),
shop.getShopName(), shop.getDescription()));
Shop shopInfo =
new Shop(
(String) request.getSession().getAttribute("userName"),
shop.getCategoryID(), new Date(), null, null, shopDetails);
profileBean.requestShop(shopInfo);
request.setAttribute(
"message",
MessageCache.getMessage(
"message.shopcreation.success",
getLocale(request)));
} catch(ShopException ex) {
forward = mapping.findForward("display");
try {
AdministrationHome adminHome =
(AdministrationHome) ServiceLocator.getLocator().getService("Administration");
Administration adminBean = adminHome.create();
Category[] categoryList =
adminBean.getAllCategories(request.getLocale().getLanguage());
request.setAttribute("categories", categoryList);
request.setAttribute(
"message",
MessageCache.getMessage(
"error.shop.duplicaterequest",
getLocale(request)));
request.setAttribute("shop", shop);
} catch(Exception e) {
forward = mapping.findForward("error");
}
} catch(Exception ex) {
ActionErrors errors = new ActionErrors();
errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} finally {
try {
if(profileBean != null) {
profileBean.remove();
}
} catch(Exception ex) {
}
}
return forward;
}
/**
* This is the action called from the Struts framework to display a form for
* shop creation request details
*
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
*/
public ActionForward displayForm(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException,
ServletException {
AdministrationHome adminHome = null;
Administration adminBean = null;
try {
adminHome =
(AdministrationHome) ServiceLocator.getLocator().getService("Administration");
adminBean = adminHome.create();
Category[] categoryList =
adminBean.getAllCategories(request.getLocale().getLanguage());
request.setAttribute("categories", categoryList);
} catch(CategoryException ex) {
ActionErrors errors = new ActionErrors();
errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} catch(Exception ex) {
ActionErrors errors = new ActionErrors();
errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} finally {
try {
if(adminBean != null) {
adminBean.remove();
}
} catch(Exception ex) {
}
}
return mapping.findForward("display");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -