01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2003-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.shapefile.indexed;
17:
18: import org.geotools.data.FIDReader;
19: import org.geotools.feature.FeatureType;
20: import java.io.IOException;
21:
22: /**
23: * DOCUMENT ME!
24: *
25: * @author Tommaso Nolli
26: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/indexed/ShapeFIDReader.java $
27: */
28: public class ShapeFIDReader implements FIDReader {
29: protected static final String CLOSE_MESG = "Close has already been called"
30: + " on this FIDReader";
31: private boolean opened;
32: private IndexedShapefileDataStore.Reader reader;
33: private int len;
34: protected StringBuffer buffer;
35:
36: public ShapeFIDReader(String typeName,
37: IndexedShapefileDataStore.Reader reader) {
38: buffer = new StringBuffer(typeName);
39: buffer.append('.');
40: len = typeName.length() + 1;
41: this .opened = true;
42: this .reader = reader;
43: }
44:
45: public ShapeFIDReader(FeatureType featureType,
46: IndexedShapefileDataStore.Reader reader) {
47: this (featureType.getTypeName(), reader);
48: }
49:
50: /**
51: * Release any resources associated with this reader
52: */
53: public void close() {
54: this .opened = false;
55: }
56:
57: /**
58: * This method always returns true, since it is built with a
59: * <code>ShapefileDataStore.Reader</code> you have to call
60: * <code>ShapefileDataStore.Reader.hasNext()</code>
61: *
62: * @return always return <code>true</code>
63: *
64: * @throws IOException If closed
65: */
66: public boolean hasNext() throws IOException {
67: if (!this .opened) {
68: throw new IOException(CLOSE_MESG);
69: }
70:
71: /* In DefaultFIDReader this is always called after
72: * atttributesReader.hasNext so, as we use the same
73: * attributeReader, we'll return true
74: */
75: return true;
76: }
77:
78: /**
79: * Read the feature id.
80: *
81: * @return the Feature Id
82: *
83: * @throws IOException If closed
84: */
85: public String next() throws IOException {
86: if (!this .opened) {
87: throw new IOException(CLOSE_MESG);
88: }
89:
90: buffer.delete(len, buffer.length());
91: buffer.append(reader.getRecordNumber() - 1);
92:
93: return buffer.toString();
94: }
95: }
|