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

📄 proxyobjectfactory.java

📁 在Struts2中的jar包xwork的源代码.版本为2.0.7
💻 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 + -