001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032: package com.vividsolutions.jump.io.datasource;
033:
034: import java.util.ArrayList;
035: import java.util.Collection;
036:
037: import com.vividsolutions.jump.coordsys.CoordinateSystem;
038: import com.vividsolutions.jump.feature.FeatureCollection;
039: import com.vividsolutions.jump.io.DriverProperties;
040: import com.vividsolutions.jump.io.JUMPReader;
041: import com.vividsolutions.jump.io.JUMPWriter;
042: import com.vividsolutions.jump.task.TaskMonitor;
043:
044: /**
045: * Adapts the old JUMP I/O API (Readers and Writers) to the new JUMP I/O API
046: * (DataSources).
047: */
048: public class ReaderWriterFileDataSource extends DataSource {
049: protected JUMPReader reader;
050: protected JUMPWriter writer;
051:
052: public ReaderWriterFileDataSource(JUMPReader reader,
053: JUMPWriter writer) {
054: this .reader = reader;
055: this .writer = writer;
056: }
057:
058: public Connection getConnection() {
059: return new Connection() {
060: public FeatureCollection executeQuery(String query,
061: Collection exceptions, TaskMonitor monitor) {
062: try {
063: return reader.read(getReaderDriverProperties());
064: } catch (Exception e) {
065: exceptions.add(e);
066: return null;
067: //<<TODO>> Modify Readers and Writers to store exceptions and continue
068: //processing. [Jon Aquino]
069: }
070: }
071:
072: public void executeUpdate(String update,
073: FeatureCollection featureCollection,
074: TaskMonitor monitor) throws Exception {
075: writer.write(featureCollection,
076: getWriterDriverProperties());
077: }
078:
079: public void close() {
080: }
081:
082: public FeatureCollection executeQuery(String query,
083: TaskMonitor monitor) throws Exception {
084: ArrayList exceptions = new ArrayList();
085: FeatureCollection featureCollection = executeQuery(
086: query, exceptions, monitor);
087: if (!exceptions.isEmpty()) {
088: throw (Exception) exceptions.iterator().next();
089: }
090: return featureCollection;
091: }
092: };
093: }
094:
095: protected DriverProperties getReaderDriverProperties() {
096: return getDriverProperties();
097: }
098:
099: protected DriverProperties getWriterDriverProperties() {
100: return getDriverProperties();
101: }
102:
103: private DriverProperties getDriverProperties() {
104: DriverProperties properties = new DriverProperties();
105: properties.putAll(getProperties());
106: return properties;
107: }
108:
109: }
|