001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2003-2004, Julian J. Ray, All Rights Reserved
006: * (C) 2001-2003 TOPP - www.openplans.org
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: */
018: package org.geotools.data.tiger;
019:
020: import java.io.File;
021: import java.io.IOException;
022: import java.util.Collections;
023: import java.util.Map;
024:
025: import org.geotools.data.DataStore;
026: import org.geotools.data.DataStoreFactorySpi;
027:
028: /**
029: * <p>
030: * Title: GeoTools2 Development
031: * </p>
032: *
033: * <p>
034: * Description:
035: * </p>
036: *
037: * <p>
038: * Copyright: Copyright (c) 2003
039: * </p>
040: *
041: * <p>
042: * Company:
043: * </p>
044: *
045: * @author Julian J. Ray
046: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/tiger/src/main/java/org/geotools/data/tiger/TigerDataStoreFactory.java $
047: * @version 1.0
048: */
049: public class TigerDataStoreFactory implements DataStoreFactorySpi {
050: /**
051: * Creates a new TigerDataStoreFactory object.
052: */
053: public TigerDataStoreFactory() {
054: }
055:
056: /**
057: * createDataStore
058: *
059: * @param params Map
060: *
061: * @return DataStore
062: *
063: * @throws IOException
064: */
065: public DataStore createDataStore(Map params) throws IOException {
066: File file = (File) DIRECTORY.lookUp(params);
067: if (file.exists() && file.isDirectory()) {
068: return new TigerDataStore(file);
069: } else {
070: throw new IOException();
071: }
072: }
073:
074: /**
075: * createNewDataStore
076: *
077: * @param params Map
078: *
079: * @return DataStore
080: *
081: * @throws IOException
082: */
083: public DataStore createNewDataStore(Map params) throws IOException {
084: String dirName = (String) params.get("directory");
085:
086: File dir = new File(dirName);
087:
088: if (dir.exists()) {
089: throw new IOException("Can't create new data store: " + dir
090: + " already exists!");
091: }
092:
093: boolean created;
094: created = dir.mkdir();
095:
096: if (!created) {
097: throw new IOException("Can't create directory: " + dir);
098: }
099:
100: return new TigerDataStore(dirName);
101: }
102:
103: public String getDisplayName() {
104: return "Tiger";
105: }
106:
107: /**
108: * getDescription
109: *
110: * @return String
111: */
112: public String getDescription() {
113: return "Data Store for TIGER/Line 2002 Line files.";
114: }
115:
116: public static final Param DIRECTORY = new Param("directory",
117: File.class, "Directory containing TIGER/Line 2002 files.");
118:
119: // public DataSourceMetadataEnity createMetadata( Map params ) throws IOException {
120: // if( !canProcess( params )){
121: // throw new IOException( "Provided params cannot be used to connect");
122: // }
123: // File dir = (File) DIRECTORY.lookUp( params );
124: // return new DataSourceMetadataEnity( dir, "Tiger data source access for " + dir );
125: // }
126: /**
127: * getParametersInfo
128: *
129: * @return Param[]
130: */
131: public Param[] getParametersInfo() {
132: return new Param[] { DIRECTORY };
133: }
134:
135: /**
136: * Test to see if this datastore is available, if it has all the
137: * appropriate libraries to construct a datastore. This datastore just
138: * returns true for now. This method is used for gui apps, so as to not
139: * advertise data store capabilities they don't actually have.
140: *
141: * @return <tt>true</tt> if and only if this factory is available to create
142: * DataStores.
143: *
144: * @task REVISIT: I'm just adding this method to compile, maintainer should
145: * revisit to check for any libraries that may be necessary for
146: * datastore creations. ch.
147: */
148: public boolean isAvailable() {
149: return true;
150: }
151:
152: /**
153: * canProcess
154: *
155: * @param params Map
156: *
157: * @return boolean
158: */
159: public boolean canProcess(Map params) {
160: try {
161: File file = (File) DIRECTORY.lookUp(params);
162: return (file.exists() && file.isDirectory());
163: } catch (Exception e) {
164: return false;
165: }
166: }
167:
168: /**
169: * Returns the implementation hints. The default implementation returns en empty map.
170: */
171: public Map getImplementationHints() {
172: return Collections.EMPTY_MAP;
173: }
174: }
|