⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rolecommand.java

📁 java实现的可配置的工作流引擎,采用jsp+javabean实现
💻 JAVA
字号:
package com.hongsoft.res.command;

import java.util.List;

import org.hibernate.Session;

import com.hongsoft.agile.Agile;
import com.hongsoft.agile.AgileConnection;
import com.hongsoft.res.dispatcher.BaseCommand;
import com.hongsoft.res.formbean.FormUtils;
import com.hongsoft.res.formbean.RoleFormBean;
import com.hongsoft.res.formbean.RoleIteratorFormBean;
import com.hongsoft.res.pojo.ResManager;
import com.hongsoft.res.pojo.Role;

public class RoleCommand extends BaseCommand {
  /**
   * 具体的处理过程
   * @throws com.hongsoft.res.exception.BaseException
   */
  public void command() throws Exception {
    RoleFormBean bean = (RoleFormBean) request.getAttribute(ResParamName.
	ROLE_FORM_BEAN_PARAM);
    String returnView = request.getReturnView();
    StringBuffer sb = new StringBuffer("res.role.");
    String cmdType = request.getCommandType();    
    AgileConnection ac=Agile.connectToServer();
    //实现具体的业务逻辑处理
    if ("create".equals(cmdType)) {
      createRole(ac.getHibernateSession(),bean);
      returnView = "facade";
      request.setAttribute(ResParamName.TIP_PARAM, "成功创建角色!");
    } else if ("modify".equals(cmdType)) {
      //To do
      modifyRole(ac.getHibernateSession(),bean);
      returnView = "facade";
      request.setAttribute(ResParamName.TIP_PARAM, "角色修改成功!");
    } else if ("delete".equals(cmdType)) {
    	ResManager.deleteRole(ac.getHibernateSession(),bean.getRoleID());
    } else if ("load".equals(cmdType)) {
      loadRole(ac.getHibernateSession(),bean); //返回页面由前端的request中指定参数,此处不能指定returnView
    } else if ("search".equals(cmdType)) {
      RoleIteratorFormBean riBean =
	  (RoleIteratorFormBean) request.getAttribute(ResParamName.
	  ROLE_ITERATOR_FORM_BEAN_PARAM);
      searchRole(ac.getHibernateSession(),riBean);
      returnView = "search";
    } 
    Agile.disConnectServer(ac,true);	
    sb.append(returnView);    
    this.forward(sb.toString(), request, response);
  }

  /**
   * 通过角色ID获取角色信息,并写入RoleFormBean,设置request
   * @param bean RoleFormBean对象,该对象的uid必须已被赋值
   * @throws BaseException
   */
  private void loadRole(Session session,RoleFormBean bean) throws Exception {   
      Role role = ResManager.getRole(session,bean.getRoleID());
      bean = FormUtils.getRoleFormBean(role);
      request.setAttribute(ResParamName.ROLE_FORM_BEAN_PARAM, bean);    
  }

  /**
   * 修改角色信息,同时将角色信息写入RoleFormBean中,设置request
   * @param bean RoleFormBean
   * @throws BaseException
   */
  private void modifyRole(Session session,RoleFormBean bean) throws Exception {    
      Role role = FormUtils.getRole(bean);
      ResManager.modifyRole(session,role);
      request.setAttribute(ResParamName.ROLE_FORM_BEAN_PARAM, bean);    
  } 

  /**
   * 搜索角色信息列,将列表信息写入RoleIteratorFormBean中,设置request
   * @param bean RoleFormBean
   * @throws BaseException
   */
  private void searchRole(Session session,RoleIteratorFormBean bean) throws Exception {    
      List list = ResManager.searchRole(session,bean.getRoleName(), true);
      bean.setItr(list.iterator());
      request.setAttribute(ResParamName.ROLE_ITERATOR_FORM_BEAN_PARAM,
			   bean);    
  }

  /**
   * 创建角色信息,同时将角色信息写入RoleFormBean中,设置request
   * @param bean RoleFormBean
   * @throws BaseException
   */
  private void createRole(Session session,RoleFormBean bean) throws Exception {
    
      Role role = FormUtils.getRole(bean);
      role = ResManager.createRole(session,role);
      bean.setRoleID(role.getId());
      request.setAttribute(ResParamName.ROLE_FORM_BEAN_PARAM, bean);    
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -