/* File: DatumSpecification.java CVS Info: $Id: DatumSpecification.java,v 1.3 1998/01/28 08:28:19 mcgredo Exp $ Compiler: jdk 1.3 */ package mil.navy.nps.dis; import java.util.*; import java.io.*; import mil.navy.nps.util.*; import mil.navy.nps.disEnumerations.*; /** * Grouped datum information. * *@version 1.0 *@author Antonio Alexandre Rua (http://www.garfield.fe.up.pt/~alexrua) * *
Location: *
Web: * http://www.web3d.org/WorkingGroups/vrtp/mil/navy/nps/dis/DatumSpecification.java * *
or locally: * ~/mil/navy/nps/dis/DatumSpecification.java * *
Hierarchy Diagram: *
* *
Summary: *
The Datum Specification record is used to communicate grouped datum information. * *
Explanation: *
This record shall specify the number of Fixed Datums and Variable Datums, * as well as the records itself. * The Datum Specification is included in several PDU, as for example * the SetDataPDU, the CommentPdu...

* Note that our implementation might seem quite different from the representation of a Datum * Specification Record in the DIS format, in fact we take advantage of the power of java where * we can use elaborate structures "transparently". * * As with other things, the DatumSpecification record has to * know how to serialize and deserialize itself, clone itself, * and print out its values. * *

Note: * DatumSpecification doesn't exist in the on-line Dis Data Dictionary. * *
History: *
16Sep97 /Antonio Alexandre Rua /New *
8Dec97 /Ronan Fauglas /changes for documentation templates + complements in documentation *
11Dec97 /Ronan Fauglas /changed access methods: thisVariable() --> getThisVariable() * *
References: *
DIS-Java-VRML Working Group: * http://www.web3d.org/WorkingGroups/vrtp/dis-java-vrml/ *
DIS specification : IEEE 1278.1, Section 5.3.9 * *@see ProtocolDataUnit *@see PduElement *@see SerializationInterface */ public class DatumSpecification extends PduElement { /** *Elaborate structure that represents the list of fixed datums. *One fixed datum is made of Datum ID --a 32 bit long and a variable datum--a 32 bit long. */ protected Vector fixedDatumList; // list of fixed datums /** *Elaborate structure that represents the list of variable datums. *When written on the wire One variable datum is made of Datum ID --a 32 bit long, *a variable length --a 32 bit long, and of variable datum value--padding bit long. */ protected Vector variableDatumList; // List of variable datums /** *Constant value--size of a fixed data of the Datum Specification record (actually the 2 counters); here :sizeOf = 8 bytes. */ public static final int sizeOf = 8; // 8 bytes stands for fixed, counters /** *Default constructor. Creates two empty lists of data. */ public DatumSpecification() // default constructor { fixedDatumList = new Vector(); variableDatumList = new Vector(); return; } public void serialize(DataOutputStream outputStream) { /** Serialize our data out to the stream. We first call the superclass, so that all the data there is written out to the buffer first. Then we serialize each of our ivars to the stream, being careful about the order. */ UnsignedInt fixedDatumCount; // number of fixed datums UnsignedInt variableDatumCount; // number of variable datums Enumeration listContents; // easy way to loop thru vector // write out the number of fixed and variable datums. fixedDatumCount = new UnsignedInt(fixedDatumList.size()); variableDatumCount = new UnsignedInt(variableDatumList.size()); fixedDatumCount.serialize(outputStream); variableDatumCount.serialize(outputStream); // loop thru and write out all the elements of the list of fixed datums. listContents = fixedDatumList.elements(); while(listContents.hasMoreElements()) { FixedDatum aDatum = (FixedDatum)listContents.nextElement(); aDatum.serialize(outputStream); } // loop thru and write out all the elements of the list of variable datums. listContents = variableDatumList.elements(); while(listContents.hasMoreElements()) { VariableDatum aDatum = (VariableDatum)listContents.nextElement(); aDatum.serialize(outputStream); } return; } public void deSerialize(DataInputStream inputStream) { /** deserialize our data from the stream. We first call the superclass, so that all the data there is read into the buffer first. Then we deserialize each of our ivars to the stream, being careful about the order. */ int idx = 0; UnsignedInt variableDatumCount = new UnsignedInt(0), fixedDatumCount = new UnsignedInt(0); fixedDatumCount.deSerialize(inputStream); variableDatumCount.deSerialize(inputStream); // read in the correct number of fixed datums. for(idx = 0; idx < fixedDatumCount.longValue(); idx++) { FixedDatum aDatum = new FixedDatum(); aDatum.deSerialize(inputStream); fixedDatumList.addElement(aDatum); } // read in the correct number of variable datums. for(idx = 0; idx < variableDatumCount.longValue(); idx++) { VariableDatum aDatum = new VariableDatum(); aDatum.deSerialize(inputStream); variableDatumList.addElement(aDatum); } return; } public Object clone() { /** Clone the DatumSpecification, being careful to not share any pointers between the new object and the old object. */ DatumSpecification newDatumSpecification = (DatumSpecification)super.clone(); int fixedDatumCount; // number of fixedDatums int variableDatumCount; // number of variableDatums int idx; fixedDatumCount = fixedDatumList.size(); for(idx = 0; idx