webwork *.action的执行流程(http://seadragonnj.javaeye.com/blog/144412)

这里把webwork的工作流程作一个简单的记录吧,算是这里看源码的总结:

当一个*.action请求过来之后 ,被com.opensymphony.webwork.dispatcher.ServletDispatcher这个类截获,很自然这个Servlet首先会调用

java 代码
  1. public void init(ServletConfig servletConfig) throws ServletException {   
  2.       super.init(servletConfig);   
  3.       DispatcherUtils.initialize(getServletContext());   
  4.   }  
这个方法先进行一些初始化工作,它最终调用DispatcherUtils的init()方法做初始化工作,init()方法通过调用default.properties这样的属性文件进行初始化,初始化工作结束后调用
java 代码
  1. public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException   

这个方法,剩下所有事情都发生到这里了~~~~

java 代码
  1. public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {   
  2.        DispatcherUtils du = DispatcherUtils.getInstance();   
  3.        //根据前面的初始数据对字符集、本地化等一些基本信息进行设置   
  4.        du.prepare(request, response);   
  5.        //(一)、通过request对象,读取URL来得到action的name和methodName   
  6.        ActionMapping mapping = ActionMapperFactory.getMapper().getMapping(request);   
  7.        if (mapping == null) {   
  8.            try {   
  9.                response.sendError(404);   
  10.            } catch (IOException e) {   
  11.                LOG.error("Could not send 404 after not finding any ActionMapping", e);   
  12.            }   
  13.            return;   
  14.        }   
  15.   
  16.        try {   
  17.         //对HttpServletRequest进行了包装   
  18.            request = du.wrapRequest(request, getServletContext());   
  19.        } catch (IOException e) {   
  20.            String message = "Could not wrap servlet request with MultipartRequestWrapper!";   
  21.            LOG.error(message, e);   
  22.            throw new ServletException(message, e);   
  23.        }   
  24.        //转发继续处理   
  25.        du.serviceAction(request, response, getServletContext(), mapping);   
  26.    }  

在这里有必要看一下上面的(一)发生了什么

首先通过工厂类来得到一个ActionMaper的实例,ActionMaper就是提供一个request到action的mapping(映射),它其实做很少的工作,它并不会去考虑这个映射的合法性。工厂类通过读取default.properties属性文件里的

  1. webwork.mapper.class=com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper  

 得到要实例化那个对象,这个对象会根据URL得到nameSpace,actionnName,methodNamet等信息。最后转发到DispatcherUtils对象的serviceAction(request, response, getServletContext(), mapping);方法继续处理。

在这个方法中做的主要工作就是创建一个DefaultActionProxy对象,它是ActionProxy默认实现,它就是一个从webwork到xwork的action之间的一个桥梁

DefaultActionProxy的构建函数中,有通过

  1. config = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, actionName);//这里完成解析xwork.xml的工作  

 这段代码解析xwork.xml文件,实际上它最后通过XmlConfigurationProvider这个类进行XML文件的解析,在DefaultActionProxy这个对象的构建过程中还会创建一个DefaultActionInvocation对象,它是ActionInvocation的默认实现,action执行就是在这里完成的,包括所有interptors和action执行后的result的执行,都在这里完成,这个类的关键是invoke()这个方法,

java 代码
  1.  public String invoke() throws Exception {   
  2.         if (executed) {   
  3.             throw new IllegalStateException("Action has already executed");   
  4.         }   
  5.         //执行interceptors,这里用的责任链模式,最好看一下这个模式,才能对这段代码怎么运行有一个更好的理解   
  6.         if (interceptors.hasNext()) {   
  7.             Interceptor interceptor = (Interceptor) interceptors.next();   
  8.             resultCode = interceptor.intercept(this);   
  9.         } else {   
  10.             //在action之后调用Action类中的方法,并返回result代码   
  11.             resultCode = invokeActionOnly();   
  12.         }   
  13.   
  14.         // this is needed because the result will be executed, then control will return to the Interceptor, which will   
  15.         // return above and flow through again   
  16. //      这里干什么不太清楚   
  17.         if (!executed) {   
  18.             if (preResultListeners != null) {   
  19.                 for (Iterator iterator = preResultListeners.iterator();   
  20.                      iterator.hasNext();) {   
  21.                     PreResultListener listener = (PreResultListener) iterator.next();   
  22.                     listener.beforeResult(this, resultCode);   
  23.                 }   
  24.             }   
  25. //            在这里执行result   
  26.             if (proxy.getExecuteResult()) {   
  27.                 executeResult();   
  28.             }   
  29.   
  30.             executed = true;   
  31.         }   
  32.   
  33.         return resultCode;   
  34.     }  
