001: /*
002: * $RCSfile: HashSetState.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:50 $
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.HashSet;
020: import java.util.Iterator;
021: import javax.media.jai.JAI;
022: import javax.media.jai.remote.SerializerFactory;
023: import javax.media.jai.remote.SerializableState;
024:
025: /**
026: * This class is a serializable proxy for a HashSet object.
027: * <br>(entries which are neither <code>Serializable</code> nor supported by
028: * <code>SerializerFactory</code> are omitted);
029: *
030: *
031: * @since 1.1
032: */
033: public class HashSetState extends SerializableStateImpl {
034: /**
035: * Returns the classes supported by this SerializableState.
036: */
037: public static Class[] getSupportedClasses() {
038: return new Class[] { HashSet.class };
039: }
040:
041: /**
042: * Constructs a <code>HashSetState</code> from a
043: * <code>HashSet</code> object.
044: *
045: * @param c The <code>Class</code> of the object to be serialized.
046: * @param o The <code>HashSet</code> object to be serialized.
047: * @param h The <code>RebderingHint</code> for this serialization.
048: */
049: public HashSetState(Class c, Object o, RenderingHints h) {
050: super (c, o, h);
051: }
052:
053: /**
054: * Serialize the HashSetState.
055: */
056: private void writeObject(ObjectOutputStream out) throws IOException {
057: // -- Create a serializable form of the HashSet object. --
058: HashSet set = (HashSet) theObject;
059:
060: HashSet serializableSet = new HashSet();
061:
062: // If there are hints, add them to the set.
063: if (set != null && !set.isEmpty()) {
064: // Get an iterator for the set.
065: Iterator iterator = set.iterator();
066:
067: // Loop over the set.
068: while (iterator.hasNext()) {
069: Object object = iterator.next();
070: Object serializableObject = getSerializableForm(object);
071: serializableSet.add(serializableObject);
072: }
073: }
074:
075: // Write serialized form to the stream.
076: out.writeObject(serializableSet);
077: }
078:
079: /**
080: * Deserialize the HashSetState.
081: */
082: private void readObject(ObjectInputStream in) throws IOException,
083: ClassNotFoundException {
084: // Read serialized form from the stream.
085: HashSet serializableSet = (HashSet) in.readObject();
086:
087: // Create an empty HashSet object.
088: HashSet set = new HashSet();
089:
090: // If the set is empty just return.
091: if (serializableSet.isEmpty()) {
092: theObject = set;
093: return;
094: }
095:
096: Iterator iterator = serializableSet.iterator();
097:
098: // Loop over the set keys.
099: while (iterator.hasNext()) {
100: // Get the next key element.
101: Object serializableObject = iterator.next();
102: Object object = getDeserializedFrom(serializableObject);
103:
104: // Add an entry to the set.
105: set.add(object);
106: }
107:
108: theObject = set;
109: }
110: }
|