com.bbn.openmap.layer.vpf
Class DcwRecordFile

java.lang.Object
  extended by com.bbn.openmap.layer.vpf.DcwRecordFile
Direct Known Subclasses:
FeatureClassInfo, PrimitiveTable

public class DcwRecordFile
extends java.lang.Object

Read and encapsulate VPF table files.


Field Summary
protected  boolean byteorder
          remember the byte order for later file openings, true for MSB first
protected  DcwColumnInfo[] columnInfo
          ordered set of columns (read from table header)
protected  java.lang.String documentationFileName
          the name of another table that describes what this one is for
protected  java.lang.String filename
          the name of the file
static java.lang.String ID_COLUMN_NAME
          the name of the row identifier column "id"
protected  BinaryFile inputFile
          input is read from this file
protected  boolean MSBFirst
          big-endian (true) or little-endian ( false)
protected  int recordLength
          length of a record (-1 indicates variable-length record)
protected  java.lang.String tableDescription
          the description of the table [read from the file]
protected  java.lang.String tablename
          the name of the table
protected  DcwVariableLengthIndexFile vli
          for tables with variable-length records, the corresponding variable-length index
 
Constructor Summary
DcwRecordFile(java.lang.String name)
          Open a DcwRecordFile and completely initialize it
DcwRecordFile(java.lang.String name, boolean deferInit)
          Open a DcwRecordFile
 
Method Summary
 void close()
          Closes the associated input file.
protected  void finalize()
          releases associated resources
 void finishInitialization()
          Complete initialization of this object.
 int getColumnCount()
          Returns the number of columns this table has
 DcwColumnInfo[] getColumnInfo()
          Return the column info for this table.
 java.lang.String getColumnName(int index)
          Returns the name of a column
 java.lang.String getDescription()
          Returns the table description for this table.
 java.lang.String getDocumentationFilename()
          Returns the documentation file associated with this table.
 int getRecordCount()
          Gets the number of records in the table.
 int getRecordLength()
          get the length of a single record
 java.util.List<java.lang.Object> getRow(int rownumber)
          Parses the row specified by rownumber
 boolean getRow(java.util.List<java.lang.Object> retval, int rownumber)
          Parses the row specified by rownumber
 java.lang.String getTableFile()
          Returns the File this instance is using
 java.lang.String getTableName()
          return the name of the table
 TilingAdapter getTilingAdapter(int tileColumn, int primColumn)
          Returns a TilingAdapter for the selected column.
 TilingAdapter getTilingAdapter(java.lang.String primColumnName)
          Returns a TilingAdapter for the selected column.
 TilingAdapter getTilingAdapter(java.lang.String tileColumnName, java.lang.String primColumnName)
          Returns a TilingAdapter for the selected column.
 int[] lookupSchema(java.lang.String[] names, boolean mustExist)
          Get the column number for a set of column names.
 int[] lookupSchema(java.lang.String[] names, boolean mustExist, char[] type, int[] length, boolean strictlength)
          Get the column number for a set of column names.
static void main(java.lang.String[] args)
          An test main for parsing VPF table files.
 void parseAllRowsAndPrintSome()
          Good for looking at the contents of a data file, this method dumps a bunch of rows to System.out.
 java.util.List<java.lang.Object> parseRow()
          Return a row from the table.
 boolean parseRow(java.util.List<java.lang.Object> retval)
          Return a row from the table.
 void parseSomeRowsAndPrint()
          Good for looking at the contents of a data file, this method dumps a bunch of rows to System.out.
 void printSchema()
          Prints the table information to System.out.
 void reopen(int seekRow)
          Reopen the associated input file.
 void seekToRow(int recordNumber)
          moves the input cursor to the specified row [affects subsequent calls parseRow.]
 int whatColumn(java.lang.String columnname)
          Returns the index into columnInfo of the column with the specified name
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputFile

