javax.media.jai.remote
Interface Serializer


public interface Serializer

An interface to be implemented by classes which are capable of converting an instance of a supported class into a state representation of the object which is serializable. Supported classes may in fact be classes or interfaces.

When possible, classes (not interfaces) should be supported explicitly, i.e., the getObjectClass() method of the SerializableState returned by getState(Object) should return the same value which would be returned by invoking getClass() on the object passed to getState(Object). In particular, whenever feasible a Serializer should not be used to serialize a given object into a form which when deserialized would yield an instance of the superclass of the class of which the object is an instance. When it is not possible to provide a class-specific Serializer, such as when a factory class generate subclasses of itself via factory methods, then permitsSubclasses() should return true; in the case of class-specific Serializers it should return false.

Since:
JAI 1.1
See Also:
SerializableState, Serializable

Method Summary
 SerializableState getState(Object o, RenderingHints h)
          Converts an object into a state-preserving object which may be serialized.
 Class getSupportedClass()
          Returns the class or interface which is supported by this Serializer.
 boolean permitsSubclasses()
          Returns true if and only if it is legal for this Serializer to be used to serialize a subclass.
 

Method Detail

getSupportedClass

public Class getSupportedClass()
Returns the class or interface which is supported by this Serializer.

Returns:
The supported Class.

permitsSubclasses

public boolean permitsSubclasses()
Returns true if and only if it is legal for this Serializer to be used to serialize a subclass. In general this method should return false, i.e., a specific Serializer should be registered explicitly for each class. In some cases this is however not expedient. An example of this is a Serializer of classes created by a factory class: the exact subclasses may not be known but sufficient information may be able to be extracted from the subclass instance to permit its serialization by the Serializer registered for the factory class.


getState

public SerializableState getState(Object o,
                                  RenderingHints h)
Converts an object into a state-preserving object which may be serialized. If the value returned by getSupportedClass() is a class, i.e., not an interface, then the parameter of getState() should be an instance of that class; if getSupportedClass() returns an interface, then the parameter of getState() should implement that interface. If the apposite condition is not satisfied then an IllegalArgumentException will be thrown.

If the class of the parameter is supported explicitly, i.e., is an instance of the class returned by getSupportedClass(), then the object returned by the getObject() method of the generated SerializableState will be an instance of the same class. If getSupportedClass() returns an interface which the class of the parameter implements, then the object returned by the getObject() method of the generated SerializableState will be an instance of an unspecified class which implements that interface.

Parameters:
o - The object to be converted into a serializable form.
h - Configuration parameters the exact nature of which is Serializer-dependent. If null, reasonable default settings should be used.
Returns:
A serializable form of the supplied object.
Throws:
IllegalArgumentException - if o is null, the supported class is an interface not implemented by the class of which o is an instance, or the supported class is not an interface and getSupportedClass().equals(o.getClass()) returns false.