Package org.acplt.oncrpc
Class XdrUnion
- java.lang.Object
-
- org.acplt.oncrpc.XdrUnion
-
- All Implemented Interfaces:
XdrAble
public abstract class XdrUnion extends java.lang.Object implements XdrAble
The abstract base classXdrUnion
helps (de-)serializing polymorphic classes. This class should not be confused with C unions in general. InsteadXdrUnion
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 fromwww.acplt.org/ks
. As a sidenote, the serialization scheme implemented byXdrUnion
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
fromXdrUnion
and implement the two methodsxdrEncodeCommon(XdrEncodingStream)
andxdrDecodeCommon(XdrDecodingStream)
. Do not overwrite the methods xdrEncode and xdrDecode!Then, in your
foo
-derived classes, likebar
andbaz
, implement the other two methodsxdrEncodeVariant(XdrEncodingStream)
andxdrDecodeVariant(XdrDecodingStream)
. In addition, implementgetXdrTypeCode()
to return an int, uniquely identifying your class. Note that this identifier only needs to be unique within the scope of yourfoo
class.- Version:
- $Revision: 1.1.1.1 $ $Date: 2003/08/13 12:03:41 $ $State: Exp $ $Locker: $
- Author:
- Harald Albrecht
-
-
Constructor Summary
Constructors Constructor Description XdrUnion()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
getXdrTypeCode()
Returns the so-called type code which identifies a derived class when encoded or decoded.void
xdrDecode(XdrDecodingStream xdr)
Decodes -- that is: deserializes -- an object from a XDR stream in compliance to RFC 1832.abstract void
xdrDecodeCommon(XdrDecodingStream xdr)
Decodes -- that is: deserializes -- the common part of an object from a XDR stream in compliance to RFC 1832.abstract void
xdrDecodeVariant(XdrDecodingStream xdr)
Decodes -- that is: deserializes -- the variant part of an object from a XDR stream in compliance to RFC 1832.void
xdrEncode(XdrEncodingStream xdr)
Encodes -- that is: serializes -- an object into a XDR stream in compliance to RFC 1832.abstract void
xdrEncodeCommon(XdrEncodingStream xdr)
Encodes -- that is: serializes -- the common part of an object into a XDR stream in compliance to RFC 1832.abstract void
xdrEncodeVariant(XdrEncodingStream xdr)
Encodes -- that is: serializes -- the variant part of an object into a XDR stream in compliance to RFC 1832.
-
-
-
Method Detail
-
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
public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, java.io.IOException
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.java.io.IOException
- if an I/O error occurs.
-
xdrDecode
public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, java.io.IOException
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.java.io.IOException
- if an I/O error occurs.
-
xdrEncodeCommon
public abstract void xdrEncodeCommon(XdrEncodingStream xdr) throws OncRpcException, java.io.IOException
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.java.io.IOException
- if an I/O error occurs.
-
xdrDecodeCommon
public abstract void xdrDecodeCommon(XdrDecodingStream xdr) throws OncRpcException, java.io.IOException
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.java.io.IOException
- if an I/O error occurs.
-
xdrEncodeVariant
public abstract void xdrEncodeVariant(XdrEncodingStream xdr) throws OncRpcException, java.io.IOException
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.java.io.IOException
- if an I/O error occurs.
-
xdrDecodeVariant
public abstract void xdrDecodeVariant(XdrDecodingStream xdr) throws OncRpcException, java.io.IOException
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.java.io.IOException
- if an I/O error occurs.
-
-