dynamic初步
来源:互联网 发布:淘宝小叶紫檀树苗真假 编辑:程序博客网 时间:2024/05/17 04:04
1.BusinessInterface.java
package dynamic;
public interface BusinessInterface {
public void processBusiness();
}
2.BusinessImpl.java
package dynamic;
public class BusinessImpl implements BusinessInterface{
public void processBusiness(){
System.out.println("here is business logic");
}
}
3.LogHandler.java
package dynamic;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.logging.Logger;
public class LogHandler implements InvocationHandler {
private Logger logger = Logger.getLogger(this.getClass().getName());
private Object delegate;
public LogHandler(Object delegate){
this.delegate = delegate;
}
public Object invoke(Object arg0, Method method, Object[] args)
throws Throwable {
Object o = null;
try {
logger.info("method stats..." + method);
o = method.invoke(delegate,args);
logger.info("method ends..." + method);
} catch (Exception e){
logger.info("Exception happends...");
//excetpion handling.
}
return o;
}
}
4.Client.java
package dynamic;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
public class Client {
/**
* @param args
* @throws NoSuchMethodException
* @throws SecurityException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws IllegalArgumentException
*/
public static void main(String[] args) throws SecurityException,
NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
// TODO Auto-generated method stub
BusinessInterface businessImp = new BusinessImpl();
InvocationHandler handler = new LogHandler(businessImp);
BusinessInterface proxy = (BusinessInterface) Proxy.newProxyInstance(
businessImp.getClass().getClassLoader(),
businessImp.getClass().getInterfaces(),
handler);
proxy.processBusiness();
//businessImp.processBusiness();
}
}
- dynamic初步
- 动态规划(dynamic programming)初步入门
- 动态规划(dynamic programming)初步入门
- dynamic
- @dynamic
- Dynamic
- @dynamic
- dynamic
- dynamic
- dynamic
- @dynamic
- @dynamic
- 静态连接(dynamic link)和动态连接(static link)初步理解
- 初步
- dynamic-insert,dynamic-update
- dynamic programming
- Dynamic MBean
- Dynamic Menu
- uncaught exception: Access to restricted URI denied (NS_ERROR_DOM_BAD_URI)
- Apache自带网站压力测试工具ab
- Lesson 01 A private conversation 私人谈话
- 集合类碎碎念
- css的position-relative兼容问题与解决办法
- dynamic初步
- Jbpm 4 撤回 、强制完成
- C#中IList与List区别
- 字符编码ASCII、Unicode、UTF-8、iso8859-1、GBK、GB2312
- 体绘制(Volume Rendering)概述之2:体数据详解
- php调用存储过程返回结果集,解决can't return a result set in the given context错误的方法
- wget参数及用法
- MFC注册表操作详解
- Asp常用通用函数之生成时间的整数