001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/io/dbaseapi/FieldDescriptor.java $ 002 003 /*---------------- FILE HEADER ------------------------------------------ 004 005 This file is part of deegree. 006 Copyright (C) 2001-2008 by: 007 EXSE, Department of Geography, University of Bonn 008 http://www.giub.uni-bonn.de/deegree/ 009 lat/lon GmbH 010 http://www.lat-lon.de 011 012 This library is free software; you can redistribute it and/or 013 modify it under the terms of the GNU Lesser General Public 014 License as published by the Free Software Foundation; either 015 version 2.1 of the License, or (at your option) any later version. 016 017 This library is distributed in the hope that it will be useful, 018 but WITHOUT ANY WARRANTY; without even the implied warranty of 019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 020 Lesser General Public License for more details. 021 022 You should have received a copy of the GNU Lesser General Public 023 License along with this library; if not, write to the Free Software 024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 025 026 Contact: 027 028 Andreas Poth 029 lat/lon GmbH 030 Aennchenstr. 19 031 53115 Bonn 032 Germany 033 E-Mail: poth@lat-lon.de 034 035 Prof. Dr. Klaus Greve 036 Department of Geography 037 University of Bonn 038 Meckenheimer Allee 166 039 53115 Bonn 040 Germany 041 E-Mail: greve@giub.uni-bonn.de 042 043 044 ---------------------------------------------------------------------------*/ 045 046 package org.deegree.io.dbaseapi; 047 048 049 050 051 /** 052 * Class representing a field descriptor of a dBase III/IV file 053 * 054 * @version 28.04.2000 055 * @author Andreas Poth 056 */ 057 058 059 public class FieldDescriptor { 060 061 /** 062 * fieldinformation as byte array 063 */ 064 private byte[] data = null; 065 066 067 /** 068 * constructor 069 * recieves name and type of the field, the length of the field 070 * in bytes and the decimalcount. the decimalcount is only considered 071 * if type id "N" or "F", it's maxvalue if fieldlength - 2! 072 */ 073 public FieldDescriptor(String name, String type, byte fieldlength, 074 byte decimalcount) throws DBaseException { 075 076 if ( (!type.equalsIgnoreCase("C")) && 077 (!type.equalsIgnoreCase("D")) && 078 (!type.equalsIgnoreCase("F")) && 079 (!type.equalsIgnoreCase("N")) && 080 (!type.equalsIgnoreCase("M")) && 081 (!type.equalsIgnoreCase("L")) ) throw new DBaseException("data type is not supported"); 082 083 data = new byte[32]; 084 085 // fill first 11 bytes with ASCII zero 086 for (int i = 0; i <= 10; i++) data[i] = 0x0; 087 088 // copy name into the first 11 bytes 089 byte[] dum = name.getBytes(); 090 091 int cnt = dum.length; 092 093 if (cnt > 11) cnt = 11; 094 095 for (int i = 0; i < cnt; i++) data[i] = dum[i]; 096 097 byte[] b = type.getBytes(); 098 099 data[11] = b[0]; 100 101 // set fieldlength 102 data[16] = fieldlength; 103 104 // set decimalcount 105 if (type.equalsIgnoreCase("N") || type.equalsIgnoreCase("F") ) 106 data[17] = decimalcount; 107 else data[17] = 0; 108 109 // throw DBaseException if the decimalcount is larger then the 110 // number off fields required for plotting a float number 111 // as string 112 if (data[17] > data[16]-2) 113 throw new DBaseException("invalid fieldlength and/or decimalcount"); 114 115 // work area id (don't know if it should be 1) 116 data[20] = 1; 117 118 // has no index tag in a MDX file 119 data[31] = 0x00; 120 121 // all other fields are reserved! 122 123 } 124 125 /** 126 * method: public byte[] getFieldDescriptor() 127 * returns the field descriptor as byte array 128 */ 129 public byte[] getFieldDescriptor() { 130 131 return data; 132 133 } 134 135 }