📄 proxyobjectfactory.java
字号:
package com.opensymphony.xwork2;import java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;import java.lang.reflect.Proxy;import java.util.Map;/** * ObjectFactory that returns a FooProxy in the buildBean if the clazz is FooAction */public class ProxyObjectFactory extends ObjectFactory { /** * It returns an instance of the bean except if the class is FooAction. * In this case, it returns a FooProxy of it. */ public Object buildBean(Class clazz, Map extraContext) throws Exception { Object bean = super.buildBean(clazz, extraContext); if(clazz.equals(ProxyInvocationAction.class)) { return Proxy.newProxyInstance(bean.getClass() .getClassLoader(), bean.getClass().getInterfaces(), new ProxyInvocationProxy(bean)); } return bean; } /** * Simple proxy that just invokes the method on the target on the invoke method */ public class ProxyInvocationProxy implements InvocationHandler { private Object target; public ProxyInvocationProxy(Object target) { this.target = target; } public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { return m.invoke(target, args); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -