ostore.util
Class TypeTable

java.lang.Object
  |
  +--ostore.util.TypeTable

public class TypeTable
extends Object

Allows for the creation of new QuickSerializable objects from their type codes and a byte array. This class facilitates the de-serialization process by providing what are, in effect, virtual constructors.

Version:
"$Id: TypeTable.java,v 1.22 2002/03/28 02:29:11 ravenben Exp $"
Author:
Sean C. Rhea
See Also:
QuickSerializable, QSException, Types

Inner Class Summary
static class TypeTable.DuplicateTypeCode
          An exception class thrown when a given type code is passed to register_type(java.lang.String, int) for the second time with a different Java type than the original call.
static class TypeTable.NoSuchTypeCode
          An exception class thrown when a request to new_object(int, byte[], int[]) passes in an un-registered type code.
static class TypeTable.NotQuickSerializable
          An exception class thrown when the object named by the parameter name to register_type(java.lang.String, int) does not refer to a class which implements QuickSerializeable.
 
Constructor Summary
TypeTable()
           
 
Method Summary
static QuickSerializable new_object(int type_code, byte[] data, int[] offset)
          Constructs a new object of the type associated with the given type code through a call to register_type(java.lang.String, int) using the data in the given byte array.
static QuickSerializable new_object(long type_code, byte[] data, int[] offset)
           
static void register_type(String name)
           
static void register_type(String name, int type_code)
          Register a new type, so that new_object(int, byte[], int[]) can be called later.
static long type_code(QuickSerializable obj)
           
static long type_code(String class_name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeTable

public TypeTable()
Method Detail

register_type

public static void register_type(String name,
                                 int type_code)
                          throws TypeTable.DuplicateTypeCode,
                                 ClassNotFoundException,
                                 NoSuchMethodException,
                                 TypeTable.NotQuickSerializable
Register a new type, so that new_object(int, byte[], int[]) can be called later.
Parameters:
name - the fully qualified name of the Java class being registered
type_code - the type code to associate with this class
Throws:
TypeTable.DuplicateTypeCode - if the given type code has already been associated with another class
ClassNotFoundException - if the given class name cannot be resolved to any loadable class by the JVM
NoSuchMethodException - if the given class does not have a contructor of the form Foo (byte [] data, int [] offset) or Foo (byte [] data, int [] offset) throws QSException
TypeTable.NotQuickSerializable - if the given class is not a subtype of QuickSerializable

register_type

public static void register_type(String name)
                          throws TypeTable.DuplicateTypeCode,
                                 ClassNotFoundException,
                                 NoSuchMethodException,
                                 TypeTable.NotQuickSerializable

new_object

public static QuickSerializable new_object(int type_code,
                                           byte[] data,
                                           int[] offset)
                                    throws QSException
Constructs a new object of the type associated with the given type code through a call to register_type(java.lang.String, int) using the data in the given byte array.
Parameters:
type_code - the type code of the class to construct
data - an array of bytes containing an encoding of an object of the given type (!= null)
offset - a single element array which on function entry should contain the starting index into the data array to begin reading from, and which on function exit will be incremented by the number of bytes read.
Throws:
QSException - if the constructor for the given type throws one

new_object

public static QuickSerializable new_object(long type_code,
                                           byte[] data,
                                           int[] offset)
                                    throws QSException

type_code

public static long type_code(QuickSerializable obj)

type_code

public static long type_code(String class_name)