001: /*
002: * $RCSfile: VectorState.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:56:55 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.rmi;
013:
014: import java.awt.RenderingHints;
015: import java.io.IOException;
016: import java.io.ObjectInputStream;
017: import java.io.ObjectOutputStream;
018: import java.io.Serializable;
019: import java.util.Vector;
020: import java.util.Iterator;
021: import javax.media.jai.remote.SerializerFactory;
022: import javax.media.jai.remote.SerializableState;
023:
024: /**
025: * This class is a serializable proxy for a Vector object.
026: * <br>(entries which are neither <code>Serializable</code> nor supported by
027: * <code>SerializerFactory</code> are omitted);
028: *
029: *
030: * @since 1.1
031: */
032: public class VectorState extends SerializableStateImpl {
033: /**
034: * Returns the classes supported by this SerializableState.
035: */
036: public static Class[] getSupportedClasses() {
037: return new Class[] { Vector.class };
038: }
039:
040: /**
041: * Constructs a <code>VectorState</code> from a
042: * <code>Vector</code> object.
043: *
044: * @param c The <code>Class</code> of the object to be serialized.
045: * @param o The <code>Vector</code> object to be serialized.
046: * @param h The <code>RebderingHint</code> for this serialization.
047: */
048: public VectorState(Class c, Object o, RenderingHints h) {
049: super (c, o, h);
050: }
051:
052: /**
053: * Serialize the VectorState.
054: */
055: private void writeObject(ObjectOutputStream out) throws IOException {
056: // -- Create a serializable form of the Vector object. --
057: Vector vector = (Vector) theObject;
058: Vector serializableVector = new Vector();
059: Iterator iterator = vector.iterator();
060:
061: // If there are hints, add them to the vector.
062: while (iterator.hasNext()) {
063: Object object = iterator.next();
064: Object serializableObject = getSerializableForm(object);
065: serializableVector.add(serializableObject);
066: }
067:
068: // Write serialized form to the stream.
069: out.writeObject(serializableVector);
070: }
071:
072: /**
073: * Deserialize the VectorState.
074: */
075: private void readObject(ObjectInputStream in) throws IOException,
076: ClassNotFoundException {
077: // Read serialized form from the stream.
078: Vector serializableVector = (Vector) in.readObject();
079:
080: // Create an empty Vector object.
081: Vector vector = new Vector();
082: theObject = vector;
083:
084: // If the vector is empty just return.
085: if (serializableVector.isEmpty()) {
086: return;
087: }
088:
089: // Get an enumeration of the vector keys.
090: Iterator iterator = serializableVector.iterator();
091:
092: // Loop over the vector keys.
093: while (iterator.hasNext()) {
094: // Get the next key element.
095: Object serializableObject = iterator.next();
096: Object object = getDeserializedFrom(serializableObject);
097:
098: // Add an entry to the vector.
099: vector.add(object);
100: }
101: }
102: }
|