BufferedReader reader = null; try { ds = DataStoreFinder.getDataStore(filters); if (ds == null) { final String warning =
/** * Checks each available datasource implementation in turn and returns the first one which * claims to support the resource identified by the params object. * * @param params A Map object which contains a defenition of the resource to connect to. for * file based resources the property 'url' should be set within this Map. * @return The first datasource which claims to process the required resource, returns null if * none can be found. * @throws IOException If a suitable loader can be found, but it can not be attached to the * specified resource without errors. */ public static synchronized DataStore getDataStore(Map params) throws IOException { Iterator<DataStoreFactorySpi> ps = getAvailableDataStores(); DataAccess<? extends FeatureType, ? extends Feature> dataStore; dataStore = DataAccessFinder.getDataStore(params, ps); return (DataStore) dataStore; }
/** * Finds all implemtaions of DataAccessFactory which have registered using the services * mechanism, regardless weather it has the appropriate libraries on the classpath. * * @return An iterator over all discovered datastores which have registered factories */ public static synchronized Iterator<DataAccessFactory> getAllDataStores() { Set<DataAccessFactory> all = new HashSet<DataAccessFactory>(); Iterator<DataStoreFactorySpi> allDataStores = DataStoreFinder.getAllDataStores(); Iterator<DataAccessFactory> allDataAccess = getAllDataStores(getServiceRegistry(), DataAccessFactory.class); while (allDataStores.hasNext()) { DataStoreFactorySpi next = allDataStores.next(); all.add(next); } while (allDataAccess.hasNext()) { all.add(allDataAccess.next()); } return all.iterator(); }
public DataStore dataStore(Name name) { String localName = name.getLocalPart(); DataStore ds = map.get(localName); if (ds != null) return ds; try { Map<String, Serializable> params = getMapFromPropetryLocation(localName); ds = DataStoreFinder.getDataStore(params); } catch (IOException ex) { log.log(Level.SEVERE, ex.getMessage(), ex); return null; } map.put(localName, ds); return ds; }
/** * Finds all implemtaions of DataAccessFactory which have registered using the services * mechanism, and that have the appropriate libraries on the classpath. * * @return An iterator over all discovered datastores which have registered factories, and whose * available method returns true. */ public static synchronized Iterator<DataAccessFactory> getAvailableDataStores() { FactoryRegistry serviceRegistry = getServiceRegistry(); Set<DataAccessFactory> availableDS = getAvailableDataStores(serviceRegistry, DataAccessFactory.class); Iterator<DataStoreFactorySpi> availableDataStores = DataStoreFinder.getAvailableDataStores(); while (availableDataStores.hasNext()) { availableDS.add(availableDataStores.next()); } return availableDS.iterator(); }
Iterator<DataStoreFactorySpi> it = DataStoreFinder.getAllDataStores(); while (it.hasNext()) { DataStoreFactorySpi factory = it.next();
public GTDataStoreFootprintProvider( Map<String, Serializable> params, String typeName, Filter filter) throws IOException { store = DataStoreFinder.getDataStore(params); if (store == null) { throw new IOException("Coould not create footprint data store from params: " + params); } if (typeName != null) { this.featureSource = store.getFeatureSource(typeName); } else { this.featureSource = store.getFeatureSource("footprints"); } this.filter = filter; }
for (Iterator<DataStoreFactorySpi> iter = DataStoreFinder.getAvailableDataStores(); iter.hasNext(); ) { factoryList.add(iter.next());
@SuppressWarnings("unchecked") public void testGetAllDataStores() { Iterator<DataStoreFactorySpi> availableDataStores; availableDataStores = DataStoreFinder.getAllDataStores(); assertNotNull(availableDataStores); assertTrue(availableDataStores.hasNext()); DataStoreFactorySpi dsf1 = availableDataStores.next(); assertTrue(availableDataStores.hasNext()); DataStoreFactorySpi dsf2 = availableDataStores.next(); assertFalse(availableDataStores.hasNext()); assertNotNull(dsf1); assertNotNull(dsf2); // do not assume iteration order... if (dsf1 instanceof MockUnavailableDataStoreFactory) { assertTrue(dsf2 instanceof MockDataStoreFactory); } else { assertTrue(dsf1 instanceof MockDataStoreFactory); assertTrue(dsf2 instanceof MockUnavailableDataStoreFactory); } }
/** * Builds a datastore from a property file configuration, using GeoTools default convention as * well as ImageMosaic own one */ public static DataStore getDataStore(Properties configuration) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { // first try out the default GeoTools approach final DataStore dataStore = DataStoreFinder.getDataStore(configuration); if (dataStore == null) { // use ImageMosaic bizarre own way final String spiClass = (String) configuration.get("SPI"); DataStoreFactorySpi spi = (DataStoreFactorySpi) Class.forName(spiClass).newInstance(); Map<String, Serializable> datastoreParams = Utils.filterDataStoreParams(configuration, spi); return spi.createDataStore(datastoreParams); } return null; }
@SuppressWarnings("unchecked") public void testGetAvailableDataStores() { Iterator<DataStoreFactorySpi> availableDataStores; availableDataStores = DataStoreFinder.getAvailableDataStores(); assertNotNull(availableDataStores); assertTrue(availableDataStores.hasNext()); DataStoreFactorySpi dsf = availableDataStores.next(); assertFalse(availableDataStores.hasNext()); assertTrue(dsf instanceof MockDataStoreFactory); }
/** * Finds all implemtaions of DataAccessFactory which have registered using * the services mechanism, regardless weather it has the appropriate * libraries on the classpath. * * @return An iterator over all discovered datastores which have registered * factories */ public static synchronized Iterator<DataAccessFactory> getAllDataStores() { Set<DataAccessFactory> all = new HashSet<DataAccessFactory>(); Iterator<DataStoreFactorySpi> allDataStores = DataStoreFinder.getAllDataStores(); Iterator<DataAccessFactory> allDataAccess = getAllDataStores(getServiceRegistry(), DataAccessFactory.class); while (allDataStores.hasNext()) { DataStoreFactorySpi next = allDataStores.next(); all.add(next); } while (allDataAccess.hasNext()) { all.add(allDataAccess.next()); } return all.iterator(); }
/** * Load a quick repository from a properties file. * * <p>This is useful for test cases; the format is: * * <pre><code> * nameA=param=value,param2=value2,... * nameB=param=value,param2=value2,... * </code></pre> * * @throws IOException * @throws FileNotFoundException */ public void load(File propertiesFile) throws Exception { Properties properties = new Properties(); properties.load(new FileInputStream(propertiesFile)); for (Iterator i = properties.entrySet().iterator(); i.hasNext(); ) { Map.Entry<String, String> entry = (Map.Entry) i.next(); String name = (String) entry.getKey(); String definition = (String) entry.getValue(); Map<String, Serializable> params = definition(definition); DataStore dataStore = DataStoreFinder.getDataStore(params); register(name, dataStore); } }
/** Populates the list of available data stores that can be connected to. */ private void populateAvailableDataStores() { DataAccessFactory fac = null; logger.debug("Available data store factories:"); Iterator<DataStoreFactorySpi> iterator = DataStoreFinder.getAvailableDataStores(); while (iterator.hasNext()) { fac = iterator.next(); logger.debug("\t" + fac.getDisplayName()); availableDataStoreList.add(fac.getDisplayName()); } }
Iterator<DataStoreFactorySpi> it = DataStoreFinder.getAllDataStores(); while(it.hasNext()) { DataStoreFactorySpi factory = it.next();
private SimpleFeatureIterator getFeatureIterator() throws IOException { try { Map<String, Object> map = new HashMap<String, Object>(); map.put("url", shapeFileUrl); DataStore shapefile = DataStoreFinder.getDataStore(map); int index = shapeFileUrl.getPath().lastIndexOf('/'); int startIndex = (index == -1) ? 0 : (index + 1); index = shapeFileUrl.getPath().lastIndexOf('.'); int endIndex = (index == -1) ? shapeFileUrl.getPath().length() : index; String layerName = shapeFileUrl.getPath().substring(startIndex, endIndex); SimpleFeatureSource contents = shapefile.getFeatureSource(layerName); featureColl = contents.getFeatures(); total = featureColl.size(); logTotalInfo(); return featureColl.features(); } catch (IOException ex) { logError(ex, "Cannot open shape file"); throw ex; } }
/** * Checks each available datasource implementation in turn and returns the * first one which claims to support the resource identified by the params * object. * * @param params A Map object which contains a defenition of the resource * to connect to. for file based resources the property 'url' * should be set within this Map. * * @return The first datasource which claims to process the required * resource, returns null if none can be found. * * @throws IOException If a suitable loader can be found, but it can not be * attached to the specified resource without errors. */ public static synchronized DataStore getDataStore(Map params) throws IOException { Iterator<DataStoreFactorySpi> ps = getAvailableDataStores(); DataAccess<? extends FeatureType, ? extends Feature> dataStore; dataStore = DataAccessFinder.getDataStore(params, ps); return (DataStore) dataStore; }
Iterator<DataStoreFactorySpi> it = DataStoreFinder.getAllDataStores(); while(it.hasNext()) { DataStoreFactorySpi factory = it.next();
public void createSchema(SimpleFeatureType featureType) throws IOException { File f = new File(cache.directory, featureType.getTypeName() + ".shp"); Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("url", URLs.fileToUrl(f)); params.put("filetype", "shapefile"); DataStore ds = null; try { ds = DataStoreFinder.getDataStore(params); if (ds != null) { ds.createSchema(featureType); ds.dispose(); cache.refreshCacheContents(); } } catch (Exception e) { throw (IOException) new IOException("Error creating new data store").initCause(e); } if (ds == null) { throw new IOException("Could not find the shapefile data store in the classpath"); } }
/** * Finds all implemtaions of DataAccessFactory which have registered using * the services mechanism, and that have the appropriate libraries on the * classpath. * * @return An iterator over all discovered datastores which have registered * factories, and whose available method returns true. */ public static synchronized Iterator<DataAccessFactory> getAvailableDataStores() { FactoryRegistry serviceRegistry = getServiceRegistry(); Set<DataAccessFactory> availableDS = getAvailableDataStores(serviceRegistry, DataAccessFactory.class); Iterator<DataStoreFactorySpi> availableDataStores = DataStoreFinder .getAvailableDataStores(); while (availableDataStores.hasNext()) { availableDS.add(availableDataStores.next()); } return availableDS.iterator(); }