1 /* -------------------------------------------------------------------
2 GeoVISTA Center (Penn State, Dept. of Geography)
3 Java source file for the class DBaseFieldDescriptor
4 Copyright (c), 2002, GeoVISTA Center
5 All Rights Reserved.
6 Original Author: Michael T. Wheeler
7 Modified for more generic use, accessors added,
8 some comments added by: Frank Hardisty
9
10 $Author: jmacgill $
11 $Id: DBaseFieldDescriptor.java,v 1.1.1.1 2003/02/28 14:54:01 jmacgill Exp $
12 $Date: 2003/02/28 14:54:01 $
13 Reference: Document no:
14 ___ ___
15 To Do:
16 ___
17 ------------------------------------------------------------------- *
18 * formatted with JxBeauty (c) johann.langhofer@nextra.at
19 */
20 /* --------------------------- Package ---------------------------- */
21
22
23 package edu.psu.geovista.db.dbase;
24
25
26 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">color="#329900"> ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900"> ------------------ Import classes (packages) ------------------- */
27 import java.io.IOException;
28
29
30 /*====================================================================
31 Implementation of class DBaseFieldDescriptor
32 ====================================================================*/
33 /***
34 * DBaseFieldDescriptor holds the information about each
35 * "column" or "variable" in a dBase file.
36 *
37 * @version $Revision: 1.1.1.1 $
38 * @author Michael T. Wheeler (mtwheels@psu.edu)
39 * @see: http://www.apptools.com/dbase/faq/qformt.htm
40 */
41 public class DBaseFieldDescriptor {
42 // Constants
43 private static final int DATA_SIZE_BYTES = 32;
44 public static final byte FIELD_TYPE_STRING = 'C';
45 public static final byte FIELD_TYPE_DATE = 'D';
46 public static final byte FIELD_TYPE_NUMERIC = 'N';
47 public static final byte FIELD_TYPE_BOOLEAN = 'L'; // Logical
48 public static final byte FIELD_TYPE_MEMO = 'M';
49 // Fields
50 private String fieldName;
51 private byte fieldType;
52 private byte fieldLength;
53 private byte fieldDecimalPlaces;
54 private byte setFieldsFlag;
55 private Object dataArray;
56
57 public DBaseFieldDescriptor (Object[] dataSet,
58 byte[] byteArray,
59 int numRecords, int currArrayNum
60 ) throws IOException {
61 //public DBaseFieldDescriptor (byte[] byteArray) throws IOException {
62 fieldName = new String(byteArray, 0, 10);
63 fieldName = fieldName.trim();
64 fieldDecimalPlaces = byteArray[17];
65 //System.out.println("");
66 //System.out.println("DBaseFieldDescriptor, fieldName = " + fieldName);
67 //System.out.println("DBaseFieldDescriptor, fieldType = " + byteArray[11]);
68 //if (fieldName.equals("UNITS50_UP")) {
69 for (int i = 0; i < byteArray.length; i++) {
70 //System.out.println(i + " " + byteArray[i]);
71 }
72 //}
73 fieldType = processType(dataSet, fieldName, (fieldDecimalPlaces > 0),
74 byteArray[11], numRecords, currArrayNum);
75 fieldLength = byteArray[16];
76 setFieldsFlag = byteArray[23];
77 if (setFieldsFlag != 0)
78 throw new IOException("What is a SET FIELDS flag?");
79 }
80
81 /***
82 * Doesn't really parse right now, we just use the dBase standard values
83 * as the constant. We should probably convert to a Java-specific type
84 * or a GeoVISTA-specific type at some point in here.
85 */
86 private byte processType (Object[] dataSet, String fieldName,
87 boolean floatingPoint, byte dBaseFieldType,
88 int numRecords, int currArrayNum) throws IOException {
89 switch (dBaseFieldType) {
90 case FIELD_TYPE_STRING:
91 dataArray = new String[numRecords];
92 break;
93 case FIELD_TYPE_NUMERIC:
94 if (floatingPoint) {
95 dataArray = new double[numRecords];
96 }
97 else {
98 dataArray = new int[numRecords];
99 }
100 break;
101
102 case FIELD_TYPE_BOOLEAN:
103 dataArray = new boolean[numRecords];
104 break;
105 case FIELD_TYPE_DATE:case FIELD_TYPE_MEMO:
106 throw new IOException("Currently unsupported fieldType, dBaseFieldType = "
107 + dBaseFieldType);
108 default:
109 throw new IOException("Unexpected dBaseFieldType = " + dBaseFieldType);
110 }
111 //add to big array
112 dataSet[currArrayNum] = dataArray;
113 return dBaseFieldType;
114 }
115
116 //begin accessors
117 public void setFieldName (String fieldName) {
118 this.fieldName = fieldName;
119 }
120 public String getFieldName () {
121 return this.fieldName;
122 }
123
124 public void setFieldType (byte fieldType) {
125 this.fieldType = fieldType;
126 }
127 public byte getFieldType () {
128 return this.fieldType;
129 }
130
131 public void setFieldLength (byte fieldLength) {
132 this.fieldLength = fieldLength;
133 }
134 public byte getFieldLength () {
135 return this.fieldLength;
136 }
137
138 public void setFieldDecimalPlaces (byte fieldDecimalPlaces) {
139 this.fieldDecimalPlaces = fieldDecimalPlaces;
140 }
141 public byte getFieldDecimalPlaces () {
142 return this.fieldDecimalPlaces;
143 }
144
145 public void setSetFieldsFlag (byte setFieldsFlag) {
146 this.setFieldsFlag = setFieldsFlag;
147 }
148 public byte getSetFieldsFlag () {
149 return this.setFieldsFlag;
150 }
151
152 public void setDataArray (Object dataArray) {
153 this.dataArray = dataArray;
154 }
155 public Object getDataArray () {
156 return this.dataArray;
157 }
158 //end accessors
159
160 final static int getDataSizeBytes () {
161 return DATA_SIZE_BYTES;
162 }
163
164 /***
165 * Gives info about the object.
166 */
167 public String toString () {
168 String res = new String("{" + fieldName + ", type = " + fieldType + ", length = "
169 + fieldLength + ", decimalPlaces = " + fieldDecimalPlaces + "}");
170 return res;
171 }
172 }
173
174
175
This page was automatically generated by Maven