📄 shopmanagementactions.java
字号:
/*
* @author : Sujatha
* @Version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : ShopManagementActions.java
* Creation/Modification History :
*
* Sujatha 16-Jan-2003 Created
*
*/
package oracle.otnsamples.vsm.actions.owner;
// IO and Servlet APIs
import java.io.IOException;
import java.util.ArrayList;
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.ShopException;
import oracle.otnsamples.vsm.services.ShopOwner;
import oracle.otnsamples.vsm.services.ShopOwnerHome;
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 manage the shop - update shop information,
* discontinue shop etc.
*
* @author Sujatha
* @version 1.0
*/
public class ShopManagementActions extends DispatchAction {
/**
* This is the action called from the Struts framework to discontinue a given
* shop
*
* @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 discontinue(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
ShopOwnerHome shopHome = null;
ShopOwner shop = null;
ActionForward forward = mapping.findForward("discontinued");
try {
shopHome =
(ShopOwnerHome) ServiceLocator.getLocator().getService("ShopOwner");
shop = shopHome.create();
shop.discontinueShop(
(String) request.getSession().getAttribute("shopID"),
request.getParameter("justify"),
request.getLocale().getLanguage());
request.setAttribute(
"message",
MessageCache.getMessage(
"message.shopdiscontinue.success",
getLocale(request)));
} catch(ShopException ex) {
servlet.log("DiscontinueShopError", ex);
ActionErrors errors = new ActionErrors();
errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} catch(Exception ex) {
servlet.log("DiscontinueShopError", ex);
ActionErrors errors = new ActionErrors();
errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} finally {
try {
if(shop != null) {
shop.remove();
}
} catch(Exception ex) {
}
}
return forward;
}
/**
* This is the action called from the Struts framework to retrieve
* information about a shop
*
* @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 getShopDetails(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException,
ServletException {
ShopOwnerHome shopHome = null;
ShopOwner shopBean = null;
AdministrationHome adminHome = null;
Administration adminBean = null;
Shop shop = null;
Category category = null;
ActionForward forward = mapping.findForward("shopdetailsform");
try {
String langID = request.getLocale().getLanguage();
shopHome =
(ShopOwnerHome) ServiceLocator.getLocator().getService("ShopOwner");
shopBean = shopHome.create();
shop =
shopBean.getShopDetails(
(String) request.getSession().getAttribute("shopID"),
langID);
// Get the category name associated with this shop
adminHome =
(AdministrationHome) ServiceLocator.getLocator().getService("Administration");
adminBean = adminHome.create();
category = adminBean.findCategory(shop.getCategoryId(), langID);
request.setAttribute("category", category.getName());
request.setAttribute("shop", shop);
} catch(ShopException ex) {
servlet.log("ShopDetailsError", ex);
ActionErrors errors = new ActionErrors();
errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} catch(Exception ex) {
servlet.log("ShopDetailsError", ex);
ActionErrors errors = new ActionErrors();
errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} finally {
try {
if(shopBean != null) {
shopBean.remove();
}
if(adminBean != null) {
adminBean.remove();
}
} catch(Exception ex) {
}
}
return forward;
}
/**
* This is the action called from the Struts framework to update shop
* information
*
* @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 editShopDetails(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException,
ServletException {
ShopOwnerHome shopHome = null;
ShopOwner shopBean = null;
ShopForm shopInfo = (ShopForm) form;
Shop shop = null;
ActionForward forward = mapping.findForward("success");
String langID = request.getLocale().getLanguage();
try {
shopHome =
(ShopOwnerHome) ServiceLocator.getLocator().getService("ShopOwner");
shopBean = shopHome.create();
List shopDetails = new ArrayList(1);
shopDetails.add(new ShopDetail(
langID, shopInfo.getShopName(),
shopInfo.getDescription()));
// Construct a value object to be passed to the shop service
shop =
new Shop(
(String) request.getSession().getAttribute("userName"), null,
null, (String) request.getSession().getAttribute("shopID"),
null, shopDetails);
shopBean.updateShopDetails(shop);
request.setAttribute(
"message",
MessageCache.getMessage(
"message.shopupdate.success",
getLocale(request)));
} catch(ShopException ex) {
servlet.log("EditShopDetailsError", ex);
request.setAttribute(
"message",
MessageCache.getMessage(
ex.getMessageCode(),
getLocale(request)));
forward = mapping.findForward("shopdetailsform");
AdministrationHome adminHome = null;
Administration adminBean = null;
/* If shop updation fails, retrieve earlier shop and category information
and put the same in request scope to display the shop details form */
try {
shop =
shopBean.getShopDetails(
(String) request.getSession().getAttribute("shopID"),
langID);
adminHome =
(AdministrationHome) ServiceLocator.getLocator().getService("Administration");
adminBean = adminHome.create();
Category category =
adminBean.findCategory(shop.getCategoryId(), langID);
request.setAttribute("category", category.getName());
} catch(Exception e) {
servlet.log("EditShopDetailsError", ex);
forward = mapping.findForward("error");
}
request.setAttribute("shop", shop);
} catch(Exception ex) {
servlet.log("EditShopDetailsError", ex);
ActionErrors errors = new ActionErrors();
errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} finally {
try {
if(shopBean != null) {
shopBean.remove();
}
} catch(Exception ex) {
}
}
return forward;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -