Class XdrUnion

  • All Implemented Interfaces:
    XdrAble

    public abstract class XdrUnion
    extends java.lang.Object
    implements 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 
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XdrUnion

        public XdrUnion()
    • 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. If foo is derived from XdrUnion and foo is the base class for bar and baz, then the type code needs only be unique between bar and baz.
        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 interface XdrAble
        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 interface XdrAble
        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.