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

📄 logproxy.java

📁 精通RMI 这是RMI的入门基础 特别对刚开始学RMI的同胞们很有帮助
💻 JAVA
字号:
/*
 * Copyright 1999 by dreamBean Software,
 * All rights reserved.
 */
package smartproxy.proxies;

import java.lang.reflect.Method;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 *    This is a smart proxy wrapper that logs calls
 *     
 *    Note that it is not tightly bound to the remote object interface,
 *    and can therefore be reused with any remote object(!)
 *
 *   @author Rickard 謆erg (rickard@dreambean.com)
 *   @version $Revision:$
 */
public class LogProxy
   implements InvocationHandler, java.io.Serializable, LinkedProxy
{
   Object next;

   // Constructors --------------------------------------------------
   public LogProxy(Object next)
   {
      this.next = next;
   }
   
   // Public --------------------------------------------------------
   public Object invoke(Object proxy,
                        Method method,
                        Object[] args)
      throws Throwable
   {
      // Log call
      String log = method.getDeclaringClass().getName()+"."+method.getName()+"(";
      for (int i = 0; i < args.length; i++)
      {
         log += (i>0?",":"")+args[i].toString();
      }
      log += ")";
      System.out.println(log);
      
      try
      {
         return method.invoke(next, args);
      } catch (InvocationTargetException e)
      {
         throw e.getTargetException();
      }
   }
   
   public Object getNext()
   {
      return next;
   }
   
   public void setNext(Object next)
   {
      this.next = next;
   }
}

⌨️ 快捷键说明

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