com.bbn.openmap.dataAccess.shape
Class DbfFile

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.bbn.openmap.dataAccess.shape.DbfTableModel
          extended by com.bbn.openmap.dataAccess.shape.DbfFile
All Implemented Interfaces:
ShapeConstants, java.io.Serializable, java.lang.Iterable<java.util.List<java.lang.Object>>, java.util.EventListener, javax.swing.event.TableModelListener, javax.swing.table.TableModel

public class DbfFile
extends DbfTableModel

An extension to DbfTableModel that handles reading only certain records when needed, in conjunction with some spatial indexing mechanism. Can be told to which columns to read and which to skip, so unnecessary/unused information isn't held in memory.

Author:
dietrick
See Also:
Serialized Form

Field Summary
protected  java.lang.Object[] _columnMask
          This _columnMask variable is an array that either contains a Boolean.TRUE for the indexes for columns that should be read, or a Integer object that contains the byte length of the column entry, so the reader will know how many bytes to skip for columns being ignored.
protected  int _headerLength
           
protected  int _recordLength
           
protected  int _rowCount
           
protected  BinaryFile bf
           
protected  java.text.DecimalFormat df
           
 
Fields inherited from class com.bbn.openmap.dataAccess.shape.DbfTableModel
_columnCount, _decimalCounts, _lengths, _names, _records, _types, DEBUG, dirty, DONE_MASK, exitOnClose, filePath, frame, logger, MODIFY_COLUMN_MASK, MODIFY_ROW_MASK, parent, SAVE_MASK, table, TYPE_AUTOINCREMENT, TYPE_BINARY, TYPE_CHARACTER, TYPE_DATE, TYPE_DOUBLE, TYPE_FLOAT, TYPE_LOGICAL, TYPE_LONG, TYPE_MEMO, TYPE_NUMERIC, TYPE_OLE, TYPE_TIMESTAMP, writable, ZERO
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.bbn.openmap.dataAccess.shape.ShapeConstants
DBF_ATTRIBUTE, DBF_AUTOINCREMENT, DBF_BINARY, DBF_CHARACTER, DBF_DATE, DBF_DOUBLE, DBF_FLOAT, DBF_LOGICAL, DBF_LONG, DBF_MEMO, DBF_NUMERIC, DBF_OLE, DBF_TIMESTAMP, DBF_TYPE_AUTOINCREMENT, DBF_TYPE_BINARY, DBF_TYPE_CHARACTER, DBF_TYPE_DATE, DBF_TYPE_DOUBLE, DBF_TYPE_FLOAT, DBF_TYPE_LOGICAL, DBF_TYPE_LONG, DBF_TYPE_MEMO, DBF_TYPE_NUMERIC, DBF_TYPE_OLE, DBF_TYPE_TIMESTAMP, PARAM_DBF, PARAM_SHP, PARAM_SHX, SHAPE_BOUNDS_ATTRIBUTE, SHAPE_DBF_DASHPATTERN, SHAPE_DBF_DASHPHASE, SHAPE_DBF_DESCRIPTION, SHAPE_DBF_FILLCOLOR, SHAPE_DBF_INFO_ATTRIBUTE, SHAPE_DBF_LINECOLOR, SHAPE_DBF_LINEWIDTH, SHAPE_DBF_SELECTCOLOR, SHAPE_FILE_HEADER_LENGTH, SHAPE_FILE_RECORD_HEADER_LENGTH, SHAPE_INDEX_ATTRIBUTE, SHAPE_MAX_MEASURE_ATTRIBUTE, SHAPE_MAX_Z_ATTRIBUTE, SHAPE_MEASURE_ATTRIBUTE, SHAPE_MIN_MEASURE_ATTRIBUTE, SHAPE_MIN_Z_ATTRIBUTE, SHAPE_TYPE_ARC, SHAPE_TYPE_MULTIPATCH, SHAPE_TYPE_MULTIPOINT, SHAPE_TYPE_MULTIPOINTM, SHAPE_TYPE_MULTIPOINTZ, SHAPE_TYPE_NULL, SHAPE_TYPE_POINT, SHAPE_TYPE_POINTM, SHAPE_TYPE_POINTZ, SHAPE_TYPE_POLYGON, SHAPE_TYPE_POLYGONM, SHAPE_TYPE_POLYGONZ, SHAPE_TYPE_POLYLINE, SHAPE_TYPE_POLYLINEM, SHAPE_TYPE_POLYLINEZ, SHAPE_Z_ATTRIBUTE
 
