Package org.acplt.oncrpc
Class XdrUnion
java.lang.Object
org.acplt.oncrpc.XdrUnion
- All Implemented Interfaces:
XdrAble
The abstract base class
XdrUnion
helps (de-)serializing
polymorphic classes. This class should not be confused with C unions in
general. Instead XdrUnion
is an object-oriented construct
which helps in deploying polymorphism. For examples on how to use this,
please take a look at the "ACPLTea Java Library" package, which is also
available from www.acplt.org/ks
. As a sidenote, the
serialization scheme implemented by XdrUnion
is only a question
of getting used to it: after serializing the type code of the polymorphic
class, the variant part is serialized first before the common part. This
behaviour stems from the ACPLT C++ Communication Library and has been
retained for compatibility reasons. As it doesn't hurt, you won't mind
anyway.
To use polymorphism with XDR streams, you'll have to derive your own base
class (let's call it foo
from XdrUnion
and implement the two methods
xdrEncodeCommon(XdrEncodingStream)
and
xdrDecodeCommon(XdrDecodingStream)
. Do not overwrite
the methods xdrEncode and xdrDecode!
Then, in your foo
-derived classes, like bar
and baz
, implement the other two methods
xdrEncodeVariant(XdrEncodingStream)
and
xdrDecodeVariant(XdrDecodingStream)
. In addition, implement
getXdrTypeCode()
to return an int, uniquely identifying your
class. Note that this identifier only needs to be unique within the scope
of your foo
class.
- Version:
- $Revision: 1.1.1.1 $ $Date: 2003/08/13 12:03:41 $ $State: Exp $ $Locker: $
- Author:
- Harald Albrecht
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract int
Returns the so-called type code which identifies a derived class when encoded or decoded.void
Decodes -- that is: deserializes -- an object from a XDR stream in compliance to RFC 1832.abstract void
Decodes -- that is: deserializes -- the common part of an object from a XDR stream in compliance to RFC 1832.abstract void
Decodes -- that is: deserializes -- the variant part of an object from a XDR stream in compliance to RFC 1832.void
Encodes -- that is: serializes -- an object into a XDR stream in compliance to RFC 1832.abstract void
Encodes -- that is: serializes -- the common part of an object into a XDR stream in compliance to RFC 1832.abstract void
Encodes -- that is: serializes -- the variant part of an object into a XDR stream in compliance to RFC 1832.
-
Constructor Details
-
XdrUnion
public XdrUnion()
-
-
Method Details
-
getXdrTypeCode
public abstract int getXdrTypeCode()Returns the so-called type code which identifies a derived class when encoded or decoded. Note that the type code is not globally unique, but rather it is only unique within the derived classes of a direct descend of XdrUnion. Iffoo
is derived fromXdrUnion
andfoo
is the base class forbar
andbaz
, then the type code needs only be unique betweenbar
andbaz
.- Returns:
- Type code identifying an object's class when encoding or decoding the object into or from a XDR stream.
-
xdrEncode
Encodes -- that is: serializes -- an object into a XDR stream in compliance to RFC 1832.- Specified by:
xdrEncode
in interfaceXdrAble
- Parameters:
xdr
- XDR stream to which information is sent for encoding.- Throws:
OncRpcException
- if an ONC/RPC error occurs.IOException
- if an I/O error occurs.
-
xdrDecode
Decodes -- that is: deserializes -- an object from a XDR stream in compliance to RFC 1832.- Specified by:
xdrDecode
in interfaceXdrAble
- Parameters:
xdr
- XDR stream from which decoded information is retrieved.- Throws:
OncRpcException
- if an ONC/RPC error occurs.IOException
- if an I/O error occurs.
-
xdrEncodeCommon
Encodes -- that is: serializes -- the common part of an object into a XDR stream in compliance to RFC 1832. Note that the common part is deserialized after the variant part.- Throws:
OncRpcException
- if an ONC/RPC error occurs.IOException
- if an I/O error occurs.
-
xdrDecodeCommon
Decodes -- that is: deserializes -- the common part of an object from a XDR stream in compliance to RFC 1832. Note that the common part is deserialized after the variant part.- Throws:
OncRpcException
- if an ONC/RPC error occurs.IOException
- if an I/O error occurs.
-
xdrEncodeVariant
Encodes -- that is: serializes -- the variant part of an object into a XDR stream in compliance to RFC 1832. Note that the variant part is deserialized before the common part.- Throws:
OncRpcException
- if an ONC/RPC error occurs.IOException
- if an I/O error occurs.
-
xdrDecodeVariant
Decodes -- that is: deserializes -- the variant part of an object from a XDR stream in compliance to RFC 1832. Note that the variant part is deserialized before the common part.- Throws:
OncRpcException
- if an ONC/RPC error occurs.IOException
- if an I/O error occurs.
-