/* File: FixedDatum.java CVS Info: $Id: FixedDatum.java,v 1.2 1998/01/27 18:44:16 mcgredo Exp $ Compiler: jdk 1.3 */ package mil.navy.nps.dis; import mil.navy.nps.util.*; // General-purpose utilities import mil.navy.nps.disEnumerations.*; // Enumerations for DIS import java.io.*; // input/output library import java.util.*; // utilities /** * Special data record subclass of PDUElement. * *@version 1.0 *@author Don McGregor (http://www.npsnet.org/~mcgredo) * *
* * This is a subclass of the PduElement class, the abstract class that all parts of a * PDU inherit from. It knows how to serialize, deserialize, and clone itself. It * is described on pp 108-109 in the DIS standard.
* *
sizeOf = 8 bytes
.
*/
public static final int sizeOf = 8; // size, in bytes, of a serialized fixed datum
/**
*Default constructor--fills with zeros for all values.
*/
public FixedDatum() // constructor
{
fixedDatumID = 0;
value = 0;
}
/**
*Constructs a new FixedDatum with the values specfied in parameters.
*
*@param pFixedDatumID the value of fixed Datum Identifier
*@param pValue the value of the Fixed Datum
*/
public FixedDatum(int pFixedDatumID, int pValue) // constructor
{
fixedDatumID = pFixedDatumID;
value = pValue;
}
public Object clone()
{
// make a copy of the object. We don't have any objects here, so we can
// just do a straight copy.
FixedDatum newFixedDatum = new FixedDatum();
newFixedDatum.setFixedDatumID(fixedDatumID);
newFixedDatum.setValue(value);
return newFixedDatum;
}
/**
*@exception RuntimeException when IO Error occurs.
*/
public void serialize(DataOutputStream outputStream)
{
try
{
outputStream.writeInt(fixedDatumID);
outputStream.writeInt(value);
}
catch(IOException ioException) // catch-all for all IO exceptions in the above code
{
throw new
RuntimeException("Exception in FixedDatum. Error serializing unit.");
}
return;
}
/**
*@exception RuntimeException when IO Error occurs.
*/
public void deSerialize(DataInputStream inputStream)
{
// no need to call super, since there are no ivars in the superclass.
try
{
fixedDatumID = inputStream.readInt();
value = inputStream.readInt();
}
catch(IOException ioException) // catch-all for all IO exceptions in the above code
{
throw new
RuntimeException("Exception in FixedDatum. Error deSerializing unit.");
}
return;
}
public int length()
{
return sizeOf; // 8 bytes long
}
public void printValues(int indentLevel, PrintStream printStream)
{
// print the values of the object out, with correct level of
// indentation on the page.
StringBuffer indent = ProtocolDataUnit.getPaddingOfLength(indentLevel);
int idx, superclassIndent = indentLevel;
printStream.println(indent + "fixedDatumID: " + fixedDatumID);
printStream.println(indent + "value: " + value);
return;
}
// accessor methods
public int getFixedDatumID()
{ return fixedDatumID;
}
public void setFixedDatumID(int pFixedDatumID)
{ fixedDatumID = pFixedDatumID;
}
public int getValue()
{ return value;
}
public void setValue(int pValue)
{ value = pValue;
}
} // end of class FixedDatum