javax.media.jai.remote
Class SerializerFactory

java.lang.Object
  |
  +--javax.media.jai.remote.SerializerFactory

public final class SerializerFactory
extends Object

A utility class which provides factory methods for obtaining Serializer instances.

The Serializers are maintained in a centralized repository which is organized based on the classes supported by the Serializers and the order in which the Serializers were registered. Convenience methods similar to those defined in the Serializer class are also provided. These enable functionality equivalent to a single Serializer which supports all the classes supported by the aggregate of all Serializers resident in the repository.

By default Serializers for the following classes are registered by JAI:

Since:
JAI 1.1
See Also:
SerializableState, Serializer, Serializable

Constructor Summary
protected SerializerFactory()
           
 
Method Summary
static Class getDeserializedClass(Class c)
          Determines the Class of which the deserialized form of the supplied Class will be an instance.
static Serializer getSerializer(Class c)
          Retrieves a Serializer for a given class c.
static Serializer[] getSerializers(Class c)
          Retrieves an array of all Serializers currently resident in the repository which directly support the specified Class.
static SerializableState getState(Object o)
          A convenience wrapper around getState(Object o, RenderingHints h) with the RenderingHints parameter h set to null.
static SerializableState getState(Object o, RenderingHints h)
          Converts an object into a state-preserving object which may be serialized.
static Class[] getSupportedClasses()
          Returns an array listing all classes and interfaces on which the isSupportedClass() method of this class may be invoked and return true.
static boolean isSupportedClass(Class c)
          Whether there is currently resident in the repository a Serializer the getSupportedClass() method of which returns a value equal to the parameter supplied to this method according to equals().
static void registerSerializer(Serializer s)
          Adds a Serializer to the repository.
static void unregisterSerializer(Serializer s)
          Removes a Serializer from the repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializerFactory

protected SerializerFactory()
Method Detail

registerSerializer

public static void registerSerializer(Serializer s)
Adds a Serializer to the repository.
Parameters:
s - The Serializers to be added to the repository.
Throws:
IllegalArgumentException - if s is null

unregisterSerializer

public static void unregisterSerializer(Serializer s)
Removes a Serializer from the repository.
Parameters:
s - The Serializers to be removed from the repository.
Throws:
IllegalArgumentException - if s is null

getSerializers

public static Serializer[] getSerializers(Class c)
Retrieves an array of all Serializers currently resident in the repository which directly support the specified Class. Serializers which support a superclass of the specified class and permit subclass serialization will not be included.
Parameters:
c - The class for which Serializers will be retrieved.
Throws:
IllegalArgumentException - if c is null.

getSerializer

public static Serializer getSerializer(Class c)
Retrieves a Serializer for a given class c. If more than one Serializer is available for the class then the most recently registered Serializer will be returned. If no registered Serializer exists which directly supports the specified class, i.e., one for which the getSupportedClass() returns a value equal to the specified class, then a Serializer may be returned which is actually registered against a superclass but permits subclass serialization.
Parameters:
c - The class for which Serializers will be retrieved.
Returns:
A Serializer which supports the specified class. or null if none is available.
Throws:
IllegalArgumentException - if c is null.
See Also:
BandedSampleModel, ComponentSampleModel

isSupportedClass

public static boolean isSupportedClass(Class c)
Whether there is currently resident in the repository a Serializer the getSupportedClass() method of which returns a value equal to the parameter supplied to this method according to equals().
Parameters:
c - The class to be tested for compatibility.
Returns:
Whether the specified class is directly supported.
Throws:
IllegalArgumentException - if c is null

getSupportedClasses

public static Class[] getSupportedClasses()
Returns an array listing all classes and interfaces on which the isSupportedClass() method of this class may be invoked and return true.
Returns:
An array of all supported classes and interfaces.

getDeserializedClass

public static Class getDeserializedClass(Class c)
Determines the Class of which the deserialized form of the supplied Class will be an instance. Specifically, this method returns the Class of the Object returned by invoking getObject() on the SerializableState returned by getState() after the state object has been serialized and deserialized. The returned value will equal the supplied argument unless there is no Serializer explicitly registered for this class but there is a Serializer registered for a superclass with a permitsSubclasses() method that returns true.
Parameters:
The - Class for which the deserialized class type is requested.
Returns:
The deserialized Class or null.
Throws:
IllegalArgumentException - if c is null

getState

public static SerializableState getState(Object o,
                                         RenderingHints h)
Converts an object into a state-preserving object which may be serialized. If the class of the object parameter is supported explicitly, i.e., isSupportedClass(o.getClass()) returns true, then the object will be converted into a form which may be deserialized into an instance of the same class. If the class is not supported explicitly but implements one or more supported interfaces, then it will be converted into a form which may be deserialized into an instance of an unspecified class which implements all interfaces which are both implemented by the class of the object and supported by some Serializer currently resident in the repository. If the object is null, the returned SerializableState will return null from its getObject() method and java.lang.Object.class from its getObjectClass() method.
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 non-null and either isSupportedClass(o.getClass()) returns false, or o is not an instance of a class supported by a Serializer in the repository or which implements at least one interface supported by some Serializers in the repository.

getState

public static final SerializableState getState(Object o)
A convenience wrapper around getState(Object o, RenderingHints h) with the RenderingHints parameter h set to null.