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

📄 baseaction.java

📁 公司自己开发的工作流引擎
💻 JAVA
字号:
package cn.com.iaspec.workflow.client.web.action.base;

import java.lang.reflect.*;
import java.util.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import org.apache.struts.action.*;

public abstract class BaseAction
    extends Action
    implements Interceptor{
  public final Logger logger=Logger.getLogger(this.getClass());

  public ActionForward execute(ActionMapping mapping,ActionForm form,
      HttpServletRequest request,HttpServletResponse response)
      throws Exception{
    try{
      String methodName=request.getParameter("method");
      if(methodName==null){
        throw new RuntimeException(
            "the method param must be specifed for the action "+
            this.getClass().getName());
      }
      logger.info("the method '"+methodName+"' will be executed...");
      Method method=this.getClass().getMethod(methodName,new Class[]{
          ActionMapping.class,ActionForm.class,HttpServletRequest.class,
          HttpServletResponse.class
      });
      ActionForward forward=this.before(mapping,request,methodName);
      if(forward!=null){
        return forward;
      }
      forward=(ActionForward)method.invoke(this,new Object[]{
          mapping,form,request,response});
      this.after(request,methodName);
      return forward;
    }
    catch(Exception ex){
      ex.printStackTrace();
      throw ex;
    }
  }

  protected void saveErrorInfo(HttpServletRequest request,String key,
      String error){
    Map errors=(Map)request.getAttribute("errorMap");
    if(errors==null){
      errors=new HashMap();
      request.setAttribute("errorMap",errors);
    }
    errors.put(key,error);
  }

  protected void saveErrorInfo(HttpServletRequest request,String error){
    final String defaultErrorKey="default_web_error_key";
    this.saveErrorInfo(request,defaultErrorKey,error);
  }

  /**
   * after advice
   *
   */
  public void after(HttpServletRequest request,String methodName)
      throws Exception{
  }

  /**
   * before advice
   *
   */
  public ActionForward before(ActionMapping mapping,HttpServletRequest request,
      String methodName)
      throws Exception{
    return null;
  }

}

⌨️ 快捷键说明

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