protected BinaryFile inputFile
input is read from this file


tableDescription

protected java.lang.String tableDescription
the description of the table [read from the file]


documentationFileName

protected java.lang.String documentationFileName
the name of another table that describes what this one is for


MSBFirst

protected boolean MSBFirst
big-endian (true) or little-endian ( false)


columnInfo

protected DcwColumnInfo[] columnInfo
ordered set of columns (read from table header)


recordLength

protected int recordLength
length of a record (-1 indicates variable-length record)


vli

protected DcwVariableLengthIndexFile vli
for tables with variable-length records, the corresponding variable-length index


filename

protected final java.lang.String filename
the name of the file


tablename

protected java.lang.String tablename
the name of the table


byteorder

protected boolean byteorder
remember the byte order for later file openings, true for MSB first


ID_COLUMN_NAME

public static final java.lang.String ID_COLUMN_NAME
the name of the row identifier column "id"

See Also:
Constant Field Values
Constructor Detail

DcwRecordFile

public DcwRecordFile(java.lang.String name)
              throws FormatException
Open a DcwRecordFile and completely initialize it

Parameters:
name - the name of the file to use for input
Throws:
FormatException - some problem was encountered dealing with the file

DcwRecordFile

public DcwRecordFile(java.lang.String name,
                     boolean deferInit)
              throws FormatException
Open a DcwRecordFile

Parameters:
name - the name of the file to use for input
deferInit - if true, don't actually open files and initialize the object. In this state, the only method that should be called is finishInitialization.
Throws:
FormatException - some problem was encountered dealing with the file
See Also:
finishInitialization()
Method Detail

getTableFile

public java.lang.String getTableFile()
Returns the File this instance is using

Returns:
the File being read

getTableName

public java.lang.String getTableName()
return the name of the table


finishInitialization

public void finishInitialization()
                          throws FormatException
Complete initialization of this object. This function should only be called once, and only if the object was constructed with deferred initialization.

Throws:
FormatException - some problem was encountered dealing with the file

getTilingAdapter

public TilingAdapter getTilingAdapter(java.lang.String primColumnName)
Returns a TilingAdapter for the selected column.

Parameters:
primColumnName - the name of the primitive column
Returns:
an appropriate TilingAdapter instance or null

getTilingAdapter

public TilingAdapter getTilingAdapter(java.lang.String tileColumnName,
                                      java.lang.String primColumnName)
Returns a TilingAdapter for the selected column.

Parameters:
primColumnName - the name of the primitive column
tileColumnName - the name of the tile_id column
Returns:
an appropriate TilingAdapter instance or null

getTilingAdapter

public TilingAdapter getTilingAdapter(int tileColumn,
                                      int primColumn)
Returns a TilingAdapter for the selected column.

Parameters:
primColumn - the position of the primitive column
tileColumn - the position of the tile_id column
Returns:
an appropriate TilingAdapter instance or null

lookupSchema

public int[] lookupSchema(java.lang.String[] names,
                          boolean mustExist)
                   throws FormatException
Get the column number for a set of column names.

Parameters:
names - the names of the columns
Returns:
an array of column numbers
Throws:
FormatException - the table does not match the specified schema

lookupSchema

public int[] lookupSchema(java.lang.String[] names,
                          boolean mustExist,
                          char[] type,
                          int[] length,
                          boolean strictlength)
                   throws FormatException
Get the column number for a set of column names.

Parameters:
names - the names of the columns
type - in same order as names
length - in same order as names (-1 for a variable length column)
strictlength - false means that variable length columns can be fixed-length instead
mustExist - if true and a column doesn't exist, method returns null
Returns:
an array of column numbers
Throws:
FormatException - the table does not match the specified schema

parseAllRowsAndPrintSome

public void parseAllRowsAndPrintSome()
                              throws FormatException
Good for looking at the contents of a data file, this method dumps a bunch of rows to System.out. It parses all the lines of the file.

