nl.knaw.dans.common.dbflib
Class Value

java.lang.Object
  extended by nl.knaw.dans.common.dbflib.Value
Direct Known Subclasses:
BooleanValue, ByteArrayValue, DateValue, NumberValue, StringValue

public abstract class Value
extends Object

Represents a value that can be stored in a record. Values can be created by instantiating sub-classes of this type. These subclasses are by convention called according to the Java type they store, e.g., a BooleanValue stores a Java Boolean.

This interface has methods to retrieve the wrapped value in two formats: as an object of the Java type that the concrete subclass refers to (e.g., Boolean.TRUE) or as the raw bytes that are stored in the DBF file (e.g., {(byte)'Y'}). The raw value may depend on the exact specifications (length, decimal count) of the field that is read from or written to. That is why a Field instance must be specified when retrieving it.

Author:
Jan van Mansum

Field Summary
protected  Object typed
           
 
Constructor Summary
protected Value(Field originalField, byte[] rawValue)
          Constructs a Value object with the specified raw value.
protected Value(Object aTypedValue)
          Constructs a Value object with the specified typed value, i.e.
 
Method Summary
protected abstract  byte[] doGetRawValue(Field aField)
          Converts the typed value to a byte array, according to the field specifications provided.
protected abstract  Object doGetTypedValue(byte[] rawValue)
          Converts the raw bytes to a Java object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typed

protected Object typed
Constructor Detail

Value

protected Value(Field originalField,
                byte[] rawValue)
Constructs a Value object with the specified raw value. The subclass must take care of converting the raw value to a Java object by implementing doGetTypedValue(byte[]) .

Parameters:
rawValue - the bytes that constitute the raw value

Value

protected Value(Object aTypedValue)
Constructs a Value object with the specified typed value, i.e. Java object. The subclass must take care of converting the typed value to a byte array by implementing doGetRawValue(nl.knaw.dans.common.dbflib.Field).

Parameters:
aTypedValue - the value as a Java object
Method Detail

doGetTypedValue

protected abstract Object doGetTypedValue(byte[] rawValue)
Converts the raw bytes to a Java object. The class of Java object to create is determined by the subclass of Value.

Returns:
the value as a Java object

doGetRawValue

protected abstract byte[] doGetRawValue(Field aField)
                                 throws ValueTooLargeException
Converts the typed value to a byte array, according to the field specifications provided.

Parameters:
aField - the field specifications
Returns:
a byte array containing the raw value
Throws:
ValueTooLargeException - if the value is too large for the field


Copyright © 2009-2012 DANS. All Rights Reserved.