ds.ov2.util
Class Serializable_array

java.lang.Object
  extended by ds.ov2.util.Serializable_array
All Implemented Interfaces:
APDU_Serializable
Direct Known Subclasses:
APDU_short_array, Bignat_array, Host_modulus, Host_signature, Host_vector, Modulus, Signature

public abstract class Serializable_array
extends Object
implements APDU_Serializable

Abstract class providing the APDU_Serializable interface for arrays of APDU_Serializable's. This abstract class implements the APDU_Serializable interface for data types that contain several APDU_Serializable's of possibly different type or size. Clients only need to override the get_array(), and the is_compatible_with method. Overriding get_length() is necessary for clients that can change their size for testing purposes. Overriding size() is optional. Overriding to_byte_array and from_byte_array makes not much sense, execpt for special purposes, such as performing side effects before serialization starts or after deserialization finshes.

CPP Preprocessing
This class uses the following cpp defines: PACKAGE, PUBLIC, ASSERT
Execution Environment:
host, card
Author:
Hendrik Tews
Version:
$Revision: 1.14 $
Last Commit:
$Date: 2009-06-19 20:37:37 $ by $Author: tews $

Constructor Summary
protected Serializable_array()
          Disabled constructor.
 
Method Summary
 short from_byte_array(short len, short this_index, byte[] byte_array, short byte_index)
          Deserialization of this object for the OV-chip protocol layer.
protected abstract  APDU_Serializable[] get_array()
          Array of objects to (de-)serialize.
 short get_length()
          Length of the serializable array.
 boolean is_compatible_with(Object o)
          Compatibility check for the OV-chip protocol layer.
 short size()
          Size in bytes necessary to send or receive this object via the OV-chip protocol layer, see APDU_Serializable.size().
 short to_byte_array(short len, short this_index, byte[] byte_array, short byte_index)
          Serialization of this object for the OV-chip protocol layer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Serializable_array

protected Serializable_array()
Disabled constructor. Creation possible only for subclasses.

Method Detail

get_array

protected abstract APDU_Serializable[] get_array()
Array of objects to (de-)serialize. This method might get called serveral times per (de-)serializtion. The returned array must contain at least one element. Further it must not contain any null references.

Clients must override this method.

Returns:
array of objects to (de-)serialize

get_length

public short get_length()
Length of the serializable array. This method must be used consistently instead of get_array().length to determine the size of the array returned from get_array(). The returned value must be greater than zero and less than or equal to the actual array size.

The default implementation returns get_array().length. By overriding clients can provide the illusion of a shorter array without the need of reallocating this shorter array.

Returns:
effictive size of the array returned by get_array()

size

public short size()
Size in bytes necessary to send or receive this object via the OV-chip protocol layer, see APDU_Serializable.size(). The default implementation used Misc.length_of_serializable_array to determine the size.

Can be overriden for homegenous arrays that can determine their size more efficiently.

Specified by:
size in interface APDU_Serializable
Returns:
size in bytes

is_compatible_with

public boolean is_compatible_with(Object o)
Compatibility check for the OV-chip protocol layer. See the compatibility check explanations and also APDU_Serializable.is_compatible_with.

The default implementation returns false, which is the right value for all host data types. Card data types must override this method.

Specified by:
is_compatible_with in interface APDU_Serializable
Parameters:
o - actual argument or result
Returns:
true if this (the declared argument or result) is considered binary compatible with o.

to_byte_array

public short to_byte_array(short len,
                           short this_index,
                           byte[] byte_array,
                           short byte_index)
Serialization of this object for the OV-chip protocol layer. See APDU_Serializable.to_byte_array.

Overriding makes little sense, except when side effects must be scheduled before the start or after the end of serialization.

Specified by:
to_byte_array in interface APDU_Serializable
Parameters:
len - available space in byte_array
this_index - number of bytes that have already been written in preceeding calls
byte_array - data array to serialize the state into
byte_index - index in byte_array
Returns:
the number of bytes actually written, except for the case where serialization finished by writing precisely len bytes, in this case len + 1 is returned.

from_byte_array

public short from_byte_array(short len,
                             short this_index,
                             byte[] byte_array,
                             short byte_index)
Deserialization of this object for the OV-chip protocol layer. See APDU_Serializable.from_byte_array.

Overriding makes little sense, except when side effects must be scheduled before the start or after the end of serialization.

Specified by:
from_byte_array in interface APDU_Serializable
Parameters:
len - available data in byte_array
this_index - number of bytes that have already been read in preceeding calls
byte_array - data array to deserialize from
byte_index - index in byte_array
Returns:
the number of bytes actually read, except for the case where deserialization finished by reading precisely len bytes, in this case len + 1 is returned.