有完整的程序和源码

源代码在线查看: business.jav

软件大小: 13211 K
上传用户: yingyingyingyin
关键词: 程序 源码
下载地址: 免注册下载 普通下载 VIP

相关代码

				//---------------------------------------------------------
				// Application: Personal of System
				// Author     : eSingle
				// File       : BusinessAction.java
				//
				// Copyright 2002 LandSoft Corp.
				// Generated at Mon Nov 18 10:18:19 CST 2002
				// Created by caoguangxin
				// mailto:gxcao@mail.tsinghua.edu.cn
				//---------------------------------------------------------
				
				
				package com.landsoft.personal.controller;
				
				import javax.sql.*;
				import java.util.*;
				
				import org.apache.commons.logging.LogFactory;
				
				
				import javax.servlet.http.*;
				import javax.servlet.*;
				
				import org.apache.struts.action.*;
				import org.apache.struts.util.*;
				
				import com.landsoft.personal.model.*;
				import com.landsoft.personal.dao.*;
				import com.landsoft.personal.util.*;
				
				public class BusinessAction extends Action {
				  private org.apache.commons.logging.Log __log = LogFactory.getFactory().getInstance(this.getClass());
				  private static final int PAGE_LENGTH = 20;
				
				  public ActionForward execute(ActionMapping mapping, ActionForm form,
				      HttpServletRequest request, HttpServletResponse response) {
				    ActionForward myforward = null;
				    String myaction = mapping.getParameter();
				
				    if (isCancelled(request)) {
				      if (__log.isInfoEnabled()) {
				        __log.info(" [Business] " + mapping.getAttribute() + " - action was cancelled");
				      }
				      return mapping.findForward("cancel");
				    }
				    if (__log.isInfoEnabled()) {
				      __log.info(" [Business] action: "+myaction);
				    }
				    if ("".equalsIgnoreCase(myaction)) {
				      myforward = mapping.findForward("failure");
				    } else if ("VIEW".equalsIgnoreCase(myaction)) {
				      myforward = performView(mapping, form, request, response);
				    } else if ("EDIT".equalsIgnoreCase(myaction)) {
				      myforward = performEdit(mapping, form, request, response);
				    } else if ("ADD".equalsIgnoreCase(myaction)) {
				      myforward = performAdd(mapping, form, request, response);
				    } else if ("SAVE".equalsIgnoreCase(myaction)) {
				      myforward = performSave(mapping, form, request, response);
				    } else if ("REMOVE".equalsIgnoreCase(myaction)) {
				      myforward = performRemove(mapping, form, request, response);
				    } else if ("TRASH".equalsIgnoreCase(myaction)) {
				      myforward = performTrash(mapping, form, request, response);
				    } else if ("LIST".equalsIgnoreCase(myaction)) {
				      myforward = performList(mapping, form, request, response);
				    } else {
				      myforward = mapping.findForward("failure");
				    }
				    return myforward;
				  }
				
				
				  private ActionForward performList(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
				    try {
				      DataSource ds = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
				
				      BusinessDAO businessDAO = new BusinessDAO(ds);
				
				      int offset;
				      int length = PAGE_LENGTH;
				      String pageOffset = request.getParameter("pager.offset");
				      if (pageOffset == null || pageOffset.equals("")) {
				        offset = 0;
				      } else {
				        offset = Integer.parseInt(pageOffset);
				      }
				
				      List businesss = businessDAO.list(offset, length);
				
				      String[] objKeys = {"Business", "list"};
				      String objKey = CacheManager.createKey(objKeys);
				      Integer size = (Integer)SizeCacheManager.getCache(objKey);
				      if(size == null) {
				        size = new Integer(businessDAO.getSize("business", ""));
				        SizeCacheManager.putCache(size, objKey, 1);
				      }
				
				      String url = request.getContextPath()+"/"+mapping.getPath()+".do";
				      String pagerHeader = Pager.generate(offset, size.intValue(), length, url);
				      request.setAttribute("pagerHeader", pagerHeader);
				
				      request.setAttribute("BUSINESSS", businesss);
				    } catch (Exception e) {
				      generalError(request, e);
				      return mapping.findForward("failure");
				    }
				
				    return mapping.findForward("success");
				  }
				
				  private ActionForward performView(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
				    BusinessForm form = (BusinessForm) actionForm;
				    try {
				      DataSource ds = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
				
				      BusinessDAO businessDAO = new BusinessDAO(ds);
				
				      String businessname = request.getParameter("businessname");
				      Business business = businessDAO.retrieve(businessname);
				      if (business == null) {
				        ActionErrors aes = new ActionErrors();
				        aes.add(aes.GLOBAL_ERROR, new ActionError("error.object.notfound", "Business"));
				        saveErrors(request, aes);
				        if (__log.isErrorEnabled()) {
				          __log.error(" [Business] Object not found");
				        }
				      } else {
				        org.apache.commons.beanutils.BeanUtils.populate(form, org.apache.commons.beanutils.BeanUtils.describe(business));
				      }
				    } catch (Exception e) {
				      generalError(request, e);
				      return mapping.findForward("failure");
				    }
				    return mapping.findForward("success");
				  }
				
				  private ActionForward performSave(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
				    BusinessForm form = (BusinessForm) actionForm;
				
				    try {
				      DataSource ds = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
				
				      BusinessDAO businessDAO = new BusinessDAO(ds);
				
				      Business business = new Business();
				      org.apache.commons.beanutils.BeanUtils.populate(business, org.apache.commons.beanutils.BeanUtils.describe(form));
				      int strutsAction = form.getStrutsAction();
				      if (strutsAction == BusinessForm.ADD) {
				        String businessname = business.getBusinessname();
				        if (businessDAO.retrieve(businessname) == null) {
				          businessDAO.insert(business);
				        } else {
				          sqlDuplicateError(request, "Business");
				          return mapping.findForward("failure");
				        }
				      } else if (strutsAction == BusinessForm.EDIT) {
				        businessDAO.update(business);
				      }
				    } catch (Exception e) {
				      generalError(request, e);
				      return mapping.findForward("failure");
				    }
				    return mapping.findForward("success");
				  }
				
				  private ActionForward performEdit(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
				    BusinessForm form = (BusinessForm) actionForm;
				    form.setStrutsAction(BusinessForm.EDIT);
				    try {
				      DataSource ds = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
				
				      BusinessDAO businessDAO = new BusinessDAO(ds);
				
				      String businessname = request.getParameter("businessname");
				
				      Business business = businessDAO.retrieve(businessname);
				      org.apache.commons.beanutils.BeanUtils.populate(form, org.apache.commons.beanutils.BeanUtils.describe(business));
				    } catch (Exception e) {
				      generalError(request, e);
				      return mapping.findForward("failure");
				    }
				    return mapping.findForward("success");
				  }
				
				  private ActionForward performAdd(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
				    BusinessForm form = (BusinessForm) actionForm;
				    form.setStrutsAction(BusinessForm.ADD);
				    return mapping.findForward("success");
				  }
				  private ActionForward performRemove(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
				    return performView(mapping, actionForm, request, response);
				  }
				
				  private ActionForward performTrash(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
				    BusinessForm form = (BusinessForm) actionForm;
				    try {
				      DataSource ds = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
				
				      BusinessDAO businessDAO = new BusinessDAO(ds);
				
				      String businessname = request.getParameter("businessname");
				      businessDAO.delete(businessname);
				    } catch (Exception e) {
				      generalError(request, e);
				      return mapping.findForward("failure");
				    }
				    return mapping.findForward("success");
				  }
				
				
				  private void sqlDuplicateError(HttpServletRequest request, String objName) {
				    ActionErrors aes = new ActionErrors();
				    aes.add(aes.GLOBAL_ERROR, new ActionError("errors.database.duplicate", objName));
				    saveErrors(request, aes);
				    if (__log.isErrorEnabled()) {
				      __log.error(" [Business] Duplicate key Error - " + objName);
				    }
				  }
				
				  private void generalError(HttpServletRequest request, Exception e) {
				    ActionErrors aes = new ActionErrors();
				    aes.add(aes.GLOBAL_ERROR, new ActionError("error.general", e.getMessage()));
				    saveErrors(request, aes);
				    e.printStackTrace();
				    if (__log.isErrorEnabled()) {
				      __log.error(" [Business] Error - " + e.getMessage());
				    }
				  }
				}
							

相关资源