/[classpath]/classpath/java/io/ObjectStreamClass.java
ViewVC logotype

Diff of /classpath/java/io/ObjectStreamClass.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by mark, Tue Jan 22 22:26:59 2002 UTC revision 1.18 by cbj, Mon Mar 25 05:12:18 2002 UTC
# Line 44  import java.lang.reflect.Field; Line 44  import java.lang.reflect.Field;
44  import java.lang.reflect.Member;  import java.lang.reflect.Member;
45  import java.lang.reflect.Method;  import java.lang.reflect.Method;
46  import java.lang.reflect.Modifier;  import java.lang.reflect.Modifier;
47    import java.lang.reflect.Proxy;
48  import java.security.DigestOutputStream;  import java.security.DigestOutputStream;
49  import java.security.MessageDigest;  import java.security.MessageDigest;
50  import java.security.NoSuchAlgorithmException;  import java.security.NoSuchAlgorithmException;
# Line 74  public class ObjectStreamClass implement Line 75  public class ObjectStreamClass implement
75      if (! (Serializable.class).isAssignableFrom (cl))      if (! (Serializable.class).isAssignableFrom (cl))
76        return null;        return null;
77    
78        return lookupForClassObject (cl);
79      }
80    
81      /**
82       * This lookup for internal use by ObjectOutputStream.  Suppose
83       * we have a java.lang.Class object C for class A, though A is not
84       * serializable, but it's okay to serialize C.
85       */
86      static ObjectStreamClass lookupForClassObject (Class cl)
87      {
88        if (cl == null)
89          return null;
90    
91      ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl);      ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl);
92    
93      if (osc != null)      if (osc != null)
# Line 246  public class ObjectStreamClass implement Line 260  public class ObjectStreamClass implement
260    }    }
261    
262    
263      final boolean isProxyClass()
264      {
265        return _isProxyClass;
266      }
267    
268    
269    ObjectStreamClass (String name, long uid, byte flags,    ObjectStreamClass (String name, long uid, byte flags,
270                       ObjectStreamField[] fields)                       ObjectStreamField[] fields)
271    {    {
# Line 258  public class ObjectStreamClass implement Line 278  public class ObjectStreamClass implement
278    
279    void setClass (Class clazz)    void setClass (Class clazz)
280    {    {
281        _isProxyClass = Proxy.isProxyClass(clazz);
282      this.clazz = clazz;      this.clazz = clazz;
283        ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (clazz);
284        if (osc == null)
285          classLookupTable.put (clazz, this);
286        superClass = lookupForClassObject (clazz.getSuperclass ());
287        calculateOffsets ();
288    }    }
289    
290    
# Line 312  public class ObjectStreamClass implement Line 338  public class ObjectStreamClass implement
338    {    {
339      uid = 0;      uid = 0;
340      flags = 0;      flags = 0;
341        _isProxyClass = Proxy.isProxyClass (cl);
342    
343      clazz = cl;      clazz = cl;
344      name = cl.getName ();      name = cl.getName ();
345      setFlags (cl);      setFlags (cl);
346      setFields (cl);      setFields (cl);
347      setUID (cl);      // to those class nonserializable, its uid field is 0
348        if ( (Serializable.class).isAssignableFrom (cl) )
349          setUID (cl);
350      superClass = lookup (cl.getSuperclass ());      superClass = lookup (cl.getSuperclass ());
351    }    }
352    
# Line 397  public class ObjectStreamClass implement Line 426  public class ObjectStreamClass implement
426        if (all_fields[from] != null)        if (all_fields[from] != null)
427        {        {
428          Field f = all_fields[from];          Field f = all_fields[from];
429          fields[to] = new ObjectStreamField (f.getName (), f.getType ());          String name = f.getName();
430            // here is a hack to interoperate with JDK
431            /* if Throwable is not align with serialized form of Java API spec,
432               you should uncomment the following two line.
433               if (name.equals("message") && getName().equals("java.lang.Throwable"))
434               name = "detailMessage";
435            */
436            fields[to] = new ObjectStreamField (name, f.getType ());
437          to++;          to++;
438        }        }
439    
# Line 602  public class ObjectStreamClass implement Line 638  public class ObjectStreamClass implement
638    
639      try      try
640        {        {
641            /*
642             * There exists a problem here, JDK run of
643             * clazz.getDeclaredMethod ("<clinit>", classArgs);
644             * will always throw NoSuchMethodException, even the static
645             * intializer does exist.
646             */
647          Class classArgs[] = {};          Class classArgs[] = {};
648          m = clazz.getDeclaredMethod ("<clinit>", classArgs);          m = clazz.getDeclaredMethod ("<clinit>", classArgs);
649        }        }
# Line 635  public class ObjectStreamClass implement Line 677  public class ObjectStreamClass implement
677    // these are accessed by ObjectIn/OutputStream    // these are accessed by ObjectIn/OutputStream
678    int primFieldSize = -1;  // -1 if not yet calculated    int primFieldSize = -1;  // -1 if not yet calculated
679    int objectFieldCount;    int objectFieldCount;
680    
681      boolean _isProxyClass = false;
682    
683    // This is probably not necessary because this class is special cased already    // This is probably not necessary because this class is special cased already
684    // but it will avoid showing up as a discrepancy when comparing SUIDs.    // but it will avoid showing up as a discrepancy when comparing SUIDs.
685    private static final long serialVersionUID = -6120832682080437368L;    private static final long serialVersionUID = -6120832682080437368L;

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26