Constructor Summary
protected DbfFile()
           
  DbfFile(BinaryFile bf)
           
  DbfFile(int columnCount)
          Creates a blank DbfTableModel
 
Method Summary
 void clearRecords()
          Clear the record information from memory.
 void close()
          Tells the BinaryFile input reader to close, releasing the file pointer.
protected  void createColumnMaskArray(boolean[] mask)
          Given a boolean[] where trues mark columns to keep, a _columnMask Object[] is set on this object with Boolean.TRUE objects in that array for the trues, and Integer objects representing the lengths of the false columns.
 BinaryFile getBinaryFile()
           
 boolean[] getColumnMask()
          Checks the _columnMask Object[] and looks for Boolean.TRUE objects, indicating a column that should be used.
static DbfTableModel getDbfTableModel(java.lang.String dbf)
          Creates a DbfTableModel for a given .dbf file
static DbfTableModel getDbfTableModel(java.net.URL dbf)
          Creates a DbfTableModel for a given .dbf file
 java.text.DecimalFormat getDecimalFormat()
           
 int getHeaderLength()
           
 java.util.List<java.lang.Object> getRecordData(int index)
          Fetches the record data for the given index.
 int getRecordLength()
           
 int getRowCount()
          Retrieves the number of columns that exist in the model
 DbfTableModel headerClone()
          Create another DbfTableModel with the same structure as this one (number of columns, column names, lengths and decimal counts).
static void main(java.lang.String[] args)
           
 void readData()
          Reads the data and puts data in an ArrayList of records.
 void readData(int startingRecordIndex, int numRecordsToRead)
          Read in a set of records from the dbf file, starting at the provided index and continuing for the provided count.
 void readHeader(BinaryFile bf)
           
protected  void resolveColumns()
          Sets the metadata for the dbf file to match the current _columnMask settings.
 void setBinaryFile(BinaryFile bf)
           
 void setColumnMask(boolean[] mask)
          Limit which columns are read from the dbf file using a boolean array corresponding to the columns.
 void setColumnMask(java.lang.String[] columnNames)
          Limit which columns are read from the dbf file using the column names.
 void setDecimalFormat(java.text.DecimalFormat df)
           
 void setHeaderLength(int length)
           
 void setRecordLength(int length)
           
 void setRowCount(int count)
           
 
Methods inherited from class com.bbn.openmap.dataAccess.shape.DbfTableModel
add, add, add, addBlankRecord, addColumn, addRecord, append, appendWhitespaceOrTrim, cleanupChanges, commitEvents, deleteColumn, doAction, exitWindowClosed, getBlankRecord, getColumnClass, getColumnCount, getColumnIndexForName, getColumnName, getDecimalCount, getEmptyDefaultForType, getGUI, getLength, getObjectForType, getRecord, getRecords, getStringForType, getTable, getTable, getType, getValueAt, getWritable, hideGUI, isCellEditable, isExitOnClose, isNumericalType, isValidType, iterator, matches, read, remove, remove, remove, remove, setColumnName, setDecimalCount, setExitOnClose, setLength, setType, setValueAt, setWritable, showGUI, tableChanged, test, write
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_rowCount

protected int _rowCount

_recordLength

protected int _recordLength

_headerLength

protected int _headerLength

_columnMask

protected java.lang.Object[] _columnMask
This _columnMask variable is an array that either contains a Boolean.TRUE for the indexes for columns that should be read, or a Integer object that contains the byte length of the column entry, so the reader will know how many bytes to skip for columns being ignored. The _length array contents were modified to reflect the lengths of only the columns being read when the column mask was set, as was the _names, _types, and _decimalCount arrays. The order and length of those arrays match the order of the Boolean.TRUE objects in the _columnMask array.


df

protected java.text.DecimalFormat df

bf

protected BinaryFile bf
Constructor Detail

DbfFile

protected DbfFile()

DbfFile

public DbfFile(int columnCount)
Creates a blank DbfTableModel

Parameters:
columnCount - The number of columns this model will manage

DbfFile

public DbfFile(BinaryFile bf)
        throws java.io.EOFException,
               FormatException,
               java.io.IOException
