public interface Serializer
Title: Object Mediation Framework
Description: A general interface for all serializers.
A Serializer
is used by the Object Mediation Framework to marshal and unmarshal
objects to and from their persistence format or stream. It is expected that objects that are processed
by a serializer are Structured Data Objects
that conform to the basic interface that
provides a Serial Version Unique Identifier
, and other properties specific to the SDO.
While this makes the marshaling strategy more restrictive it allows the framework to assist in object
versioning, impact analysis and deployment.
A serializable data object must be defined as a known Semantic Type and all of its elements must be
registered in the Alias Map
used by the serializer. When an object is aliased with the
framework a generated or explicit semantic type is created and stamped with a Serial Unique
Identifier
that must match the actual implementing classes Serial Version UID. If a
supporting serializer class is generated it's serialVersionUID
must also match that of the implementation.
The restriction forces developers to design distributed systems in a more collaborative fashion.
The interface also provides a way to work with Unstructured Data Objects
in order
to allow users the flexibility of using any Plain Old Java Object. Unstructured objects are plain
Java objects (POJO) and the way that a given serializer handles these objects is implementation specific.
A POJO must still be registered as a known Semantic Type. However, how it's serialVersionUID
is handled or even if it is used is implementation specific.
As a general rule a serialVersionUID
is used by Structured Data Objects
to avoid a situation where data producers and consumers use different versions of the data object or it's
serializer. Regardless of the serial format used (XML, JSON, binary or other) any changes to data structure
that are not applied in a uniform fashion across producers and consumers will result in a brittle interface.
This fundamental problem is not solved by meta data (ie. XML, XSD, Schema) but rather by providing a tighter
control over interface versioning and object structure synchronization. The serialVersionUID
is
used by the framework to affect this type of control and assist in automated data format synchronization.
Implementers should take advantage of id generation and caching features of the Semantic Type interfaces
and include the id in the binary version of the data. However the actual usage is implementation specific and
not enforced for POJO.
Copyright: Copyright (c) 2009
Company: StreamScape Technologies
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
deserialize(byte[] buffer)
Deserializes instance of a Java object from byte array.
|
java.lang.Object |
deserialize(java.io.DataInputStream stream)
Deserializes instance of Java object from a
DataOutputStream . |
java.lang.Object |
deserialize(java.lang.String semanticType,
byte[] buffer)
Deserializes instance of a Java object from byte array.
|
java.lang.Object |
deserialize(java.lang.String semanticType,
java.io.DataInputStream stream)
Deserializes instance of Java object from a
DataOutputStream . |
void |
destroy()
Perform clean up and remove any structures that may have reserved resources on behalf of this serializer.
|
java.lang.ClassLoader |
getClassLoader()
Returns the class loader associated with this serializer.
|
java.lang.String |
getName()
Returns the name of the serializer.
|
void |
serialize(java.lang.Object obj,
java.io.DataOutputStream stream)
Serializes instance of a Java object into
DataOutputStream . |
void |
serialize(java.lang.String semanticType,
java.lang.Object obj,
java.io.DataOutputStream buffer)
Serializes instance of a Java object into
DataOutputStream . |
void |
setClassLoader(java.lang.ClassLoader loader)
Sets the class loader for this serializer, ensuring that any operations will find the classes that they need
to work on.
|
java.lang.String getName()
void serialize(java.lang.Object obj, java.io.DataOutputStream stream) throws SerializerException
DataOutputStream
. The object may be an
instance of StructuredDataObject
or a standard Java object. The actual stream format is
implementation specific. The object must be defined as a known Semantic Type and all of its elements
must be registered in the Alias Map
.obj
- the object to be serialized.stream
- the stream containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.void serialize(java.lang.String semanticType, java.lang.Object obj, java.io.DataOutputStream buffer) throws SerializerException
DataOutputStream
. The object may be an
instance of StructuredDataObject
or a standard Java object. The actual stream format is
implementation specific. The object must be defined as a known Semantic Type and all of its elements
must be registered in the Alias Map
.
This method allows for a specific semantic type to be specified, which results in a form of protected casting for
the object based on the Alias Map
. It is therefore possible to serialize varied objects that implement
the same interface.
semanticType
- the semantic type of the specified object.obj
- the object to be serialized.stream
- the stream containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.java.lang.Object deserialize(java.lang.String semanticType, byte[] buffer) throws SerializerException
Alias Map
. The actual instance
creation is implementation specific and may be JVM dependent. Framework serializers may not require the presence of a
null constructor.
The method allows users to specify a particular semantic type, thereby engaging in forced casting of the deserialized object.
semanticType
- the semantic type of the specified object.buffer
- the buffer containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.java.lang.Object deserialize(java.lang.String semanticType, java.io.DataInputStream stream) throws SerializerException
DataOutputStream
. The stream is a byte representation of an
object in its serialized form. Meaning that the actual format of the object may be binary or text or XML or whatever
format dictated by the serializer. The actual binary format is implementation specific. This method requires that the
supplied Semantic Type and all of its elements must be registered in the Alias Map
. The actual
instance creation is implementation specific and may depend on the specific JVM. Framework serializers may not require
the presence of a null constructor.
The method allows users to specify a particular semantic type, thereby engaging in forced casting of the deserialized object.
semanticType
- the semantic type of the specified object.stream
- the buffer containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.java.lang.Object deserialize(byte[] buffer) throws SerializerException
Alias Map
.
The actual instance creation is implementation specific. Framework serializers may not require the presence of a
null constructor.buffer
- the buffer containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.java.lang.Object deserialize(java.io.DataInputStream stream) throws SerializerException
DataOutputStream
. The stream is a byte representation of an
object in its serialized form. Meaning that the actual format of the object may be binary or text or XML or whatever
format dictated by the serializer. The actual binary format is implementation specific. This method requires that the
object must be defined as a known Semantic Type and all of its elements must be registered in the Alias Map
.
The actual instance creation is implementation specific and may depend on the specific JVM. Framework serializers may
not require the presence of a null constructor.stream
- the stream containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.void destroy()
void setClassLoader(java.lang.ClassLoader loader)
Semantic Types
may have been registered (aliased) at startup whose classes are not reachable by the
system thread's class loader. It is possible to set the class loader for the duration
of a serialization or deserialization operation allowing Serializer to access the needed
loader and it's classes. However, it is also possible to erroneously supply an isolated
or non-chained loader that makes the underlying classes required by Serializer internals
inaccessible.loader
- the loader to be set.java.lang.ClassLoader getClassLoader()
Copyright © 2015-2024 StreamScape Technologies. All rights reserved.