org.metasyntactic.io
Class ClassDescriptor

java.lang.Object
  |
  +--org.metasyntactic.io.ClassDescriptor

public class ClassDescriptor
extends java.lang.Object

XMLSerializer's descriptor for classes. It contains the name and serialVersionUID of the class. The ClassDescriptor for a specific class loaded in this Java VM can be found/created using the lookup method.

Comments for fields and methods will often refer to 'clazz'. 'clazz' is the class that the current ClassDescriptor is a descriptor for.


Field Summary
protected static java.util.Map classToDescriptor
          Cache of classes to their descriptors.
protected  java.lang.Class clazz
          Class that this is a descriptor for
protected  java.lang.reflect.Field[] fields
          Cached non-static and non-transient fields of clazz.
protected  boolean includeEverything
           
protected  java.lang.reflect.Method readResolveMethod
          Cached pointer to clazz's readResolve method (if clazz has such a method).
protected  boolean serializable
          True if and only if clazz is serializable, or inherits from a serializable class
protected  long suid
          Cached serial version UID for clazz
protected  ClassDescriptor superclassDescriptor
          Class descriptor for clazz's superclass
protected  java.lang.reflect.Method writeReplaceMethod
          Cached pointer to clazz's writeReplace method (if clazz has such a method).
 
Constructor Summary
protected ClassDescriptor(java.lang.Class clazz, ClassDescriptor superclassDescriptor, boolean serializable, boolean includeEverything)
          Creates a new Class Descriptor with all (non-cached) fields filled in.
 
Method Summary
 java.lang.Class forClass()
          Returns the class that this is a descriptor for
 java.lang.String getClassName()
          Returns clazz's class name
 java.lang.reflect.Field[] getFields()
          Returns all the non-static non-transient fields of clazz.
 long getSerialVersionUID()
          Returns clazz's serial version UID
 ClassDescriptor getSuperclassDescriptor()
          Returns the class descriptor for clazz's superclass.
protected  void init()
          Initializes thi class descriptor.
static ClassDescriptor lookup(java.lang.Class cl)
          Returns a ClassDescriptor for cl if cl is serializable, otherwise null.
static ClassDescriptor lookup(java.lang.Class cl, boolean includeEverything)
           
protected static ClassDescriptor lookupInternal(java.lang.Class cl, boolean includeEverything)
          Finds the actual class descriptor for cl.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classToDescriptor

protected static java.util.Map classToDescriptor
Cache of classes to their descriptors. This map is not synchronized so all accessing methods must synchronize on it.


clazz

protected java.lang.Class clazz
Class that this is a descriptor for


fields

protected java.lang.reflect.Field[] fields
Cached non-static and non-transient fields of clazz.


superclassDescriptor

protected ClassDescriptor superclassDescriptor
Class descriptor for clazz's superclass


serializable

protected boolean serializable
True if and only if clazz is serializable, or inherits from a serializable class


suid

protected long suid
Cached serial version UID for clazz

See Also:
org.metasyntactic.util.StreamUniqueIdentifier#compute(java.lang.Class)

writeReplaceMethod

protected java.lang.reflect.Method writeReplaceMethod
Cached pointer to clazz's writeReplace method (if clazz has such a method). Otherwise, this is null.


readResolveMethod

protected java.lang.reflect.Method readResolveMethod
Cached pointer to clazz's readResolve method (if clazz has such a method). Otherwise, this is null.


includeEverything

protected boolean includeEverything
Constructor Detail

ClassDescriptor

protected ClassDescriptor(java.lang.Class clazz,
                          ClassDescriptor superclassDescriptor,
                          boolean serializable,
                          boolean includeEverything)
Creates a new Class Descriptor with all (non-cached) fields filled in. This should only be called from within lookup or lookupInternal

Parameters:
clazz - The class this is a descriptor for
superclassDescriptor - The descriptor for clazz's superclass
serializable - Whether or not clazz is serialiable
See Also:
lookup(java.lang.Class), #lookupInternal(java.lang.Class)
Method Detail

getClassName

public java.lang.String getClassName()
Returns clazz's class name

Returns:
clazz's class name

getSerialVersionUID

public long getSerialVersionUID()
Returns clazz's serial version UID

Returns:
clazz's serial version UID

getSuperclassDescriptor

public ClassDescriptor getSuperclassDescriptor()
Returns the class descriptor for clazz's superclass.

Returns:
The class descriptor for clazz's superclass

forClass

public java.lang.Class forClass()
Returns the class that this is a descriptor for

Returns:
The class that this is a descriptor for

getFields

public java.lang.reflect.Field[] getFields()
Returns all the non-static non-transient fields of clazz. This may be computationally intensive the first time it is called. But the results are cached, and all subsequent calls return the cached result

Returns:
The non-static non-transient fields of clazz.

lookup

public static ClassDescriptor lookup(java.lang.Class cl)
Returns a ClassDescriptor for cl if cl is serializable, otherwise null. Note! Just how there is only one instance of a class ever in memory, there is only ever one instance of each ClassDescriptor in memory

Parameters:
cl - The class to get a descriptor for.
Returns:
The ClassDescriptor for cl.

lookup

public static ClassDescriptor lookup(java.lang.Class cl,
                                     boolean includeEverything)

lookupInternal

protected static ClassDescriptor lookupInternal(java.lang.Class cl,
                                                boolean includeEverything)
Finds the actual class descriptor for cl. If one does not exist, it is created and then initialized

Parameters:
cl - The class to get the ClassDescriptor for
Returns:
The ClassDescriptor for cl.

init

protected void init()
Initializes thi class descriptor. This method fills in values such as 'fields', 'suid', 'writeReplaceMethod', and 'readResolveMethod'.

See Also:
fields, suid, writeReplaceMethod, readResolveMethod