FileDocCategorySizeDatePackage
ObjectStreamField.javaAPI DocJava SE 5 API6244Fri Aug 26 14:54:28 BST 2005com.sun.corba.se.impl.orbutil

ObjectStreamField

public class ObjectStreamField extends Object implements Comparable
A description of a field in a serializable class. A array of these is used to declare the persistent fields of a class.

Fields Summary
private String
name
private char
type
private Field
field
private String
typeString
private Class
clazz
private String
signature
private long
fieldID
Constructors Summary
ObjectStreamField(String n, Class clazz)
Create a named field with the specified type.

    	name = n;
    	this.clazz = clazz;

	// Compute the typecode for easy switching
	if (clazz.isPrimitive()) {
	    if (clazz == Integer.TYPE) {
		type = 'I";
	    } else if (clazz == Byte.TYPE) {
		type = 'B";
	    } else if (clazz == Long.TYPE) {
		type = 'J";
	    } else if (clazz == Float.TYPE) {
		type = 'F";
	    } else if (clazz == Double.TYPE) {
		type = 'D";
	    } else if (clazz == Short.TYPE) {
		type = 'S";
	    } else if (clazz == Character.TYPE) {
		type = 'C";
	    } else if (clazz == Boolean.TYPE) {
		type = 'Z";
	    }
	} else if (clazz.isArray()) {
	    type = '[";
	    typeString = ObjectStreamClass_1_3_1.getSignature(clazz);
	} else {
	    type = 'L";
	    typeString = ObjectStreamClass_1_3_1.getSignature(clazz);
	}

	if (typeString != null)
	    signature = typeString;
	else
	    signature = String.valueOf(type);

    
ObjectStreamField()

    
ObjectStreamField(Field field)

	this(field.getName(), field.getType());
	this.field = field;
    
ObjectStreamField(String n, char t, Field f, String ts)
Create an ObjectStreamField containing a reflected Field.

	name = n;
	type = t;
	field = f;
	typeString = ts;

	if (typeString != null)
	    signature = typeString;
	else
	    signature = String.valueOf(type);
	
    
Methods Summary
public intcompareTo(java.lang.Object o)
Compare this with another ObjectStreamField. return -1 if this is smaller, 0 if equal, 1 if greater types that are primitives are "smaller" than objects. if equal, the names are compared.

	ObjectStreamField f2 = (ObjectStreamField)o;
	boolean thisprim = (this.typeString == null);
	boolean otherprim = (f2.typeString == null);

	if (thisprim != otherprim) {
	    return (thisprim ? -1 : 1);
	}
	return this.name.compareTo(f2.name);
    
public java.lang.ClassgetClazz()

        return clazz;
    
java.lang.reflect.FieldgetField()

 	return field;
    
public java.lang.StringgetName()
Get the name of this field.

    	return name;
    
public java.lang.StringgetSignature()


	return signature;

    
public java.lang.ClassgetType()
Get the type of the field.

    	if (clazz != null)
    	    return clazz;
	switch (type) {
	case 'B": clazz = Byte.TYPE;
	    break;
	case 'C": clazz = Character.TYPE;
	    break;
	case 'S": clazz = Short.TYPE;
	    break;
	case 'I": clazz = Integer.TYPE;
	    break;
	case 'J": clazz = Long.TYPE;
	    break;
	case 'F": clazz = Float.TYPE;
	    break;
	case 'D": clazz = Double.TYPE;
	    break;
	case 'Z": clazz = Boolean.TYPE;
	    break;
	case '[":
	case 'L":
	    clazz = Object.class;
	    break;
	}

    	return clazz;
    
public chargetTypeCode()

	return type;
    
public java.lang.StringgetTypeString()

	return typeString;
    
public booleanisPrimitive()
test if this field is a primitive or not.

	return (type != '[" && type != 'L");
    
voidsetField(java.lang.reflect.Field field)

 	this.field = field;
 	this.fieldID = -1;
    
public java.lang.StringtoString()
Return a string describing this field.

	if (typeString != null)
	    return typeString + " " + name;
	else
	    return type + " " + name;
    
public booleantypeEquals(com.sun.corba.se.impl.orbutil.ObjectStreamField other)
Compare the types of two class descriptors. The match if they have the same primitive types. or if they are both objects and the object types match.

	if (other == null || type != other.type)
	    return false;

	/* Return true if the primitive types matched */
	if (typeString == null && other.typeString == null)
	    return true;

	return ObjectStreamClass_1_3_1.compareClassNames(typeString,
                                                         other.typeString,
                                                         '/");