XML中:<action name="viewGroupFields" class="com.smics.apps.etst.action.admin.BaseAdminAction"> <result name="success" type="freemarker">/admin/newGroupFields.ftl</result> </action> 对应的BaseAdminAction中: /* */ package com.smics.apps.etst.action.admin; /* */ /* */ import com.smics.apps.etst.action.BaseAction; /* */ import com.smics.apps.etst.domain.admin.GroupFields; /* */ import com.smics.apps.etst.domain.admin.ReasonCode; /* */ import com.smics.apps.etst.domain.admin.ResponserDept; /* */ import com.smics.apps.etst.service.AdminService; /* */ import java.util.ArrayList; /* */ import java.util.List; /* */ /* */ public class BaseAdminAction extends BaseAction /* */ { /* 20 */ public static final List FIELDS_NAMES = new ArrayList(); /* */ /* 22 */ public static final List REASON_CODE_TYPE = new ArrayList(); /* */ private Long groupId; /* */ private Long rCodeId; /* */ private Long rDeptId; /* */ protected GroupFields groupField; /* */ protected ReasonCode reasonCode; /* */ protected ResponserDept responserDept; /* */ /* */ public boolean hasPermission() /* */ { /* 56 */ return hasAdminPrivilege(); /* */ } /* */ public boolean hasSuperPermission() { /* 59 */ return isSuperAdmin(); /* */ } /* */ /* */ public List getGroupFieldsNamesList() { /* 63 */ return this.adminService.getGroupFieldsNamesList(); /* */ } /* */ public List getGroupFields() { /* 66 */ return this.adminService.loadAllGroupFieldsList(); /* */ } /* */ /* */ public List getReasonCodes() { /* 70 */ return this.adminService.loadAllReasonCodeList(); /* */ } /* */ /* */ public List getResponserDepts() { /* 74 */ return this.adminService.loadAllResponserDeptList(); /* */ } /* */ /* */ public List getPieSiteList() { /* 78 */ return this.adminService.getPieSiteList(); /* */ } /* */ /* */ public void setGroupId(Long groupId) { /* 82 */ this.groupId = groupId; /* 83 */ this.groupField = this.adminService.loadGroupFieldsByGroupId(groupId); /* */ } /* */ /* */ public void setRCodeId(Long codeId) { /* 87 */ this.rCodeId = codeId; /* 88 */ this.reasonCode = this.adminService.loadReasonCodeById(codeId); /* */ } /* */ /* */ public void setRDeptId(Long deptId) { /* 92 */ this.rDeptId = deptId; /* 93 */ this.responserDept = this.adminService.loadResponserDeptById(deptId); /* */ } /* */ /* */ public GroupFields getGroupField() { /* 97 */ return this.groupField; /* */ } /* */ /* */ public void setGroupField(GroupFields groupField) { /* 101 */ this.groupField = groupField; /* */ } /* */ /* */ public ReasonCode getReasonCode() { /* 105 */ return this.reasonCode; /* */ } /* */ /* */ public void setReasonCode(ReasonCode reasonCode) { /* 109 */ this.reasonCode = reasonCode; /* */ } /* */ /* */ public ResponserDept getResponserDept() { /* 113 */ return this.responserDept; /* */ } /* */ /* */ public void setResponserDept(ResponserDept responserDept) { /* 117 */ this.responserDept = responserDept; /* */ } /* */ /* */ static /* */ { /* 39 */ FIELDS_NAMES.add("EE_Group"); /* 40 */ FIELDS_NAMES.add("MPC_Group"); /* 41 */ FIELDS_NAMES.add("PIE_Group"); /* 42 */ FIELDS_NAMES.add("LineLeader_Group"); /* 43 */ FIELDS_NAMES.add("QC_Line_Leader"); /* */ /* 45 */ FIELDS_NAMES.add("WaitNextProcess_Group"); /* */ /* 47 */ FIELDS_NAMES.add("System Admin"); /* */ /* 49 */ REASON_CODE_TYPE.add("Scrap"); /* 50 */ REASON_CODE_TYPE.add("Unscrap"); /* 51 */ REASON_CODE_TYPE.add("Terminate"); /* 52 */ REASON_CODE_TYPE.add("Unterminate"); /* */ } /* */ } /* Location: C:\Users\JE03789\Desktop\etst\WEB-INF\classes\ * Qualified Name: com.smics.apps.etst.action.admin.BaseAdminAction * JD-Core Version: 0.6.0 */
08-29
请解释下面代码:/* */ package com.smics.apps.erc.action.admin; /* */ /* */ import com.smics.apps.erc.RuncardRule; /* */ import com.smics.apps.erc.domain.ErcMastForm; /* */ import com.smics.apps.erc.service.ErcService; /* */ import com.smics.apps.fecp.service.StrIntegrationService; /* */ import com.smics.apps.sso.domain.UserLogin; /* */ import com.smics.apps.workflow.domain.IProcessLog; /* */ import java.util.Date; /* */ import java.util.HashMap; /* */ import java.util.Map; /* */ import org.apache.commons.logging.Log; /* */ import org.apache.commons.logging.LogFactory; /* */ /* */ public class CancelRuncardByType extends BaseSuperAdminActon /* */ { /* */ private String caseNo; /* */ private String returnto; /* */ private Long ercFormId; /* */ private String message; /* 31 */ protected static final Log log = LogFactory.getLog(CancelRuncardByType.class); /* */ /* */ public boolean hasPermission() /* */ { /* 35 */ return (super.hasPermission()) || (this.ercService.isApplicantGroup(this.caseNo, getUserLogin().getUserLoginId())); /* */ } /* */ /* */ public String execute() /* */ throws Exception /* */ { /* 41 */ Map parameters = null; /* 42 */ Map result = null; /* 43 */ ErcMastForm ercForm = this.ercService.findRequestFormByCaseNo(this.caseNo); /* */ /* 45 */ if (ercForm == null) { /* 46 */ addActionError("The caseNo is not exist!"); /* 47 */ return getReturnValue("input", this.returnto); /* */ } /* 49 */ String mbxKey = ercForm.getFabId(); /* 50 */ if (mbxKey == null) { /* 51 */ addActionError("unKnow Site " + ercForm.getFabId()); /* 52 */ return getReturnValue("input", this.returnto); /* */ } /* 54 */ if ("Paper".equalsIgnoreCase(ercForm.getCancelType())) { /* 55 */ parameters = RuncardRule.eCancelRunCardParameters(ercForm, "Paper", "Release To Fab"); /* */ } /* 57 */ else if ("After".equalsIgnoreCase(ercForm.getCancelType())) { /* 58 */ Map resultStatus = new HashMap(); /* 59 */ Map paraStatus = new HashMap(); /* 60 */ paraStatus = RuncardRule.getRuncardStatusPara(ercForm); /* 61 */ resultStatus = this.ercService.getRuncardStatus(mbxKey, "eRunCardStatus", paraStatus); /* */ /* 63 */ String succ = (String)resultStatus.get("Result"); /* 64 */ String removeRCFlag = (String)resultStatus.get("RemoveRCFlag"); /* 65 */ String runcardStatus = (String)resultStatus.get("Status"); /* 66 */ if ((resultStatus == null) || (!"0".equalsIgnoreCase(succ))) { /* 67 */ addActionError("MES Return Error:" + (String)result.get("ErrorDesc")); /* */ /* 69 */ addActionError("Withdraws runcard failure,because the runcard status is not set future hold in MES,please contact the business owner!"); /* 70 */ log.info("User:(" + getUserLogin().getUserLoginId() + ") get eRunCardStatus failure when clicked the withdraw!"); /* */ /* 74 */ return getReturnValue("input", this.returnto); /* 75 */ }if ("Running".equalsIgnoreCase(runcardStatus)) { /* 76 */ addActionError("Runcard is spliting,can not withdraw!"); /* 77 */ return getReturnValue("input", this.returnto); /* */ } /* 79 */ parameters = RuncardRule.eCancelRunCardParameters(ercForm, "After", ""); /* */ } /* */ else { /* 82 */ parameters = RuncardRule.eCancelRunCardParameters(ercForm, "Before", ""); /* */ } /* */ /* 85 */ result = this.ercService.cancelRuncard(mbxKey, "eCancelRunCard", parameters); /* */ /* 87 */ String succ = (String)result.get("Result"); /* 88 */ if ((result == null) || (!"0".equalsIgnoreCase(succ))) { /* 89 */ addActionError("MES Return Error " + (String)result.get("ErrorDesc")); /* */ /* 91 */ this.message = "Rescind runcard failure!"; /* 92 */ return getReturnValue("input", this.returnto); /* */ } /* */ /* 96 */ if (null == ercForm.getWorkflowId()) /* 97 */ addProcessLog(ercForm); /* */ else { /* 99 */ this.ercService.withdrawRuncardByMode(ercForm, "admin"); /* */ } /* 101 */ this.message = "Rescind runcard successful!"; /* */ /* 104 */ if (this.strIntegrationService != null) this.strIntegrationService.cancelRunCard(ercForm.getId()); /* */ /* 106 */ return getReturnValue("success", this.returnto); /* */ } /* */ /* */ private String getReturnValue(String returnValue1, String returnValue2) { /* 110 */ if ("view".equals(returnValue2)) { /* 111 */ return returnValue2; /* */ } /* */ /* 114 */ return returnValue1; /* */ } /* */ /* */ private void addProcessLog(ErcMastForm requestForm) { /* 118 */ IProcessLog changeLog = requestForm.createProcessLog(); /* 119 */ changeLog.setActionName("Rescind RunCard"); /* 120 */ changeLog.setRemark("Admin/Applicant had changed the runcard's status"); /* 121 */ changeLog.setStatus(requestForm.getStatus()); /* 122 */ changeLog.setCaller(getUserLogin().getUserLoginId()); /* 123 */ changeLog.setOwner(getUserLogin().getUserLoginId()); /* 124 */ changeLog.setFromDate(requestForm.getCreated()); /* 125 */ changeLog.setThruDate(new Date()); /* 126 */ requestForm.setStatus("Withdrew"); /* 127 */ requestForm.setWorkflowFinishDate(new Date()); /* 128 */ requestForm.addProcessLog(changeLog); /* 129 */ this.ercService.updateRequestForm(requestForm); /* */ } /* */ /* */ public String getCaseNo() { /* 133 */ return this.caseNo; /* */ } /* */ /* */ public void setCaseNo(String caseNo) { /* 137 */ this.caseNo = caseNo; /* */ } /* */ /* */ public String getMessage() { /* 141 */ return this.message; /* */ } /* */ /* */ public void setMessage(String message) { /* 145 */ this.message = message; /* */ } /* */ public String getReturnto() { /* 148 */ return this.returnto; /* */ } /* */ public void setReturnto(String returnto) { /* 151 */ this.returnto = returnto; /* */ } /* */ public Long getErcFormId() { /* 154 */ return this.ercFormId; /* */ } /* */ public void setErcFormId(Long ercFormId) { /* 157 */ this.ercFormId = ercFormId; /* */ } /* */ } /* Location: C:\Users\JE03789\Documents\erc.zip * Qualified Name: erc.WEB-INF.classes.com.smics.apps.erc.action.admin.CancelRuncardByType * JD-Core Version: 0.6.0 */
最新发布
08-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值