zoukankan      html  css  js  c++  java
  • 深入struts2.0(七)--ActionInvocation接口以及3DefaultActionInvocation类

    1.1.1       ActionInvocation类

    ActionInvocation定义为一个接口。主要作用是表现action的运行状态。它拥有拦截器和action的实例。通过重复的运行invoke方法。首先被actionProxy,然后是拦截器,全部拦截器运行完后就是action和result .

    图3.3.4 ActionInvocation类的主要方法

    1.1.2       DefaultActionInvocation类

    DefaultActionInvocation类是ActionInvocation接口的实现类. 一般都用该类实例化ActionInvocation。 基本的方法例如以下:

     

    图3.3.5 DefaultActionInvocation类的主要方法

    关键方法:invoke()方法

    executed = false; 默觉得false。表示该action还没有运行。

    假设运行就会抛出已经运行的异常。

    然后推断拦截器是否已经配置,假设配置了拦截器就会从配置信息中获得拦截器配置类InterceptorMapping。

    此类中仅仅包括两个属性,一个就是name和interceptor实例。

    public String invoke() throws Exception {

            String profileKey = "invoke: ";

            try {

                UtilTimerStack.push(profileKey);

                if (executed) {

                    throw new IllegalStateException("Action has already executed");

                }

                //递归运行interceptor

                if (interceptors.hasNext())

    {          //interceptorsInterceptorMapping实际上是像一个像//FilterChain一样的Interceptor    

                //通过调用Invocation.invoke()实现递归牡循环 

                    final InterceptorMapping interceptor = interceptors.next();

                    String interceptorMsg = "interceptor: " + interceptor.getName();

                    UtilTimerStack.push(interceptorMsg);

                    try {

    //在每一个Interceptor的方法中都会return invocation.invoke()                               

      resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this);

                                }

                    finally {

                        UtilTimerStack.pop(interceptorMsg);

                    }

                } else {

    //当全部interceptor都运行完,最后运行Action,invokeActionOnly会调用//invokeAction()方法

                    resultCode = invokeActionOnly();

                }

     

      // this is needed because the result will be executed, then control will return to the Interceptor, which will

                // return above and flow through again

       //Result返回之前调用preResultListeners     

            //通过executed控制,仅仅运行一次 

                if (!executed) {

                    if (preResultListeners != null) {

                        for (Object preResultListener : preResultListeners) {

                            PreResultListener listener = (PreResultListener) preResultListener;

                            String _profileKey = "preResultListener: ";

                            try {

                                UtilTimerStack.push(_profileKey);

                                listener.beforeResult(this, resultCode);

                            }

                            finally {

                                UtilTimerStack.pop(_profileKey);

                            }

                        }

                    }

                    // now execute the result, if we're supposed to

    //运行result

                    if (proxy.getExecuteResult()) {

                        executeResult();

                    }

                    executed = true;

                }

                return resultCode;

            }

            finally {

                UtilTimerStack.pop(profileKey);

            }

        }

     


      

  • 相关阅读:
    Flex实现页面多态state对象
    Flex精华摘要使用AS脚本
    JMeter最常用的三种类型的压力测试
    工作流简介
    Android模拟器使用模拟SD卡
    交大研究生,就一个字牛
    Google code上利用SVN托管代码
    主流浏览器内核概览
    Android开发之ADB使用
    Redis入门教程
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6842653.html
Copyright © 2011-2022 走看看