com.sleepycat.bdb.bind.tuple
Class TupleBinding

java.lang.Object
  extended by com.sleepycat.bdb.bind.tuple.TupleBinding
All Implemented Interfaces:
DataBinding
Direct Known Subclasses:
TupleMarshalledBinding

public abstract class TupleBinding
extends java.lang.Object
implements DataBinding

An abstract tuple binding for tuple keys or values. This class takes care of converting the data to/from TupleInput and TupleOutput objects. Its two abstract methods must be implemented by a concrete subclass to convert between tuples and key or value objects.

For keys or values which are Java primitive classes (String, Integer, etc) getPrimitiveBinding(java.lang.Class, com.sleepycat.bdb.bind.tuple.TupleFormat) may be used to return a builtin tuple binding. A custom tuple binding for these types is not needed.


Field Summary
protected  TupleFormat format
           
 
Constructor Summary
TupleBinding(TupleFormat format)
          Creates a tuple binding.
 
Method Summary
 java.lang.Object dataToObject(DataBuffer data)
          Converts a data buffer into an Object.
abstract  java.lang.Object dataToObject(TupleInput input)
          Constructs a key or value object from TupleInput data.
 DataFormat getDataFormat()
          Returns the format used for the data of this binding.
static TupleBinding getPrimitiveBinding(java.lang.Class cls, TupleFormat format)
          Creates a tuple binding for a primitive Java class.
 void objectToData(java.lang.Object object, DataBuffer data)
          Converts an Object into a data buffer.
abstract  void objectToData(java.lang.Object object, TupleOutput output)
          Converts a key or value object to a tuple data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

format

protected TupleFormat format
Constructor Detail

TupleBinding

public TupleBinding(TupleFormat format)
Creates a tuple binding.

Parameters:
format - is the format of the new binding.
Method Detail

dataToObject

public java.lang.Object dataToObject(DataBuffer data)
                              throws java.io.IOException
Description copied from interface: DataBinding
Converts a data buffer into an Object.

Specified by:
dataToObject in interface DataBinding
Parameters:
data - is the source data buffer.
Returns:
the resulting Object.
Throws:
java.io.IOException

objectToData

public void objectToData(java.lang.Object object,
                         DataBuffer data)
                  throws java.io.IOException
Description copied from interface: DataBinding
Converts an Object into a data buffer.

Specified by:
objectToData in interface DataBinding
Parameters:
object - is the source Object.
data - is the destination data buffer.
Throws:
java.io.IOException

getDataFormat

public DataFormat getDataFormat()
Description copied from interface: DataBinding
Returns the format used for the data of this binding.

Specified by:
getDataFormat in interface DataBinding
Returns:
the data format.

dataToObject

public abstract java.lang.Object dataToObject(TupleInput input)
                                       throws java.io.IOException
Constructs a key or value object from TupleInput data.

Parameters:
input - is the tuple key or value data.
Returns:
the key or value object constructed from the data.
Throws:
java.io.IOException

objectToData

public abstract void objectToData(java.lang.Object object,
                                  TupleOutput output)
                           throws java.io.IOException
Converts a key or value object to a tuple data.

Parameters:
object - is the key or value object.
output - is the tuple data to which the key or value should be written.
Throws:
java.io.IOException

getPrimitiveBinding

public static TupleBinding getPrimitiveBinding(java.lang.Class cls,
                                               TupleFormat format)
Creates a tuple binding for a primitive Java class. The following Java classes are supported.

Parameters:
cls - is the primitive Java class.
format - is the tuple format for the new binding.
Returns:
a new building for the primitive class or null if the cls parameter is not one of the supported classes.