001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.vpf.io;
017:
018: import java.util.Collections;
019: import java.util.List;
020:
021: import org.geotools.data.vpf.ifc.DataTypesDefinition;
022: import org.geotools.data.vpf.ifc.VPFHeader;
023:
024: /**
025: * This class contains definition of VPF standard table header according to
026: * specification found in: "Interface Standard for Vector Product Format."
027: * Objects of this type are immutable. Created: Thu Jan 02 22:50:59 2003
028: *
029: * @author <a href="mailto:kobit@users.fs.net">Artur Hefczyc</a>
030: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/io/TableHeader.java $
031: * @version 1.0
032: */
033: public class TableHeader implements VPFHeader, DataTypesDefinition {
034: /**
035: * Variable <code>length</code> keeps value of length of ASCII header
036: * string (i.e., the remaining information after this field)
037: */
038: private int headerLength = -0;
039:
040: /**
041: * Variable <code>byteOrder</code> keeps value of byte order in which
042: * table is written:
043: *
044: * <ul>
045: * <li>
046: * <b>L</b> - least-significant-first
047: * </li>
048: * <li>
049: * <b>M</b> - most-significant-first
050: * </li>
051: * </ul>
052: */
053: private char byteOrder = LEAST_SIGNIF_FIRST;
054:
055: /**
056: * Variable <code>description</code> keeps value of text description of the
057: * table's contents.
058: */
059: private String description = null;
060:
061: /**
062: * Variable <code>narrativeTable</code> keeps value of an optional
063: * narrative file which contains miscellaneous information about the
064: * table.
065: */
066: private String narrativeTable = null;
067:
068: /**
069: * Variable <code>columnDefs</code> keeps value of list of all column
070: * definitions found in table header. This list keeps objects of type
071: * <code>TableColumnDef</code> class.
072: */
073: private List columnDefs = null;
074:
075: /**
076: * Creates a new <code>TableHeader</code> instance.
077: *
078: * @param length an <code>int</code> value of table header length.
079: * @param byteOrder a <code>char</code> value byte order used in table
080: * file.
081: * @param description a <code>String</code> value text description of found
082: * in header of this table.
083: * @param narrativeTable a <code>String</code> value file name of narrative
084: * table.
085: * @param columnDefs a <code>List</code> value of all column definitions
086: * for this table.
087: */
088: public TableHeader(int length, char byteOrder, String description,
089: String narrativeTable, List columnDefs) {
090: this .headerLength = length;
091: this .byteOrder = byteOrder;
092: this .description = description;
093: this .narrativeTable = narrativeTable;
094: this .columnDefs = columnDefs;
095: }
096:
097: /**
098: * Method <code>toString</code> returns content of all fields values. Used
099: * only for test and debug purpose.
100: *
101: * @return a <code>String</code> value
102: */
103: public String toString() {
104: String endLine = System.getProperty("line.separator");
105: StringBuffer buff = new StringBuffer();
106: buff.append(" length=" + headerLength + endLine);
107: buff.append(" byteOrder=" + byteOrder + endLine);
108: buff.append(" description=" + description + endLine);
109: buff.append(" narrativeTable=" + narrativeTable + endLine);
110: buff.append(" columnDefs:");
111:
112: if (columnDefs == null) {
113: buff.append("null)");
114: } else {
115: for (int i = 0; i < columnDefs.size(); i++) {
116: buff.append(endLine + columnDefs.get(i).toString());
117: }
118:
119: buff.append(endLine);
120: }
121:
122: return buff.toString();
123: }
124:
125: /**
126: * Gets the value of full length of ASCII header string including
127: * <code>headerLength</code> field.
128: *
129: * @return the value of headerLength
130: */
131: public int getLength() {
132: return this .headerLength + 4;
133: }
134:
135: /**
136: * Method <code><code>getRecordSize</code></code> is used to return size in
137: * bytes of records stored in this table. If table keeps variable length
138: * records <code>-1</code> should be returned.
139: *
140: * @return an <code><code>int</code></code> value
141: */
142: public int getRecordSize() {
143: int size = 0;
144:
145: for (int i = 0; i < columnDefs.size(); i++) {
146: TableColumnDef colDef = (TableColumnDef) columnDefs.get(i);
147:
148: // System.out.println("Column def no. "+i+" column size: "+
149: // colDef.getColumnSize());
150: if (colDef.getColumnSize() < 0) {
151: return -1;
152: } else {
153: size += colDef.getColumnSize();
154: }
155: }
156:
157: return size;
158: }
159:
160: /**
161: * Gets the value of byteOrder variable. Byte order in which table is
162: * written:
163: *
164: * <ul>
165: * <li>
166: * <b>L</b> - least-significant-first
167: * </li>
168: * <li>
169: * <b>M</b> - most-significant-first
170: * </li>
171: * </ul>
172: *
173: *
174: * @return the value of byteOrder
175: */
176: public char getByteOrder() {
177: return this .byteOrder;
178: }
179:
180: /**
181: * Gets the value of the description of table content.
182: *
183: * @return the value of description
184: */
185: public String getDescription() {
186: return this .description;
187: }
188:
189: /**
190: * Gets the value of narrativeTable variable file name.
191: *
192: * @return the value of narrativeTable
193: */
194: public String getNarrativeTable() {
195: return this .narrativeTable;
196: }
197:
198: /**
199: * Gets the value of columnDefs variable keeping definitions of all columns
200: * in this table.
201: *
202: * @return the value of columnDefs
203: */
204: public List getColumnDefs() {
205: return Collections.unmodifiableList(this .columnDefs);
206: }
207: }
208:
209: // TableHeader
|