• ActionProxy相关实现类


    package com.opensymphony.xwork2;
    
    import com.opensymphony.xwork2.config.Configuration;
    import com.opensymphony.xwork2.config.ConfigurationException;
    import com.opensymphony.xwork2.config.RuntimeConfiguration;
    import com.opensymphony.xwork2.config.entities.ActionConfig;
    import com.opensymphony.xwork2.inject.Inject;
    import com.opensymphony.xwork2.util.LocalizedTextUtil;
    import com.opensymphony.xwork2.util.logging.Logger;
    import com.opensymphony.xwork2.util.logging.LoggerFactory;
    import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
    import java.io.Serializable;
    import java.util.Locale;
    import org.apache.commons.lang3.StringEscapeUtils;
    import org.apache.commons.lang3.StringUtils;
    
    public class DefaultActionProxy
      implements ActionProxy, Serializable
    {
      private static final long serialVersionUID = 3293074152487468527L;
      private static final Logger LOG = LoggerFactory.getLogger(DefaultActionProxy.class);
      protected Configuration configuration;
      protected ActionConfig config;
      protected ActionInvocation invocation;
      protected UnknownHandlerManager unknownHandlerManager;
      protected String actionName;
      protected String namespace;
      protected String method;
      protected boolean executeResult;
      protected boolean cleanupContext;
      protected ObjectFactory objectFactory;
      protected ActionEventListener actionEventListener;
      private boolean methodSpecified = true;
    
      protected DefaultActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext)
      {
        this.invocation = inv;
        this.cleanupContext = cleanupContext;
        if (LOG.isDebugEnabled()) {
          LOG.debug("Creating an DefaultActionProxy for namespace [#0] and action name [#1]", new String[] { namespace, actionName });
        }
    
        this.actionName = StringEscapeUtils.escapeHtml4(actionName);
        this.namespace = namespace;
        this.executeResult = executeResult;
        this.method = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(methodName));
      }
    
      @Inject
      public void setObjectFactory(ObjectFactory factory) {
        this.objectFactory = factory;
      }
    
      @Inject
      public void setConfiguration(Configuration config) {
        this.configuration = config;
      }
    
      @Inject
      public void setUnknownHandler(UnknownHandlerManager unknownHandlerManager) {
        this.unknownHandlerManager = unknownHandlerManager;
      }
    
      @Inject(required=false)
      public void setActionEventListener(ActionEventListener listener) {
        this.actionEventListener = listener;
      }
    
      public Object getAction() {
        return this.invocation.getAction();
      }
    
      public String getActionName() {
        return this.actionName;
      }
    
      public ActionConfig getConfig() {
        return this.config;
      }
    
      public void setExecuteResult(boolean executeResult) {
        this.executeResult = executeResult;
      }
    
      public boolean getExecuteResult() {
        return this.executeResult;
      }
    
      public ActionInvocation getInvocation() {
        return this.invocation;
      }
    
      public String getNamespace() {
        return this.namespace;
      }
    
      public String execute() throws Exception {
        ActionContext nestedContext = ActionContext.getContext();
        ActionContext.setContext(this.invocation.getInvocationContext());
    
        String retCode = null;
    
        String profileKey = "execute: ";
        try {
          UtilTimerStack.push(profileKey);
    
          retCode = this.invocation.invoke();
        } finally {
          if (this.cleanupContext) {
            ActionContext.setContext(nestedContext);
          }
          UtilTimerStack.pop(profileKey);
        }
    
        return retCode;
      }
    
      public String getMethod()
      {
        return this.method;
      }
    
      private void resolveMethod()
      {
        if (StringUtils.isEmpty(this.method)) {
          this.method = this.config.getMethodName();
          if (StringUtils.isEmpty(this.method)) {
            this.method = "execute";
          }
          this.methodSpecified = false;
        }
      }
    
      protected void prepare() {
        String profileKey = "create DefaultActionProxy: ";
        try {
          UtilTimerStack.push(profileKey);
          this.config = this.configuration.getRuntimeConfiguration().getActionConfig(this.namespace, this.actionName);
    
          if ((this.config == null) && (this.unknownHandlerManager.hasUnknownHandlers())) {
            this.config = this.unknownHandlerManager.handleUnknownAction(this.namespace, this.actionName);
          }
          if (this.config == null) {
            throw new ConfigurationException(getErrorMessage());
          }
    
          resolveMethod();
    
          if (!this.config.isAllowedMethod(this.method)) {
            throw new ConfigurationException("Invalid method: " + this.method + " for action " + this.actionName);
          }
    
          this.invocation.init(this);
        }
        finally {
          UtilTimerStack.pop(profileKey);
        }
      }
    
      protected String getErrorMessage() {
        if ((this.namespace != null) && (this.namespace.trim().length() > 0)) {
          return LocalizedTextUtil.findDefaultText("xwork.exception.missing-package-action", Locale.getDefault(), new String[] { this.namespace, this.actionName });
        }
    
        return LocalizedTextUtil.findDefaultText("xwork.exception.missing-action", Locale.getDefault(), new String[] { this.actionName });
      }
    
      public boolean isMethodSpecified()
      {
        return this.methodSpecified;
      }
    }

    ******************************************分割线**********************************

    package org.apache.struts2.impl;
    
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.DefaultActionProxy;
    import com.opensymphony.xwork2.util.LocalizedTextUtil;
    import java.util.Locale;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts2.ServletActionContext;
    
    public class StrutsActionProxy extends DefaultActionProxy
    {
      private static final long serialVersionUID = -2434901249671934080L;
    
      public StrutsActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext)
      {
        super(inv, namespace, actionName, methodName, executeResult, cleanupContext);
      }
    
      public String execute() throws Exception {
        ActionContext previous = ActionContext.getContext();
        ActionContext.setContext(this.invocation.getInvocationContext());
        try
        {
          return this.invocation.invoke();
        } finally {
          if (this.cleanupContext)
            ActionContext.setContext(previous);
        }
      }
    
      protected void prepare()
      {
        super.prepare();
      }
    
      protected String getErrorMessage()
      {
        if ((this.namespace != null) && (this.namespace.trim().length() > 0)) {
          String contextPath = ServletActionContext.getRequest().getContextPath();
          return LocalizedTextUtil.findDefaultText("struts.exception.missing-package-action.with-context", Locale.getDefault(), new String[] { this.namespace, this.actionName, contextPath });
        }
    
        return super.getErrorMessage();
      }
    }
  • 相关阅读:
    ethtool 命令输出的注意点--网卡参数
    centos7.2+zabbix3.2+sedmail邮件告警
    vscode monokai
    SQL SERVER 常用命令
    数据库问题6-將系統資料表對應至系統檢視
    数据库问题5-SYS.SYSPROCESSES使用和查找死锁
    select * from sys.sysprocesses
    【SQL Server学习笔记】事务、锁定、阻塞、死锁 sys.sysprocesses
    使用DMV调优性能 --Burgess_Liu
    sql server线程等待信息
  • 原文地址:https://www.cnblogs.com/shaohz2014/p/3697401.html
Copyright © 2020-2023  润新知