?? myproxyfactory.java
字號:
package com.easyjf.aop;
import java.lang.reflect.Proxy;
/**
* 測試
* @author stef_wu
*
*/
public class MyProxyFactory {
public static Object getProxyObject(String className, String[] interceptors)
throws Exception {
Object inputObject = getTargetObject(className);
if (interceptors != null && interceptors.length > 0) {
Object inputProxiedObject = inputObject;
for (int i = 0; i < interceptors.length; i++) {
inputProxiedObject = getProxyObject(inputObject,
interceptors[i], inputProxiedObject);
}
return inputProxiedObject;
} else {
return inputObject;
}
}
private static Object getProxyObject(Object inObject, String interceptor,
Object inProxiedObject) throws Exception {
GenericInvocationHandler invocationHandler = new GenericInvocationHandler();
IMethodInterceptor interceptorObject = (IMethodInterceptor) getInterceptor(interceptor);
if (interceptor == null) {
return inProxiedObject;
}
invocationHandler.setTarget(inProxiedObject);
invocationHandler.setRealTarget(inObject);
invocationHandler.setMethodInterceptor(interceptorObject);
return Proxy.newProxyInstance(inObject.getClass().getClassLoader(),
inObject.getClass().getInterfaces(), invocationHandler);
}
private static Object getInterceptor(String interceptors) throws Exception {
return Class.forName(interceptors).newInstance();
}
private static Object getTargetObject(String className) throws Exception {
return Class.forName(className).newInstance();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -