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