harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r492652 [3/13] - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/
Date Thu, 04 Jan 2007 17:47:05 GMT
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFields.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFields.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFields.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFields.java Thu Jan  4 09:47:01 2007
@@ -17,7 +17,6 @@
 
 package java.io;
 
-
 /**
  * An EmulatedFields is an object that represents a set of emulated fields for
  * an object being dumped or loaded. It allows objects to be dumped with a shape
@@ -28,575 +27,598 @@
  * @see EmulatedFieldsForLoading
  * @see EmulatedFieldsForDumping
  */
-
 class EmulatedFields {
-	static class ObjectSlot {
-		// A slot is a field plus its value
-		ObjectStreamField field; // Field descriptor
-
-		Object fieldValue; // Actual value this emulated field holds
-
-		boolean defaulted = true; // If this field has a default value (true)
-									// or something has been assigned (false)
-
-		/**
-		 * Returns the descriptor for this emulated field.
-		 * 
-		 * @return the field descriptor
-		 */
-		public ObjectStreamField getField() {
-			return field;
-		}
-
-		/**
-		 * Returns the value held by this emulated field.
-		 * 
-		 * @return the field value
-		 */
-		public Object getFieldValue() {
-			return fieldValue;
-		}
-	}
-
-	private ObjectSlot[] slotsToSerialize; // The collection of slots the
-											// receiver represents
-
-	private ObjectStreamField[] declaredFields;
-
-	/**
-	 * Constructs a new instance of EmulatedFields.
-	 * 
-	 * @param fields
-	 *            an array of ObjectStreamFields, which describe the fields to
-	 *            be emulated (names, types, etc).
-	 * @param declared
-	 *            an array of ObjectStreamFields, which describe the declared
-	 *            fields.
-	 */
-	public EmulatedFields(ObjectStreamField[] fields,
-			ObjectStreamField[] declared) {
-		super();
-		// We assume the slots are already sorted in the right shape for dumping
-		buildSlots(fields);
-		declaredFields = declared;
-	}
-
-	/**
-	 * Build emulated slots that correspond to emulated fields. A slot is a
-	 * field descriptor (ObjectStreamField) plus the actual value it holds.
-	 * 
-	 * @param fields
-	 *            an array of ObjectStreamField, which describe the fields to be
-	 *            emulated (names, types, etc).
-	 */
-	private void buildSlots(ObjectStreamField[] fields) {
-		slotsToSerialize = new ObjectSlot[fields.length];
-		for (int i = 0; i < fields.length; i++) {
-			ObjectSlot s = new ObjectSlot();
-			slotsToSerialize[i] = s;
-			s.field = fields[i];
-		}
-		// We assume the slots are already sorted in the right shape for dumping
-	}
-
-	/**
-	 * Return a boolean indicating if the field named <code>name</code> has
-	 * been assigned a value explicitly (false) or if it still holds a default
-	 * value for the type (true) because it hasn't been assigned to yet.
-	 * 
-	 * @param name
-	 *            a String, the name of the field to test
-	 * @return <code>true</code> if <code>name</code> still holds its
-	 *         default value, <code>false</code> otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If <code>name</code> is null
-	 */
-	public boolean defaulted(String name) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, null);
-		if (slot != null)
-			return slot.defaulted;
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return an ObjectSlot that corresponds to a field named
-	 * <code>fieldName</code> and type <code>fieldType</code>. If the field
-	 * type <code>fieldType</code> corresponds to a primitive type, the field
-	 * type has to match exactly or <code>null</code> is returned. If the
-	 * field type <code>fieldType</code> corresponds to an object type, the
-	 * field type has to be compatible in terms of assignment, or null is
-	 * returned. If <code>fieldType</code> is <code>null</code>, no such
-	 * compatibility checking is performed and the slot is returned.
-	 * 
-	 * @param fieldName
-	 *            A String, the name of the field to find
-	 * @param fieldType
-	 *            A Class, the type of the field. This will be used to test
-	 *            compatibility. If null, no testing is done, the corresponding
-	 *            slot is returned.
-	 * @return If there is no field with that name, or no compatible field
-	 *         (relative to <code>fieldType</code>)
-	 */
-	private ObjectSlot findSlot(String fieldName, Class<?> fieldType) {
-		boolean isPrimitive = fieldType != null && fieldType.isPrimitive();
-
-		for (int i = 0; i < slotsToSerialize.length; i++) {
-			ObjectSlot slot = slotsToSerialize[i];
-			if (slot.field.getName().equals(fieldName))
-				if (isPrimitive) {
-					// Looking for a primitive type field. Types must match
-					// *exactly*
-					if (slot.field.getType() == fieldType)
-						return slot;
-				} else {
-					// Looking for a non-primitive type field.
-					if (fieldType == null)
-						return slot; // Null means we take anything
-					// Types must be compatible (assignment)
-					if (slot.field.getType().isAssignableFrom(fieldType))
-						return slot;
-				}
-		}
-
-		if (declaredFields != null) {
-			for (int i = 0; i < declaredFields.length; i++) {
-				ObjectStreamField field = declaredFields[i];
-				if (field.getName().equals(fieldName)) {
-					if (isPrimitive ? field.getType() == fieldType
-							: fieldType == null
-									|| field.getType().isAssignableFrom(
-											fieldType)) {
-						ObjectSlot slot = new ObjectSlot();
-						slot.field = field;
-						slot.defaulted = true;
-						return slot;
-					}
-				}
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * Find and return the byte value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public byte get(String name, byte defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Byte.TYPE);
-		if (slot != null) // if not initialized yet, we give the default value
-			return slot.defaulted ? defaultValue : ((Byte) slot.fieldValue)
-					.byteValue();
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return the char value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public char get(String name, char defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Character.TYPE);
-		if (slot != null) // if not initialized yet, we give the default value
-			return slot.defaulted ? defaultValue
-					: ((Character) slot.fieldValue).charValue();
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return the double value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public double get(String name, double defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Double.TYPE);
-		if (slot != null) // if not initialized yet, we give the default value
-			return slot.defaulted ? defaultValue : ((Double) slot.fieldValue)
-					.doubleValue();
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return the float value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public float get(String name, float defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Float.TYPE);
-		if (slot != null) // if not initialized yet, we give the default value
-			return slot.defaulted ? defaultValue : ((Float) slot.fieldValue)
-					.floatValue();
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return the int value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public int get(String name, int defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Integer.TYPE);
-		if (slot != null) // if not initialized yet, we give the default value
-			return slot.defaulted ? defaultValue : ((Integer) slot.fieldValue)
-					.intValue();
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return the long value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public long get(String name, long defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Long.TYPE);
-		if (slot != null) // if not initialized yet, we give the default value
-			return slot.defaulted ? defaultValue : ((Long) slot.fieldValue)
-					.longValue();
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return the Object value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public Object get(String name, Object defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, null);
-		if (slot != null && !slot.field.getType().isPrimitive()) // if not
-																	// initialized
-																	// yet, we
-																	// give the
-																	// default
-																	// value
-			return slot.defaulted ? defaultValue : slot.fieldValue;
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return the short value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public short get(String name, short defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Short.TYPE);
-		if (slot != null) // if not initialized yet, we give the default value
-			return slot.defaulted ? defaultValue : ((Short) slot.fieldValue)
-					.shortValue();
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and return the boolean value of a given field named
-	 * <code>name</code> in the receiver. If the field has not been assigned
-	 * any value yet, the default value <code>defaultValue</code> is returned
-	 * instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, the default
-	 *         value otherwise
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public boolean get(String name, boolean defaultValue)
-			throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Boolean.TYPE);
-		if (slot != null) // if not initialized yet, we give the default value
-			return slot.defaulted ? defaultValue : ((Boolean) slot.fieldValue)
-					.booleanValue();
-		throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the byte value of a given field named <code>name</code> in
-	 * the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, byte value) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Byte.TYPE);
-		if (slot != null) {
-			slot.fieldValue = Byte.valueOf(value);
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the char value of a given field named <code>name</code> in
-	 * the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, char value) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Character.TYPE);
-		if (slot != null) {
-			slot.fieldValue = Character.valueOf(value);
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the double value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, double value) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Double.TYPE);
-		if (slot != null) {
-			slot.fieldValue = Double.valueOf(value);
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the float value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, float value) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Float.TYPE);
-		if (slot != null) {
-			slot.fieldValue = Float.valueOf(value);
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the int value of a given field named <code>name</code> in
-	 * the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, int value) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Integer.TYPE);
-		if (slot != null) {
-			slot.fieldValue = Integer.valueOf(value);
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the long value of a given field named <code>name</code> in
-	 * the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, long value) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Long.TYPE);
-		if (slot != null) {
-			slot.fieldValue = Long.valueOf(value);
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the Object value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, Object value) throws IllegalArgumentException {
-		Class<?> valueClass = null;
-		if (value != null)
-			valueClass = value.getClass();
-		ObjectSlot slot = findSlot(name, valueClass);
-		if (slot != null) {
-			slot.fieldValue = value;
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the short value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, short value) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Short.TYPE);
-		if (slot != null) {
-			slot.fieldValue = Short.valueOf(value);
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Find and set the boolean value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	public void put(String name, boolean value) throws IllegalArgumentException {
-		ObjectSlot slot = findSlot(name, Boolean.TYPE);
-		if (slot != null) {
-			slot.fieldValue = Boolean.valueOf(value);
-			slot.defaulted = false; // No longer default value
-		} else
-			throw new IllegalArgumentException();
-	}
-
-	/**
-	 * Return the array of ObjectSlot the receiver represents.
-	 * 
-	 * @return array of ObjectSlot the receiver represents.
-	 */
-	public ObjectSlot[] slots() {
-		return slotsToSerialize;
-	}
+
+    // A slot is a field plus its value
+    static class ObjectSlot {
+
+        // Field descriptor
+        ObjectStreamField field;
+
+        // Actual value this emulated field holds
+        Object fieldValue;
+
+        // If this field has a default value (true) or something has been
+        // assigned (false)
+        boolean defaulted = true;
+
+        /**
+         * Returns the descriptor for this emulated field.
+         * 
+         * @return the field descriptor
+         */
+        public ObjectStreamField getField() {
+            return field;
+        }
+
+        /**
+         * Returns the value held by this emulated field.
+         * 
+         * @return the field value
+         */
+        public Object getFieldValue() {
+            return fieldValue;
+        }
+    }
+
+    // The collection of slots the receiver represents
+    private ObjectSlot[] slotsToSerialize;
+
+    private ObjectStreamField[] declaredFields;
+
+    /**
+     * Constructs a new instance of EmulatedFields.
+     * 
+     * @param fields
+     *            an array of ObjectStreamFields, which describe the fields to
+     *            be emulated (names, types, etc).
+     * @param declared
+     *            an array of ObjectStreamFields, which describe the declared
+     *            fields.
+     */
+    public EmulatedFields(ObjectStreamField[] fields,
+            ObjectStreamField[] declared) {
+        super();
+        // We assume the slots are already sorted in the right shape for dumping
+        buildSlots(fields);
+        declaredFields = declared;
+    }
+
+    /**
+     * Build emulated slots that correspond to emulated fields. A slot is a
+     * field descriptor (ObjectStreamField) plus the actual value it holds.
+     * 
+     * @param fields
+     *            an array of ObjectStreamField, which describe the fields to be
+     *            emulated (names, types, etc).
+     */
+    private void buildSlots(ObjectStreamField[] fields) {
+        slotsToSerialize = new ObjectSlot[fields.length];
+        for (int i = 0; i < fields.length; i++) {
+            ObjectSlot s = new ObjectSlot();
+            slotsToSerialize[i] = s;
+            s.field = fields[i];
+        }
+        // We assume the slots are already sorted in the right shape for dumping
+    }
+
+    /**
+     * Return a boolean indicating if the field named <code>name</code> has
+     * been assigned a value explicitly (false) or if it still holds a default
+     * value for the type (true) because it hasn't been assigned to yet.
+     * 
+     * @param name
+     *            a String, the name of the field to test
+     * @return <code>true</code> if <code>name</code> still holds its
+     *         default value, <code>false</code> otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If <code>name</code> is null
+     */
+    public boolean defaulted(String name) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, null);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted;
+    }
+
+    /**
+     * Find and return an ObjectSlot that corresponds to a field named
+     * <code>fieldName</code> and type <code>fieldType</code>. If the field
+     * type <code>fieldType</code> corresponds to a primitive type, the field
+     * type has to match exactly or <code>null</code> is returned. If the
+     * field type <code>fieldType</code> corresponds to an object type, the
+     * field type has to be compatible in terms of assignment, or null is
+     * returned. If <code>fieldType</code> is <code>null</code>, no such
+     * compatibility checking is performed and the slot is returned.
+     * 
+     * @param fieldName
+     *            A String, the name of the field to find
+     * @param fieldType
+     *            A Class, the type of the field. This will be used to test
+     *            compatibility. If null, no testing is done, the corresponding
+     *            slot is returned.
+     * @return If there is no field with that name, or no compatible field
+     *         (relative to <code>fieldType</code>)
+     */
+    private ObjectSlot findSlot(String fieldName, Class<?> fieldType) {
+        boolean isPrimitive = fieldType != null && fieldType.isPrimitive();
+
+        for (int i = 0; i < slotsToSerialize.length; i++) {
+            ObjectSlot slot = slotsToSerialize[i];
+            if (slot.field.getName().equals(fieldName)) {
+                if (isPrimitive) {
+                    // Looking for a primitive type field. Types must match
+                    // *exactly*
+                    if (slot.field.getType() == fieldType) {
+                        return slot;
+                    }
+                } else {
+                    // Looking for a non-primitive type field.
+                    if (fieldType == null) {
+                        return slot; // Null means we take anything
+                    }
+                    // Types must be compatible (assignment)
+                    if (slot.field.getType().isAssignableFrom(fieldType)) {
+                        return slot;
+                    }
+                }
+            }
+        }
+
+        if (declaredFields != null) {
+            for (int i = 0; i < declaredFields.length; i++) {
+                ObjectStreamField field = declaredFields[i];
+                if (field.getName().equals(fieldName)) {
+                    if (isPrimitive ? field.getType() == fieldType
+                            : fieldType == null
+                                    || field.getType().isAssignableFrom(
+                                            fieldType)) {
+                        ObjectSlot slot = new ObjectSlot();
+                        slot.field = field;
+                        slot.defaulted = true;
+                        return slot;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Find and return the byte value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public byte get(String name, byte defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Byte.TYPE);
+        // if not initialized yet, we give the default value
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : ((Byte) slot.fieldValue)
+                .byteValue();
+    }
+
+    /**
+     * Find and return the char value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public char get(String name, char defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Character.TYPE);
+        // if not initialized yet, we give the default value
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : ((Character) slot.fieldValue)
+                .charValue();
+    }
+
+    /**
+     * Find and return the double value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public double get(String name, double defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Double.TYPE);
+        // if not initialized yet, we give the default value
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : ((Double) slot.fieldValue)
+                .doubleValue();
+    }
+
+    /**
+     * Find and return the float value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public float get(String name, float defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Float.TYPE);
+        // if not initialized yet, we give the default value
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : ((Float) slot.fieldValue)
+                .floatValue();
+    }
+
+    /**
+     * Find and return the int value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public int get(String name, int defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Integer.TYPE);
+        // if not initialized yet, we give the default value
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : ((Integer) slot.fieldValue)
+                .intValue();
+    }
+
+    /**
+     * Find and return the long value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public long get(String name, long defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Long.TYPE);
+        // if not initialized yet, we give the default value
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : ((Long) slot.fieldValue)
+                .longValue();
+    }
+
+    /**
+     * Find and return the Object value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public Object get(String name, Object defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, null);
+        // if not initialized yet, we give the default value
+        if (slot == null || slot.field.getType().isPrimitive()) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : slot.fieldValue;
+    }
+
+    /**
+     * Find and return the short value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public short get(String name, short defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Short.TYPE);
+        // if not initialized yet, we give the default value
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : ((Short) slot.fieldValue)
+                .shortValue();
+    }
+
+    /**
+     * Find and return the boolean value of a given field named
+     * <code>name</code> in the receiver. If the field has not been assigned
+     * any value yet, the default value <code>defaultValue</code> is returned
+     * instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, the default
+     *         value otherwise
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public boolean get(String name, boolean defaultValue)
+            throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Boolean.TYPE);
+        // if not initialized yet, we give the default value
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        return slot.defaulted ? defaultValue : ((Boolean) slot.fieldValue)
+                .booleanValue();
+    }
+
+    /**
+     * Find and set the byte value of a given field named <code>name</code> in
+     * the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, byte value) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Byte.TYPE);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = Byte.valueOf(value);
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Find and set the char value of a given field named <code>name</code> in
+     * the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, char value) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Character.TYPE);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = Character.valueOf(value);
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Find and set the double value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, double value) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Double.TYPE);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = Double.valueOf(value);
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Find and set the float value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, float value) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Float.TYPE);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = Float.valueOf(value);
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Find and set the int value of a given field named <code>name</code> in
+     * the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, int value) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Integer.TYPE);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = Integer.valueOf(value);
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Find and set the long value of a given field named <code>name</code> in
+     * the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, long value) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Long.TYPE);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = Long.valueOf(value);
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Find and set the Object value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, Object value) throws IllegalArgumentException {
+        Class<?> valueClass = null;
+        if (value != null) {
+            valueClass = value.getClass();
+        }
+        ObjectSlot slot = findSlot(name, valueClass);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = value;
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Find and set the short value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, short value) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Short.TYPE);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = Short.valueOf(value);
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Find and set the boolean value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     * 
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    public void put(String name, boolean value) throws IllegalArgumentException {
+        ObjectSlot slot = findSlot(name, Boolean.TYPE);
+        if (slot == null) {
+            throw new IllegalArgumentException();
+        }
+        slot.fieldValue = Boolean.valueOf(value);
+        slot.defaulted = false; // No longer default value
+    }
+
+    /**
+     * Return the array of ObjectSlot the receiver represents.
+     * 
+     * @return array of ObjectSlot the receiver represents.
+     */
+    public ObjectSlot[] slots() {
+        return slotsToSerialize;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForDumping.java Thu Jan  4 09:47:01 2007
@@ -17,227 +17,217 @@
 
 package java.io;
 
-
 /**
  * An EmulatedFieldsForDumping is an object that represents a set of emulated
  * fields for an object being dumped. It is a concrete implementation for
  * ObjectOutputStream.PutField
  * 
-
+ * 
  * @see ObjectOutputStream.PutField
  * @see EmulatedFieldsForLoading
  */
-
 class EmulatedFieldsForDumping extends ObjectOutputStream.PutField {
-	private EmulatedFields emulatedFields; // The actual representation, with a
-											// more powerful API (set&get)
 
-	/**
-	 * Constructs a new instance of EmulatedFieldsForDumping.
-	 * 
-	 * @param streamClass
-	 *            a ObjectStreamClass, which describe the fields to be emulated
-	 *            (names, types, etc).
-	 */
-	EmulatedFieldsForDumping(ObjectStreamClass streamClass) {
-		super();
-		emulatedFields = new EmulatedFields(streamClass.fields(),
-				(ObjectStreamField[]) null);
-	}
-
-	/**
-	 * Return the actual EmulatedFields instance used by the receiver. We have
-	 * the actual work in a separate class so that the code can be shared. The
-	 * receiver has to be of a subclass of PutField.
-	 * 
-	 * @return array of ObjectSlot the receiver represents.
-	 */
-	EmulatedFields emulatedFields() {
-		return emulatedFields;
-	}
-
-	/**
-	 * Find and set the byte value of a given field named <code>name</code> in
-	 * the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    // The actual representation, with a more powerful API (set&get)
+    private EmulatedFields emulatedFields;
+
+    /**
+     * Constructs a new instance of EmulatedFieldsForDumping.
+     * 
+     * @param streamClass
+     *            a ObjectStreamClass, which describe the fields to be emulated
+     *            (names, types, etc).
+     */
+    EmulatedFieldsForDumping(ObjectStreamClass streamClass) {
+        super();
+        emulatedFields = new EmulatedFields(streamClass.fields(),
+                (ObjectStreamField[]) null);
+    }
+
+    /**
+     * Return the actual EmulatedFields instance used by the receiver. We have
+     * the actual work in a separate class so that the code can be shared. The
+     * receiver has to be of a subclass of PutField.
+     * 
+     * @return array of ObjectSlot the receiver represents.
+     */
+    EmulatedFields emulatedFields() {
+        return emulatedFields;
+    }
+
+    /**
+     * Find and set the byte value of a given field named <code>name</code> in
+     * the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, byte value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Find and set the char value of a given field named <code>name</code> in
-	 * the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    /**
+     * Find and set the char value of a given field named <code>name</code> in
+     * the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, char value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Find and set the double value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    /**
+     * Find and set the double value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, double value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Find and set the float value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    /**
+     * Find and set the float value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, float value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Find and set the int value of a given field named <code>name</code> in
-	 * the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    /**
+     * Find and set the int value of a given field named <code>name</code> in
+     * the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, int value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Find and set the long value of a given field named <code>name</code> in
-	 * the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    /**
+     * Find and set the long value of a given field named <code>name</code> in
+     * the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, long value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Find and set the Object value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    /**
+     * Find and set the Object value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, Object value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Find and set the short value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    /**
+     * Find and set the short value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, short value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Find and set the boolean value of a given field named <code>name</code>
-	 * in the receiver.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to set
-	 * @param value
-	 *            New value for the field.
-	 * 
-	 */
-	@Override
+    /**
+     * Find and set the boolean value of a given field named <code>name</code>
+     * in the receiver.
+     * 
+     * @param name
+     *            A String, the name of the field to set
+     * @param value
+     *            New value for the field.
+     */
+    @Override
     public void put(String name, boolean value) {
-		emulatedFields.put(name, value);
-	}
+        emulatedFields.put(name, value);
+    }
 
-	/**
-	 * Write the field values to the specified ObjectOutput.
-	 * 
-	 * @param output
-	 *            the ObjectOutput
-	 * 
-	 * @throws IOException
-	 *             If an IO exception happened when writing the field values.
-	 */
-	@Override
+    /**
+     * Write the field values to the specified ObjectOutput.
+     * 
+     * @param output
+     *            the ObjectOutput
+     * 
+     * @throws IOException
+     *             If an IO exception happened when writing the field values.
+     */
+    @Override
     @Deprecated
     @SuppressWarnings("deprecation")
     public void write(ObjectOutput output) throws IOException {
-		EmulatedFields.ObjectSlot[] slots = emulatedFields.slots();
-		for (int i = 0; i < slots.length; i++) {
-			EmulatedFields.ObjectSlot slot = slots[i];
-			Object fieldValue = slot.getFieldValue();
-			Class<?> type = slot.getField().getType();
-			// WARNING - default values exist for each primitive type
-			if (type == Integer.TYPE) {
-				output.writeInt(fieldValue != null ? ((Integer) fieldValue)
-						.intValue() : 0);
-			} else if (type == Byte.TYPE) {
-				output.writeByte(fieldValue != null ? ((Byte) fieldValue)
-						.byteValue() : (byte) 0);
-			} else if (type == Character.TYPE) {
-				output.writeChar(fieldValue != null ? ((Character) fieldValue)
-						.charValue() : (char) 0);
-			} else if (type == Short.TYPE) {
-				output.writeShort(fieldValue != null ? ((Short) fieldValue)
-						.shortValue() : (short) 0);
-			} else if (type == Boolean.TYPE) {
-				output.writeBoolean(fieldValue != null ? ((Boolean) fieldValue)
-						.booleanValue() : false);
-			} else if (type == Long.TYPE) {
-				output.writeLong(fieldValue != null ? ((Long) fieldValue)
-						.longValue() : (long) 0);
-			} else if (type == Float.TYPE) {
-				output.writeFloat(fieldValue != null ? ((Float) fieldValue)
-						.floatValue() : (float) 0);
-			} else if (type == Double.TYPE) {
-				output.writeDouble(fieldValue != null ? ((Double) fieldValue)
-						.doubleValue() : (double) 0);
-			} else {
-				// Either array or Object
-				output.writeObject(fieldValue);
-			}
-		}
-	}
+        EmulatedFields.ObjectSlot[] slots = emulatedFields.slots();
+        for (int i = 0; i < slots.length; i++) {
+            EmulatedFields.ObjectSlot slot = slots[i];
+            Object fieldValue = slot.getFieldValue();
+            Class<?> type = slot.getField().getType();
+            // WARNING - default values exist for each primitive type
+            if (type == Integer.TYPE) {
+                output.writeInt(fieldValue != null ? ((Integer) fieldValue)
+                        .intValue() : 0);
+            } else if (type == Byte.TYPE) {
+                output.writeByte(fieldValue != null ? ((Byte) fieldValue)
+                        .byteValue() : (byte) 0);
+            } else if (type == Character.TYPE) {
+                output.writeChar(fieldValue != null ? ((Character) fieldValue)
+                        .charValue() : (char) 0);
+            } else if (type == Short.TYPE) {
+                output.writeShort(fieldValue != null ? ((Short) fieldValue)
+                        .shortValue() : (short) 0);
+            } else if (type == Boolean.TYPE) {
+                output.writeBoolean(fieldValue != null ? ((Boolean) fieldValue)
+                        .booleanValue() : false);
+            } else if (type == Long.TYPE) {
+                output.writeLong(fieldValue != null ? ((Long) fieldValue)
+                        .longValue() : (long) 0);
+            } else if (type == Float.TYPE) {
+                output.writeFloat(fieldValue != null ? ((Float) fieldValue)
+                        .floatValue() : (float) 0);
+            } else if (type == Double.TYPE) {
+                output.writeDouble(fieldValue != null ? ((Double) fieldValue)
+                        .doubleValue() : (double) 0);
+            } else {
+                // Either array or Object
+                output.writeObject(fieldValue);
+            }
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForLoading.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForLoading.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForLoading.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/EmulatedFieldsForLoading.java Thu Jan  4 09:47:01 2007
@@ -17,7 +17,6 @@
 
 package java.io;
 
-
 /**
  * An EmulatedFieldsForLoading is an object that represents a set of emulated
  * fields for an object being loaded. It is a concrete implementation for
@@ -27,275 +26,275 @@
  * @see EmulatedFieldsForDumping
  */
 class EmulatedFieldsForLoading extends ObjectInputStream.GetField {
-	private ObjectStreamClass streamClass; // The class descriptor with the
-											// declared fields the receiver
-											// emulates
-
-	private EmulatedFields emulatedFields; // The actual representation, with a
-											// more powerful API (set&get)
-
-	/**
-	 * Constructs a new instance of EmulatedFieldsForDumping.
-	 * 
-	 * @param streamClass
-	 *            an ObjectStreamClass, defining the class for which to emulate
-	 *            fields.
-	 */
-	EmulatedFieldsForLoading(ObjectStreamClass streamClass) {
-		super();
-		this.streamClass = streamClass;
-		emulatedFields = new EmulatedFields(streamClass.getLoadFields(),
-				streamClass.fields());
-	}
-
-	/**
-	 * Return a boolean indicating if the field named <code>name</code> has
-	 * been assigned a value explicitly (false) or if it still holds a default
-	 * value for the type (true) because it hasn't been assigned to yet.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to test
-	 * @return <code>true</code> if the field holds it default value,
-	 *         <code>false</code> otherwise.
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+
+    // The class descriptor with the declared fields the receiver emulates
+    private ObjectStreamClass streamClass;
+
+    // The actual representation, with a more powerful API (set&get)
+    private EmulatedFields emulatedFields;
+
+    /**
+     * Constructs a new instance of EmulatedFieldsForDumping.
+     * 
+     * @param streamClass
+     *            an ObjectStreamClass, defining the class for which to emulate
+     *            fields.
+     */
+    EmulatedFieldsForLoading(ObjectStreamClass streamClass) {
+        super();
+        this.streamClass = streamClass;
+        emulatedFields = new EmulatedFields(streamClass.getLoadFields(),
+                streamClass.fields());
+    }
+
+    /**
+     * Return a boolean indicating if the field named <code>name</code> has
+     * been assigned a value explicitly (false) or if it still holds a default
+     * value for the type (true) because it hasn't been assigned to yet.
+     * 
+     * @param name
+     *            A String, the name of the field to test
+     * @return <code>true</code> if the field holds it default value,
+     *         <code>false</code> otherwise.
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public boolean defaulted(String name) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.defaulted(name);
-	}
-
-	/**
-	 * Return the actual EmulatedFields instance used by the receiver. We have
-	 * the actual work in a separate class so that the code can be shared. The
-	 * receiver has to be of a subclass of GetField.
-	 * 
-	 * @return array of ObjectSlot the receiver represents.
-	 */
-	EmulatedFields emulatedFields() {
-		return emulatedFields;
-	}
-
-	/**
-	 * Find and return the byte value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.defaulted(name);
+    }
+
+    /**
+     * Return the actual EmulatedFields instance used by the receiver. We have
+     * the actual work in a separate class so that the code can be shared. The
+     * receiver has to be of a subclass of GetField.
+     * 
+     * @return array of ObjectSlot the receiver represents.
+     */
+    EmulatedFields emulatedFields() {
+        return emulatedFields;
+    }
+
+    /**
+     * Find and return the byte value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public byte get(String name, byte defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Find and return the char value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Find and return the char value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public char get(String name, char defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Find and return the double value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Find and return the double value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public double get(String name, double defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Find and return the float value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Find and return the float value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public float get(String name, float defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Find and return the int value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Find and return the int value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public int get(String name, int defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Find and return the long value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Find and return the long value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public long get(String name, long defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Find and return the Object value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Find and return the Object value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public Object get(String name, Object defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Find and return the short value of a given field named <code>name</code>
-	 * in the receiver. If the field has not been assigned any value yet, the
-	 * default value <code>defaultValue</code> is returned instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Find and return the short value of a given field named <code>name</code>
+     * in the receiver. If the field has not been assigned any value yet, the
+     * default value <code>defaultValue</code> is returned instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public short get(String name, short defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Find and return the boolean value of a given field named
-	 * <code>name</code> in the receiver. If the field has not been assigned
-	 * any value yet, the default value <code>defaultValue</code> is returned
-	 * instead.
-	 * 
-	 * @param name
-	 *            A String, the name of the field to find
-	 * @param defaultValue
-	 *            Return value in case the field has not been assigned to yet.
-	 * @return the value of the given field if it has been assigned, or the
-	 *         default value otherwise
-	 * 
-	 * @throws IOException
-	 *             If an IO error occurs
-	 * @throws IllegalArgumentException
-	 *             If the corresponding field can not be found.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Find and return the boolean value of a given field named
+     * <code>name</code> in the receiver. If the field has not been assigned
+     * any value yet, the default value <code>defaultValue</code> is returned
+     * instead.
+     * 
+     * @param name
+     *            A String, the name of the field to find
+     * @param defaultValue
+     *            Return value in case the field has not been assigned to yet.
+     * @return the value of the given field if it has been assigned, or the
+     *         default value otherwise
+     * 
+     * @throws IOException
+     *             If an IO error occurs
+     * @throws IllegalArgumentException
+     *             If the corresponding field can not be found.
+     */
+    @Override
     public boolean get(String name, boolean defaultValue) throws IOException,
-			IllegalArgumentException {
-		return emulatedFields.get(name, defaultValue);
-	}
-
-	/**
-	 * Return the class descriptor for which the emulated fields are defined.
-	 * 
-	 * @return ObjectStreamClass The class descriptor for which the emulated
-	 *         fields are defined.
-	 */
-	@Override
+            IllegalArgumentException {
+        return emulatedFields.get(name, defaultValue);
+    }
+
+    /**
+     * Return the class descriptor for which the emulated fields are defined.
+     * 
+     * @return ObjectStreamClass The class descriptor for which the emulated
+     *         fields are defined.
+     */
+    @Override
     public ObjectStreamClass getObjectStreamClass() {
-		return streamClass;
-	}
+        return streamClass;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Externalizable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Externalizable.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Externalizable.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Externalizable.java Thu Jan  4 09:47:01 2007
@@ -17,35 +17,34 @@
 
 package java.io;
 
-
 /**
  * Objects that want to be serialized/deserialized using
  * ObjectOutputStream/ObjectInputStream but defining their own byte
  * representation should implement this interface.
  */
 public interface Externalizable extends Serializable {
-	/**
-	 * Reads the next object from the ObjectInput <code>input</code>
-	 * 
-	 * @param input
-	 *            the ObjectInput from which the next object is read
-	 * 
-	 * @throws IOException
-	 *             If an error occurs attempting to read from this ObjectInput.
-	 * @throws ClassNotFoundException
-	 *             If the class of the instance being loaded cannot be found
-	 */
-	public void readExternal(ObjectInput input) throws IOException,
-			java.lang.ClassNotFoundException;
+    /**
+     * Reads the next object from the ObjectInput <code>input</code>
+     * 
+     * @param input
+     *            the ObjectInput from which the next object is read
+     * 
+     * @throws IOException
+     *             If an error occurs attempting to read from this ObjectInput.
+     * @throws ClassNotFoundException
+     *             If the class of the instance being loaded cannot be found
+     */
+    public void readExternal(ObjectInput input) throws IOException,
+            ClassNotFoundException;
 
-	/**
-	 * Writes the receiver to the ObjectOutput <code>output</code>.
-	 * 
-	 * @param output
-	 *            an ObjectOutput where to write the object
-	 * 
-	 * @throws IOException
-	 *             If an error occurs attempting to write to the ObjectOutput.
-	 */
-	public void writeExternal(ObjectOutput output) throws IOException;
+    /**
+     * Writes the receiver to the ObjectOutput <code>output</code>.
+     * 
+     * @param output
+     *            an ObjectOutput where to write the object
+     * 
+     * @throws IOException
+     *             If an error occurs attempting to write to the ObjectOutput.
+     */
+    public void writeExternal(ObjectOutput output) throws IOException;
 }



Mime
View raw message