serializableproxy.java

来自「用Java实现的23个常用设计模式源代码」· Java 代码 · 共 74 行

JAVA
74
字号
//$Id: SerializableProxy.java,v 1.9.2.1 2003/09/11 06:25:08 oneovthafew Exp $package net.sf.hibernate.proxy;import java.io.Serializable;import java.lang.reflect.Method;import net.sf.hibernate.LazyInitializationException;import org.apache.commons.logging.LogFactory;/** * Serializable placeholder for <tt>CGLIB</tt> proxies */public final class SerializableProxy implements Serializable {		private Class persistentClass;	private Class[] interfaces;	private Serializable id;	private Class getIdentifierMethodClass;	private Class setIdentifierMethodClass;	private String getIdentifierMethodName;	private String setIdentifierMethodName;	private Class[] setIdentifierMethodParams;		public SerializableProxy() {}		public SerializableProxy(Class persistentClass, Class[] interfaces, Serializable id, Method getIdentifierMethod, Method setIdentifierMethod) {		this.persistentClass = persistentClass;		this.interfaces = interfaces;		this.id = id;		if (getIdentifierMethod!=null) {			getIdentifierMethodClass = getIdentifierMethod.getDeclaringClass();			getIdentifierMethodName = getIdentifierMethod.getName();		}		if (setIdentifierMethod!=null) {			setIdentifierMethodClass = setIdentifierMethod.getDeclaringClass();			setIdentifierMethodName = setIdentifierMethod.getName();			setIdentifierMethodParams = setIdentifierMethod.getParameterTypes();		}	}	private Object readResolve() {		try {			 Object proxy = CGLIBLazyInitializer.getProxy(				persistentClass,				interfaces,				(getIdentifierMethodName==null) ? 					null : 					getIdentifierMethodClass.getDeclaredMethod(getIdentifierMethodName, null),				(setIdentifierMethodName==null) ? 					null : 					setIdentifierMethodClass.getDeclaredMethod(setIdentifierMethodName, setIdentifierMethodParams),				id,				null			);			//LazyInitializer li = HibernateProxyHelper.getLazyInitializer( (HibernateProxy) proxy );			//li.setTarget(target);			//li.setSnapshot(snapshot);			return proxy;		}		catch (Exception e) {			LogFactory.getLog(CGLIBLazyInitializer.class).error("Exception deserializing proxy", e);			throw new LazyInitializationException("could not deserialize a proxy", e);		}	}}

⌨️ 快捷键说明

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