/* 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) * *
* 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. * *
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