|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Serializer
A Serializer can translate a SandMessage into a stream, and read a stream to return a SandMessage. Streams were chosen over Strings to avoid requiring extra work when writing directly to a file or other display.
Streams are, however, fairly low level things. And because the same
Serializer may be used across several different kinds of streams, it is
not possible for the implementation to know how to translate the stream
into the appropriate higher level class suitable for doing its work.
As an example, consider the number of different types of output an XML
serializer might be directed to write to. All character-based, but
definitely different classes to give to a PrintWriter or BufferedReader
on construction.
Unfortunately, if the Serializer interface is declared using
higher level classes like PrintWriter and BufferedReader, then the
implementation is constrained to being character-based. Since
binary serialization is totally reasonable, that's not really a
viable alternative. Not to mention that a stream backed by a
String doesn't need to be buffered, but that's another issue.
This leaves not much room for a general declaration. Use of a
Serializer requires knowledge of what kind of format it deals with,
and implementation of a Serializer requires higher level access
protocols to be applied across a variety of stream types.
If we could ask any stream about its capabilities (whether it was
buffered, supported an un-read operation etc), and if there were
a class of reader/writer interface that supported line operations
but ignored the line concept for binary, then we'd have a chance.
But right now from the JDK1.4.0 things look pretty ugly.
The JDK writes code for each object based on an interface
declaration (e.g. Serializable), and then calls fixed methods with a
specific stream. The calls are made by the application, there is no
formal entity that has this responsibility, which is what we need.
It would of course be extremely convenient if the Serializer
would accomplish its work through static methods, but the java
language does not provide any mechanism for this declaration.
It is highly recommended that any implementation define it's
methods as completely re-entrant, so that a class can re-use
a serializer instance, given that it must now create one.
So the bottom line is that there is not much that can be
declared across the board for all serializers. So this base
interface doesn't declare anything that might get in the way.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||