edu.UCL.xmiddle.controller
Class DataPacket

java.lang.Object
  |
  +--edu.UCL.xmiddle.controller.DataPacket
All Implemented Interfaces:
Data

public class DataPacket
extends java.lang.Object
implements Data

This class represents a data packet, either received from or being sent to another host.

Since:
1.0
See Also:
Data

Field Summary
 
Fields inherited from interface edu.UCL.xmiddle.framework.controller.Data
RECEIVED, TO_SEND
 
Constructor Summary
DataPacket(Host host, boolean type, byte[] data)
          Creates a new DataPacket
DataPacket(Host host, boolean type, org.w3c.dom.Node data)
          Creates a new DataPacket
DataPacket(Host host, boolean type, java.lang.String data)
          Creates a new DataPacket
 
Method Summary
 void appendData(byte[] data)
          Append the given information to the current data.
 void appendData(byte[] data, int offset, int length)
          Append the given information to the current data.
 void appendData(org.w3c.dom.Node data)
          Append the given information to the current data.
 void appendData(java.lang.String data)
          Append the given information to the current data.
 java.lang.Object getCalculatedCheck()
          Returns the check that is calculated from the data.
 java.lang.Object getCheck()
          Retutns the check that is bound with the data.
 byte[] getData()
          Returns the data of the packet
 byte[][] getData(int segmentSize)
          Returns the data contained as numbered segments of the given size
 Host getHost()
          Returns the host to which this package is targetted or from which this packet was received
 boolean getType()
          Retrieves the type of the packet
 void init(Host host, boolean type)
           
 void prependData(byte[] data)
          Prepend the given information to the current data.
 void prependData(byte[] data, int offset, int length)
          DPrepend the given information to the current data.
 void prependData(org.w3c.dom.Node data)
          Prepend the given information to the current data.
 void prependData(java.lang.String data)
          Prepend the given information to the current data.
 void setData(byte[] data)
          Sets the data that this packet contains
 void setData(byte[] data, int offset, int length)
          Sets the data that this packet contains
 void setData(org.w3c.dom.Node data)
          Sets the data that this packet contains
 void setData(java.lang.String data)
          Sets the data that this packet contains
 void setHost(Host host)
          Sets the host to which this packet is destined to.
 void setType(boolean type)
          Sets the type of the packet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataPacket

public DataPacket(Host host,
                  boolean type,
                  byte[] data)
Creates a new DataPacket

Parameters:
host - a Host value
type - either TO_SEND or RECEIVED
data - a byte[] value

DataPacket

public DataPacket(Host host,
                  boolean type,
                  java.lang.String data)
Creates a new DataPacket

Parameters:
host - a Host value
type - either TO_SEND or RECEIVED
data - a String value

DataPacket

public DataPacket(Host host,
                  boolean type,
                  org.w3c.dom.Node data)
Creates a new DataPacket

Parameters:
host - a Host value
type - either TO_SEND or RECEIVED
data - a Node value
Method Detail

setData

public void setData(byte[] data)
Description copied from interface: Data
Sets the data that this packet contains

Specified by:
setData in interface Data
Parameters:
data - a byte[] value

setData

public void setData(byte[] data,
                    int offset,
                    int length)
Description copied from interface: Data
Sets the data that this packet contains

Specified by:
setData in interface Data
Parameters:
data - a byte[] value
offset - from offset
length - to offset+length

setData

public void setData(java.lang.String data)
Description copied from interface: Data
Sets the data that this packet contains

Specified by:
setData in interface Data
Parameters:
data - a String value

init

public void init(Host host,
                 boolean type)

getData

public byte[] getData()
Description copied from interface: Data
Returns the data of the packet

Specified by:
getData in interface Data
Returns:
the data, stored as a byte[] value

setHost

public void setHost(Host host)
Description copied from interface: Data
Sets the host to which this packet is destined to.

Specified by:
setHost in interface Data
Parameters:
host - is the target host.

getHost

public Host getHost()
Description copied from interface: Data
Returns the host to which this package is targetted or from which this packet was received

Specified by:
getHost in interface Data
Returns:
a Host value

getType

public boolean getType()
Description copied from interface: Data
Retrieves the type of the packet

Specified by:
getType in interface Data
Returns:
either TO_SEND or RECEIVED

setType

public void setType(boolean type)
Description copied from interface: Data
Sets the type of the packet. It can either be TO_SEND or RECEIVED

Specified by:
setType in interface Data
Parameters:
type - the type of the packet

setData

public void setData(org.w3c.dom.Node data)
Description copied from interface: Data
Sets the data that this packet contains

Specified by:
setData in interface Data
Parameters:
data - a Node value

getData

public byte[][] getData(int segmentSize)
Description copied from interface: Data
Returns the data contained as numbered segments of the given size

Specified by:
getData in interface Data
Parameters:
segmentSize - the maximum size of each segment (in bytes). The last segment returned could possibly contain less bytes - It is up to the caller to check this.
Returns:
the data are returned in an array of byte arrays, of the specified segment size

getCheck

public java.lang.Object getCheck()
Description copied from interface: Data
Retutns the check that is bound with the data.

Specified by:
getCheck in interface Data
Returns:
an Object value

getCalculatedCheck

public java.lang.Object getCalculatedCheck()
Description copied from interface: Data
Returns the check that is calculated from the data. If the data is RECEIVED and getCalculatedCheck() does not match getCheck then there has been a transmission error.

Specified by:
getCalculatedCheck in interface Data
Returns:
an Object value

appendData

public void appendData(byte[] data)
Description copied from interface: Data
Append the given information to the current data.

Specified by:
appendData in interface Data
Parameters:
data - a byte[] value

prependData

public void prependData(byte[] data)
Description copied from interface: Data
Prepend the given information to the current data.

Specified by:
prependData in interface Data
Parameters:
data - a byte[] value

appendData

public void appendData(byte[] data,
                       int offset,
                       int length)
Description copied from interface: Data
Append the given information to the current data.

Specified by:
appendData in interface Data
Parameters:
data - a byte[] value
offset - from offset
length - to offset+length

prependData

public void prependData(byte[] data,
                        int offset,
                        int length)
Description copied from interface: Data
DPrepend the given information to the current data.

Specified by:
prependData in interface Data
Parameters:
data - a byte[] value
offset - from offset
length - to offset+length

appendData

public void appendData(java.lang.String data)
Description copied from interface: Data
Append the given information to the current data.

Specified by:
appendData in interface Data
Parameters:
data - a String value

prependData

public void prependData(java.lang.String data)
Description copied from interface: Data
Prepend the given information to the current data.

Specified by:
prependData in interface Data
Parameters:
data - a String value

appendData

public void appendData(org.w3c.dom.Node data)
Description copied from interface: Data
Append the given information to the current data.

Specified by:
appendData in interface Data
Parameters:
data - a Node value

prependData

public void prependData(org.w3c.dom.Node data)
Description copied from interface: Data
Prepend the given information to the current data.

Specified by:
prependData in interface Data
Parameters:
data - a Node value