001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-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;
009: * version 2.1 of the License.
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.property;
017:
018: import org.geotools.data.FeatureReader;
019: import org.geotools.feature.Feature;
020: import org.geotools.feature.FeatureType;
021: import org.geotools.feature.IllegalAttributeException;
022: import java.io.File;
023: import java.io.IOException;
024: import java.util.NoSuchElementException;
025: import java.util.logging.Logger;
026:
027: /**
028: * DOCUMENT ME!
029: *
030: * @author jgarnett
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/demo/property/src/main/java/org/geotools/data/property/PropertyFeatureReader.java $
032: * @version $Id
033: */
034: public class PropertyFeatureReader implements FeatureReader {
035: private static final Logger LOGGER = org.geotools.util.logging.Logging
036: .getLogger("org.geotools.data.property");
037: /** DOCUMENT ME! */
038: PropertyAttributeReader reader;
039:
040: /**
041: * Creates a new PropertyFeatureReader object.
042: *
043: * @param directory DOCUMENT ME!
044: * @param typeName DOCUMENT ME!
045: *
046: * @throws IOException DOCUMENT ME!
047: */
048: public PropertyFeatureReader(File directory, String typeName)
049: throws IOException {
050: File file = new File(directory, typeName + ".properties");
051: reader = new PropertyAttributeReader(file);
052: }
053:
054: /**
055: * DOCUMENT ME!
056: *
057: * @return DOCUMENT ME!
058: */
059: public FeatureType getFeatureType() {
060: return reader.type;
061: }
062:
063: /**
064: * DOCUMENT ME!
065: *
066: * @return DOCUMENT ME!
067: *
068: * @throws IOException DOCUMENT ME!
069: * @throws IllegalAttributeException DOCUMENT ME!
070: * @throws NoSuchElementException DOCUMENT ME!
071: */
072: public Feature next() throws IOException,
073: IllegalAttributeException, NoSuchElementException {
074: reader.next();
075:
076: FeatureType type = reader.type;
077: String fid = reader.getFeatureID();
078: Object[] values = new Object[reader.getAttributeCount()];
079:
080: for (int i = 0; i < reader.getAttributeCount(); i++) {
081: try {
082: values[i] = reader.read(i);
083: } catch (RuntimeException e) {
084: values[i] = null;
085: } catch (IOException e) {
086: throw e;
087: }
088: }
089:
090: return type.create(values, fid);
091: }
092:
093: /**
094: * DOCUMENT ME!
095: *
096: * @return DOCUMENT ME!
097: *
098: * @throws IOException DOCUMENT ME!
099: */
100: public boolean hasNext() throws IOException {
101: return reader.hasNext();
102: }
103:
104: /**
105: * DOCUMENT ME!
106: *
107: * @throws IOException DOCUMENT ME!
108: */
109: public void close() throws IOException {
110: if (reader == null) {
111: LOGGER.warning("Stream seems to be already closed.");
112: } else {
113: reader.close();
114: }
115:
116: reader = null;
117: }
118: }
|