Throws:
java.io.EOFException
FormatException
java.io.IOException
Method Detail

readHeader

public void readHeader(BinaryFile bf)
                throws FormatException,
                       java.io.IOException
Throws:
FormatException
java.io.IOException

close

public void close()
Tells the BinaryFile input reader to close, releasing the file pointer. Will automatically reopen if necessary.


readData

public void readData()
              throws java.io.IOException,
                     FormatException
Reads the data and puts data in an ArrayList of records.

Throws:
java.io.IOException
FormatException

readData

public void readData(int startingRecordIndex,
                     int numRecordsToRead)
              throws java.io.IOException,
                     FormatException
Read in a set of records from the dbf file, starting at the provided index and continuing for the provided count.

Parameters:
startingRecordIndex - , 0 is the first record index.
numRecordsToRead -
Throws:
java.io.IOException
FormatException

getRecordData

public java.util.List<java.lang.Object> getRecordData(int index)
                                               throws java.io.IOException,
                                                      FormatException
Fetches the record data for the given index.

Parameters:
index - the index of the data, starting at 0 for the first record.
Returns:
List containing Strings and Numbers for the dbf entry for the record.
Throws:
java.io.IOException
FormatException

clearRecords

public void clearRecords()
Clear the record information from memory.


headerClone

public DbfTableModel headerClone()
Create another DbfTableModel with the same structure as this one (number of columns, column names, lengths and decimal counts).

Overrides:
headerClone in class DbfTableModel

getDbfTableModel

public static DbfTableModel getDbfTableModel(java.net.URL dbf)
Creates a DbfTableModel for a given .dbf file

Parameters:
dbf - The url of the file to retrieve.
Returns:
The DbfTableModel, null if there is a problem.

getDbfTableModel

public static DbfTableModel getDbfTableModel(java.lang.String dbf)
Creates a DbfTableModel for a given .dbf file

Parameters:
dbf - The path of the file to retrieve.
Returns:
The DbfTableModel, null if there is a problem.

main

public static void main(java.lang.String[] args)

getColumnMask

public boolean[] getColumnMask()
Checks the _columnMask Object[] and looks for Boolean.TRUE objects, indicating a column that should be used. Returns a boolean[] with trues in the indexes for those columns.

Returns:
boolean[] representing columns, true values should be used.

createColumnMaskArray

protected void createColumnMaskArray(boolean[] mask)
Given a boolean[] where trues mark columns to keep, a _columnMask Object[] is set on this object with Boolean.TRUE objects in that array for the trues, and Integer objects representing the lengths of the false columns. The lengths are used when reading the dbf file, so it's known how many bytes to skip for that column.

Parameters:
mask -

setColumnMask

public void setColumnMask(boolean[] mask)
Limit which columns are read from the dbf file using a boolean array corresponding to the columns. For indexes in the array marked true, those columns will be read. If the column mask has already been set, the dbf file header will be re-read to reset the metadata for the file.

Parameters:
mask -

setColumnMask

public void setColumnMask(java.lang.String[] columnNames)
Limit which columns are read from the dbf file using the column names. If the column mask has already been set, the dbf file header will be re-read to reset the metadata for the file.

Parameters:
columnNames -

resolveColumns

protected void resolveColumns()
Sets the metadata for the dbf file to match the current _columnMask settings.


getHeaderLength

public int getHeaderLength()

setHeaderLength

public void setHeaderLength(int length)

getRecordLength

public int getRecordLength()

setRecordLength

public void setRecordLength(int length)

getRowCount

public int getRowCount()
Description copied from class: DbfTableModel
Retrieves the number of columns that exist in the model

Specified by:
getRowCount in interface javax.swing.table.TableModel
Overrides:
getRowCount in class DbfTableModel
Returns:
The number column that exist in the model

setRowCount

public void setRowCount(int count)

getBinaryFile

public BinaryFile getBinaryFile()

setBinaryFile

public void setBinaryFile(BinaryFile bf)
                   throws java.io.EOFException,
                          FormatException,
                          java.io.IOException
Throws:
java.io.EOFException
FormatException
java.io.IOException

getDecimalFormat

public java.text.DecimalFormat getDecimalFormat()

setDecimalFormat

public void setDecimalFormat(java.text.DecimalFormat df)


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details