Interface Codable
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface Codable

public interface netscape.util.Codable
{
    /* Fields
     */
    public final static byte BOOLEAN_ARRAY_TYPE;
    public final static byte BOOLEAN_TYPE;
    public final static byte BYTE_ARRAY_TYPE;
    public final static byte BYTE_TYPE;
    public final static byte CHAR_ARRAY_TYPE;
    public final static byte CHAR_TYPE;
    public final static byte DOUBLE_ARRAY_TYPE;
    public final static byte DOUBLE_TYPE;
    public final static byte FLOAT_ARRAY_TYPE;
    public final static byte FLOAT_TYPE;
    public final static byte INT_ARRAY_TYPE;
    public final static byte INT_TYPE;
    public final static byte LONG_ARRAY_TYPE;
    public final static byte LONG_TYPE;
    public final static byte OBJECT_ARRAY_TYPE;
    public final static byte OBJECT_TYPE;
    public final static byte SHORT_ARRAY_TYPE;
    public final static byte SHORT_TYPE;
    public final static byte STRING_ARRAY_TYPE;
    public final static byte STRING_TYPE;

    /* Methods
     */
    public abstract void decode(Decoder);
    public abstract void describeClassInfo(ClassInfo);
    public abstract void encode(Encoder);
    public abstract void finishDecoding();
}
The Codable interface describes the methods that an object must implement to encode and decode its essential state. An object describes its essential state through a set of key-value pairs, where the keys are strings and the values are one of the primitive Codable types listed below. The order in which the key-value pairs are used is not important. However, it is more efficient to encode and decode them in the same order as the addField() declarations in the class' describeClassInfo() method. The follwing sample shows how a View subclass might encode itself:
    public class MyView extends View {
        Codable someObject;
        public MyView() {
        }
        public void describeClassInfo(ClassInfo info) {
            super.describeClassInfo(info);
            info.addClass("MyView", 1);
            info.addField("someObject", OBJECT_TYPE);
        }
        public void encode(Encoder encoder) throws CodingException {
            super.encode(encoder);
            encoder.encodeObject("someObject", someObject);
        }
        public void decode(Decoder decoder) throws CodingException {
            super.decode(decoder);
            someObject = decoder.decodeObject("someObject");
        }
        public void finishDecoding() throws CodingException {
            super.finishDecoding();
        }
   }
Note: To be Codable, an object must be public and must implement a public empty constructor. This empty constructor is called to create the object prior to a call to its decode() method.
See Also:
Encoder, Decoder, Archiver, Unarchiver, ClassInfo

Fields

BOOLEAN_TYPE

  public final static byte BOOLEAN_TYPE
Primitive Codable type.

BOOLEAN_ARRAY_TYPE

  public final static byte BOOLEAN_ARRAY_TYPE
Primitive Codable type.

CHAR_TYPE

  public final static byte CHAR_TYPE
Primitive Codable type.

CHAR_ARRAY_TYPE

  public final static byte CHAR_ARRAY_TYPE
Primitive Codable type.

BYTE_TYPE

  public final static byte BYTE_TYPE
Primitive Codable type.

BYTE_ARRAY_TYPE

  public final static byte BYTE_ARRAY_TYPE
Primitive Codable type.

SHORT_TYPE

  public final static byte SHORT_TYPE
Primitive Codable type.

SHORT_ARRAY_TYPE

  public final static byte SHORT_ARRAY_TYPE
Primitive Codable type.

INT_TYPE

  public final static byte INT_TYPE
Primitive Codable type.

INT_ARRAY_TYPE

  public final static byte INT_ARRAY_TYPE
Primitive Codable type.

LONG_TYPE

  public final static byte LONG_TYPE
Primitive Codable type.

LONG_ARRAY_TYPE

  public final static byte LONG_ARRAY_TYPE
Primitive Codable type.

FLOAT_TYPE

  public final static byte FLOAT_TYPE
Primitive Codable type.

FLOAT_ARRAY_TYPE

  public final static byte FLOAT_ARRAY_TYPE
Primitive Codable type.

DOUBLE_TYPE

  public final static byte DOUBLE_TYPE
Primitive Codable type.

DOUBLE_ARRAY_TYPE

  public final static byte DOUBLE_ARRAY_TYPE
Primitive Codable type.

STRING_TYPE

  public final static byte STRING_TYPE
Primitive Codable type.

STRING_ARRAY_TYPE

  public final static byte STRING_ARRAY_TYPE
Primitive Codable type.

OBJECT_TYPE

  public final static byte OBJECT_TYPE
Primitive Codable type.

OBJECT_ARRAY_TYPE

  public final static byte OBJECT_ARRAY_TYPE
Primitive Codable type.

Methods

describeClassInfo

  public abstract void describeClassInfo(ClassInfo info)
Classes must be able to describe their schema to be encoded. They must call super.describeClassInfo() and then add their own information via info.addClass() and info.addField().
See Also:
ClassInfo

encode

  public abstract void encode(Encoder encoder) throws CodingException
Called to encode the object. The object should describe its state to the encoder.
See Also:
Encoder, Archiver

decode

  public abstract void decode(Decoder decoder) throws CodingException
Called immediately after the object's empty constructor, to restore the object's state using data contained in the decoder.
See Also:
Decoder, Unarchiver

finishDecoding

  public abstract void finishDecoding() throws CodingException
Because objects retrieved from decodeObject() might not have been fully initialized, this method gives newly created instances an opportunity to talk to other objects just after decode() has been called on all of them.
See Also:
Decoder, Unarchiver

All Packages  Class Hierarchy  This Package  Previous  Next  Index