[OpenMap Users] OMGraphic class modifications for Serilization

From: David Ward <mry_yachtsman_at_hotmail.com>
Date: Thu, 14 Apr 2005 13:05:59 -0700

Previously I posted a message about my success with Serializing OmGraphic
objects.

A few small modifications were needed to the OMGraphic, OMDistance,
OMSpline, and OMText
classes so they would perform some custom serialization and deserialization
of some
transient members.

I have not yet surveyed all of the OMGRaphic subclasses to see which
additional classes need custom serialization. At present, OMLine, OMPoly,
OMCircle, OMPoint and now the above are serializable.

Below are the modificaitons.

Cheers,
David


====================================================

com.bbn.openmap.omGraphics.OMGraphic


    /**
     * Write this object to a stream.
     */
    private void writeObject(ObjectOutputStream oos)
    throws IOException {
        oos.defaultWriteObject();

        //Now write the Stroke. Take into account the font member could be
        // null.

        // All strokes are BasicStrokes (atleast for now).
        BasicStroke s = (BasicStroke)stroke;

        //First write a flag indicating if a Stroke is on the stream.
        oos.writeBoolean(s != null);

        // Write the Stroke data if a Stroke is on this object.
        if (s != null) {
            oos.writeFloat(s.getLineWidth());
            oos.writeInt(s.getEndCap());
            oos.writeInt(s.getLineJoin());
            oos.writeFloat(s.getMiterLimit());
            oos.writeObject(s.getDashArray());
            oos.writeFloat(s.getDashPhase());
        }
    }


    /**
     * Read this object from a stream.
     */
    private void readObject(ObjectInputStream ois)
    throws ClassNotFoundException, IOException {
        ois.defaultReadObject();

        //Read the Stroke

        //Get the flag indicating a stroke was streamed
        boolean hasstroke = ois.readBoolean();

        // Read and create the stroke
        if (hasstroke) {
            float linewidth = ois.readFloat();
            int endcap = ois.readInt();
            int linejoin = ois.readInt();
            float miterlimit = ois.readFloat();
            float dasharray[] = (float[]) ois.readObject();
            float dashphase = ois.readFloat();
            stroke = new BasicStroke(linewidth, endcap, linejoin,
miterlimit, dasharray, dashphase);
        }
    }

=================================================

com.bbn.openmap.omGraphics.OMDistance

    /**
     * Write this object to a stream.
     */
    private void writeObject(java.io.ObjectOutputStream stream)
            throws java.io.IOException {
        stream.defaultWriteObject();
        stream.writeObject(distUnits.getAbbr());
    }

    /**
     * Read this object from a stream.
     */
    private void readObject(java.io.ObjectInputStream stream)
            throws java.io.IOException, ClassNotFoundException {
        stream.defaultReadObject();
        distUnits = Length.get((String) stream.readObject());
    }


=================================================

com.bbn.openmap.omGraphics.OMSpline


    /**
     * Write this object to a stream.
     */
    private void writeObject(ObjectOutputStream oos)
    throws IOException {
        oos.defaultWriteObject();
        // Include the writeObject() method for consistency.
        // even though we only do the default serialization.
        // Its just good practice to have both writeObject()
        // and readObject() when performing custom serialization.
    }

    /**
     * Read this object from a stream.
     */
    private void readObject(ObjectInputStream ois)
    throws ClassNotFoundException, IOException {
        ois.defaultReadObject();

        // Instatiate the objects that are transient
        // These are not creating on the deserialization
        // candidate object.
        natCubic = new NatCubicSpline();
        natCubicClosed = new NatCubicClosedSpline();
    }


=================================================

com.bbn.openmap.omGraphics.OMText

    /**
     * Write this object to a stream.
     */
    private void writeObject(ObjectOutputStream oos)
    throws IOException {
        oos.defaultWriteObject();

        // Write the Font. Take into account the font member could be
        // null, although this is unlikely it never hurts to
        // protect one's self.

        //First write a flag indicating if a Font is on the stream.
        oos.writeBoolean(f != null);

        // Write the Font data if a font is on this object.
        if (f != null) {
            oos.writeObject(f.getName());
            oos.writeInt(f.getSize());
            oos.writeInt(f.getStyle());
        }
    }

    /** Reconstitute from an ObjectInputStream.
     **/
    private void readObject(ObjectInputStream ois)
    throws ClassNotFoundException, IOException {
        ois.defaultReadObject();

        //Read the Stroke

        // Get the flag form the stream
        boolean hasfont = ois.readBoolean();

        if (hasfont) {
            String name = (String)ois.readObject();
            int size = ois.readInt();
            int style = ois.readInt();
            f = new Font(name, style, size);
        }
    }


--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Apr 14 2005 - 16:08:43 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:06 EDT