KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > proxy > SerializableProxy


1 //$Id: SerializableProxy.java,v 1.5 2005/02/12 07:19:45 steveebersole Exp $
2
package org.hibernate.proxy;
3
4 import java.io.Serializable JavaDoc;
5 import java.lang.reflect.Method JavaDoc;
6
7 import org.hibernate.HibernateException;
8 import org.hibernate.type.AbstractComponentType;
9
10 /**
11  * Serializable placeholder for <tt>CGLIB</tt> proxies
12  */

13 public final class SerializableProxy implements Serializable JavaDoc {
14
15     private String JavaDoc entityName;
16     private Class JavaDoc persistentClass;
17     private Class JavaDoc[] interfaces;
18     private Serializable JavaDoc id;
19     private Class JavaDoc getIdentifierMethodClass;
20     private Class JavaDoc setIdentifierMethodClass;
21     private String JavaDoc getIdentifierMethodName;
22     private String JavaDoc setIdentifierMethodName;
23     private Class JavaDoc[] setIdentifierMethodParams;
24     private AbstractComponentType componentIdType;
25
26     public SerializableProxy() {}
27
28     public SerializableProxy(
29         final String JavaDoc entityName,
30         final Class JavaDoc persistentClass,
31         final Class JavaDoc[] interfaces,
32         final Serializable JavaDoc id,
33         final Method JavaDoc getIdentifierMethod,
34         final Method JavaDoc setIdentifierMethod,
35         AbstractComponentType componentIdType
36     ) {
37         this.entityName = entityName;
38         this.persistentClass = persistentClass;
39         this.interfaces = interfaces;
40         this.id = id;
41         if (getIdentifierMethod!=null) {
42             getIdentifierMethodClass = getIdentifierMethod.getDeclaringClass();
43             getIdentifierMethodName = getIdentifierMethod.getName();
44         }
45         if (setIdentifierMethod!=null) {
46             setIdentifierMethodClass = setIdentifierMethod.getDeclaringClass();
47             setIdentifierMethodName = setIdentifierMethod.getName();
48             setIdentifierMethodParams = setIdentifierMethod.getParameterTypes();
49         }
50         this.componentIdType = componentIdType;
51     }
52
53     private Object JavaDoc readResolve() {
54         try {
55             return CGLIBLazyInitializer.getProxy(
56                 entityName,
57                 persistentClass,
58                 interfaces,
59                 getIdentifierMethodName==null ?
60                     null :
61                     getIdentifierMethodClass.getDeclaredMethod(getIdentifierMethodName, null),
62                 setIdentifierMethodName==null ?
63                     null :
64                     setIdentifierMethodClass.getDeclaredMethod(setIdentifierMethodName, setIdentifierMethodParams),
65                     componentIdType,
66                 id,
67                 null
68             );
69         }
70         catch (NoSuchMethodException JavaDoc nsme) {
71             throw new HibernateException("could not create proxy for entity: " + entityName, nsme);
72         }
73     }
74
75 }
76
Popular Tags