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.43 2003/12/07 22:35:07 srhea Exp $"
Author:
Sean C. Rhea
See Also:
QuickSerializable, QSException, Types

Nested Class Summary
static class TypeTable.DuplicateTypeCode
          An exception class thrown when a given type code is passed to register_type(java.lang.String) 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(ostore.util.InputBuffer) 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) does not refer to a class which implements QuickSerializable.
 
Constructor Summary
TypeTable()
           
 
Method Summary
static QuickSerializable new_object(InputBuffer buffer)
          Constructs a new object out of an InputBuffer.
static QuickSerializable new_object(long 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) using the data in the given byte array.
static void register_type(Class this_class)
           
static void register_type(String name)
          Register a new type, so that new_object(ostore.util.InputBuffer) can be called later.
static Class type_code_to_class(long type_code)
           
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)
                          throws TypeTable.DuplicateTypeCode,
                                 ClassNotFoundException,
                                 NoSuchMethodException,
                                 TypeTable.NotQuickSerializable
Register a new type, so that new_object(ostore.util.InputBuffer) can be called later.

Parameters:
name - the fully qualified name of the Java class being registered
Throws:
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 (InputBuffer buffer) or Foo (InputBuffer buffer) throws QSException
TypeTable.NotQuickSerializable - if the given class is not a subtype of QuickSerializable
TypeTable.DuplicateTypeCode

register_type

public static void register_type(Class this_class)
                          throws TypeTable.DuplicateTypeCode,
                                 NoSuchMethodException,
                                 TypeTable.NotQuickSerializable
TypeTable.DuplicateTypeCode
NoSuchMethodException
TypeTable.NotQuickSerializable

new_object

public static QuickSerializable new_object(InputBuffer buffer)
                                    throws QSException
Constructs a new object out of an InputBuffer. Should not be called by user code. Call InputBuffer.nextObject instead.

QSException

new_object

public static QuickSerializable new_object(long 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) 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

type_code

public static long type_code(QuickSerializable obj)

type_code

public static long type_code(String class_name)

type_code_to_class

public static Class type_code_to_class(long type_code)