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

📄 proxymethodinvocation.java

📁 Java/J2EE框架Jdon-Framework系统的Sample
💻 JAVA
字号:
/**
 * Copyright 2005 Jdon.com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */

package com.jdon.aop.joinpoint;

import com.jdon.aop.interceptor.MethodInterceptor;
import com.jdon.bussinessproxy.TargetMetaDef;
import com.jdon.bussinessproxy.MethodInvoker;
import org.aopalliance.intercept.MethodInvocation;
import java.lang.reflect.Method;
import java.lang.reflect.AccessibleObject;
import java.util.Collection;
import java.util.Iterator;

import com.jdon.util.Debug;
import com.jdon.bussinessproxy.meta.MethodMetaArgs;
import com.jdon.bussinessproxy.cache.ComponentCacheVisitor;


/**
 * 使用动态代理实现拦截器调用
 * 调用拦截器链中的下一个拦截器。
 *
 * 使用ComponentManager(HttpSession)作为本实例的缓冲
 * 因为本实例保存有状态currentInterceptor,适合每个用户一个缓存。
 *
 * ComponentManager还缓存了EJBObject,见EJBMethodInvoker.java

 *
 * @author banq
 * @version 1.0
 */
public class ProxyMethodInvocation implements MethodInvocation,
    java.io.Serializable {

  private final static String module = ProxyMethodInvocation.class.getName();
  protected ComponentCacheVisitor cmcv;
  protected TargetMetaDef targetMetaDef;
  protected Object[] arguments;
  protected Collection interceptors;
  protected MethodInvoker methodInvoker;

  protected Iterator currentInterceptor;

  public ProxyMethodInvocation(ComponentCacheVisitor cmcv,
                               MethodInvoker methodInvoker,
                               Collection interceptors, TargetMetaDef targetMetaDef) {
    this.cmcv = cmcv;
    this.targetMetaDef = targetMetaDef;
    this.methodInvoker = methodInvoker;
    this.interceptors = interceptors;
    this.currentInterceptor = interceptors.iterator();
  }

  /**
   * 重新设置当前指针到开始;
   */
  public void resetIterator() {
    this.currentInterceptor = interceptors.iterator();
  }

  /**
   * Invokes next interceptor/proxy target.
   * now there is no mixin
   */
  public Object proceed() throws Throwable {
    Debug.logVerbose(" enter ProxyMethodInvocation proceed()", module);
    Object result = null;
    if (currentInterceptor.hasNext()) {
      MethodInterceptor methodInterceptor = (MethodInterceptor)
          currentInterceptor.next();
      Debug.logVerbose(" now call inteceptor : " +
                       methodInterceptor.getClass().getName(), module);
      return methodInterceptor.invoke(this);
    }else{
      Debug.logVerbose(" finish call all inteceptors", module);
      methodInvoker.setVisitor(cmcv);
      Debug.logVerbose(" begin to call the target by methodInvoker", module);
      return methodInvoker.handleInvoker(targetMetaDef);
    }
  }



  public Object getThis() {
    return this;
  }

  public AccessibleObject getStaticPart() {
    return null;
  }

  public Method getMethod() {
    MethodMetaArgs  methodMetaArgs = this.targetMetaDef.getMethodMetaArgs();
    return methodMetaArgs.getMethod();
  }

  public TargetMetaDef getTargetMetaDef() {
    return targetMetaDef;
  }

  public void setTargetMetaDef(TargetMetaDef targetMetaDef) {
    this.targetMetaDef = targetMetaDef;
  }

  public Object[] getArguments() {
    return arguments;
  }

  public void setArguments(Object[] arguments) {
    this.arguments = arguments;
  }

}

⌨️ 快捷键说明

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