Throws:
FormatException - some kind of data format error was encountered while parsing the file

parseSomeRowsAndPrint

public void parseSomeRowsAndPrint()
                           throws FormatException
Good for looking at the contents of a data file, this method dumps a bunch of rows to System.out. (Using seekToRow to move between records

Throws:
FormatException - some kind of data format error was encountered while parsing the file

parseRow

public java.util.List<java.lang.Object> parseRow()
                                          throws FormatException
Return a row from the table. repeatedly calling parseRow gets consecutive rows.

Returns:
a List of fields read from the table
Throws:
FormatException - an error was encountered reading the row

parseRow

public boolean parseRow(java.util.List<java.lang.Object> retval)
                 throws FormatException
Return a row from the table. repeatedly calling parseRow gets consecutive rows.

Parameters:
retval - append the fields from a row in the table. clear() is called before any real work is done.
Returns:
true is we read a row, false if no more rows are available
Throws:
FormatException - an error was encountered reading the row
See Also:
List.clear()

getDocumentationFilename

public java.lang.String getDocumentationFilename()
Returns the documentation file associated with this table.

Returns:
the doc file - may be null

getDescription

public java.lang.String getDescription()
Returns the table description for this table.

Returns:
the table description - may be null

getRecordLength

public int getRecordLength()
get the length of a single record

Returns:
-1 indicates a variably sized record

getRecordCount

public int getRecordCount()
                   throws FormatException
Gets the number of records in the table.

Returns:
the number of records
Throws:
FormatException - some problem was encountered dealing with the file

getRow

public java.util.List<java.lang.Object> getRow(int rownumber)
                                        throws FormatException
Parses the row specified by rownumber

Parameters:
rownumber - the number of the row to return [1..recordCount]
Returns:
the values contained in the row
Throws:
FormatException - data format errors

getRow

public boolean getRow(java.util.List<java.lang.Object> retval,
                      int rownumber)
               throws FormatException
Parses the row specified by rownumber

Parameters:
rownumber - the number of the row to return [1..recordCount]
retval - values contained in the row
Throws:
FormatException - data format errors
See Also:
parseRow()

seekToRow

public void seekToRow(int recordNumber)
               throws FormatException
moves the input cursor to the specified row [affects subsequent calls parseRow.]

Parameters:
recordNumber - the number of the row to seek to
Throws:
FormatException - data format errors
java.lang.IllegalArgumentException - recordNumber less than 1

whatColumn

public int whatColumn(java.lang.String columnname)
Returns the index into columnInfo of the column with the specified name

Parameters:
columnname - the column name to match
Returns:
an index into columnInfo (-1 indicates no such column)

getColumnName

public java.lang.String getColumnName(int index)
Returns the name of a column

Parameters:
index - the column to get the name for
Returns:
the columnName

printSchema

public void printSchema()
                 throws FormatException
Prints the table information to System.out.

Throws:
FormatException - some problem was encountered dealing with the file

close

public void close()
Closes the associated input file. (may later get reopened)


reopen

public void reopen(int seekRow)
            throws FormatException
Reopen the associated input file.

Parameters:
seekRow - the row to seek to upon reopening the file. If seekRow is invalid (less than 1), then the input stream is in an undefined location, and seekToRow (or getRow(int)) must be called before parseRow
Throws:
FormatException - some error was encountered in reopening file or seeking to the desired row.
See Also:
parseRow(), getRow(int), close()

getColumnCount

public final int getColumnCount()
Returns the number of columns this table has


getColumnInfo

public final DcwColumnInfo[] getColumnInfo()
Return the column info for this table.

NOTE: modifying this array is likely to cause problems...


finalize

protected void finalize()
releases associated resources

Overrides:
finalize in class java.lang.Object

main

public static void main(java.lang.String[] args)
An test main for parsing VPF table files.

Parameters:
args - file names to be read


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