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.HashMap;
035: import java.util.Map;
036:
037: import org.apache.log4j.Logger;
038:
039: import com.vividsolutions.jump.coordsys.CoordinateSystem;
040: import com.vividsolutions.jump.coordsys.CoordinateSystemRegistry;
041: import com.vividsolutions.jump.feature.FeatureCollection;
042:
043: /**
044: * A file, database, web service, or other source of data. To be savable to a
045: * project file, a DataSource must not be an anonymous class (because the class
046: * name is recorded in the project file) and it must have a parameterless
047: * constructor (so it can be reconstructed by simply being instantiated and
048: * having #setProperties called).
049: */
050: public abstract class DataSource {
051: private static Logger LOG = Logger.getLogger(DataSource.class);
052:
053: private HashMap properties;
054:
055: /**
056: * Sets properties required to open a DataSource, such as username, password,
057: * filename, coordinate system, etc. Called by DataSourceQueryChoosers.
058: */
059: public void setProperties(Map properties) {
060: this .properties = new HashMap(properties);
061: }
062:
063: public Map getProperties() {
064: //This method needs to be public because it is called by Java2XML [Jon Aquino 11/13/2003]
065:
066: //I was returning a Collections.unmodifiableMap before, but
067: //Java2XML couldn't open it after saving it (can't instantiate
068: //java.util.Collections$UnmodifiableMap). [Jon Aquino]
069: return properties;
070: }
071:
072: /**
073: * Creates a new Connection to this DataSource.
074: */
075: public abstract Connection getConnection();
076:
077: /**
078: * Filename property, used for file-based DataSources
079: */
080: public static final String FILE_KEY = "File";
081:
082: /**
083: * Coordinate-system property, used for files and other DataSources that
084: * have a single CoordinateSystem
085: */
086: public static final String COORDINATE_SYSTEM_KEY = "Coordinate System";
087:
088: public boolean isReadable() {
089: return true;
090: }
091:
092: public boolean isWritable() {
093: return true;
094: }
095:
096: public FeatureCollection installCoordinateSystem(
097: FeatureCollection queryResult,
098: CoordinateSystemRegistry registry) {
099: if (queryResult == null) {
100: return queryResult;
101: }
102: String coordinateSystemName = null;
103: try {
104: coordinateSystemName = (String) getProperties().get(
105: COORDINATE_SYSTEM_KEY);
106: } catch (NullPointerException e) {
107: return queryResult;
108: }
109: if (coordinateSystemName == null) {
110: return queryResult;
111: }
112: CoordinateSystem coordinateSystem = registry
113: .get(coordinateSystemName);
114: if (coordinateSystem == null) {
115: return queryResult;
116: }
117: queryResult.getFeatureSchema().setCoordinateSystem(
118: coordinateSystem);
119: return queryResult;
120: }
121:
122: }
|