ActionInvocation,(请求)数据对象

  ActionInvocation 是Xworks 中Action 调度的核心。而对Interceptor 的调度,也正是由ActionInvocation负责。
  ActionInvocation 是一个接口, 而DefaultActionInvocation 则是Webwork 对ActionInvocation的默认实现。



 Interceptor 的调度流程大致如下:

1. ActionInvocation初始化时,根据配置,加载Action相关的所有Interceptor。
private void init() throws Exception ...{
……
List interceptorList
= new
ArrayList(proxy.getConfig().getInterceptors());
interceptors
= interceptorList.iterator();

2. 通过ActionInvocation.invoke方法调用Action实现时,执行Interceptor:
       下面是DefaultActionInvocation中Action调度代码:
public String invoke() throws Exception ...{
    
if (executed)
        
throw new IllegalStateException("Action has already executed");
    
if (interceptors.hasNext()) ...{
         Interceptor interceptor
= (Interceptor) interceptors.next();
         resultCode
= interceptor.intercept(this);
     }
else
         resultCode
= invokeAction(getAction(), proxy.getConfig());
    
if (!executed) ...{
        
if (preResultListeners != null) ...{
         Iterator iterator
= preResultListeners.iterator();
        
while (iterator.hasNext()) ...{
             PreResultListener listener
            
= (PreResultListener) iterator.next();
             listener.beforeResult(
this, resultCode);
         }

         }

        
if (proxy.getExecuteResult())
         executeResult();
         executed
= true;
     }

    
return resultCode;
     }

所有的拦截器都必须实现Interceptor 接口。

      public interface Interceptor {
         void destroy();
         void init();
         String intercept(ActionInvocation invocation) throws Exception;
     }

在Interceptor 实现中,抽象实现AroundInterceptor得到了最广泛的应用(扩展),它增加了预处理(before)和后处理(after)方法的定义。

public abstract class AroundInterceptor implements Interceptor
...{
    
protected Log log = LogFactory.getLog(this.getClass());
    
    
public void destroy() ...{
     }

    
    
public void init() ...{
     }

    
    
public String intercept(ActionInvocation invocation) throws Exception ...{
     String result
= null;
     before(invocation);
     result
= invocation.invoke();
     after(invocation, result);
    
return result;
     }

    
    
protected abstract void after
     (ActionInvocation actioninvocation, String string)
throws Exception;
    
    
protected abstract void before(ActionInvocation actioninvocation)
    
throws Exception;
AroundInterceptor.invoke 方法中,调用了参数invocation的invoke 方法。

最后,结合最常用的ParametersInterceptor,看看Xwork 是如何通过Interceptor,将Webwork传入的Map类型数据结构,转换为Action所需的Java 模型对象。
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值