001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-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: */
017: package org.geotools.data.feature.adapter;
018:
019: import java.io.IOException;
020: import java.util.Collections;
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: import org.geotools.data.DataAccess;
025: import org.geotools.data.DataAccessFactory;
026: import org.geotools.data.DataStore;
027: import org.geotools.data.DataStoreFactorySpi;
028: import org.geotools.data.DataStoreFinder;
029: import org.geotools.data.feature.FeatureAccess;
030: import org.geotools.feature.iso.simple.SimpleFeatureFactoryImpl;
031: import org.geotools.util.SimpleInternationalString;
032: import org.opengis.feature.simple.SimpleFeatureFactory;
033: import org.opengis.util.InternationalString;
034:
035: /**
036: * A {@link DataAccessFactory} that adapts any available geotools
037: * {@link DataStore} to the {@link FeatureAccess} interface.
038: *
039: * @author Gabriel Roldan, Axios Engineering
040: * @version $Id: FeatureAccessFactoryAdapter.java 25814 2007-06-12 12:03:41Z groldan $
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/community-schemas/community-schema-ds/src/main/java/org/geotools/data/feature/adapter/FeatureAccessFactoryAdapter.java $
042: * @since 2.4
043: */
044: public class FeatureAccessFactoryAdapter implements DataAccessFactory {
045:
046: /**
047: * @param expected
048: * {@link Map} instance suitable for a
049: * {@link DataStoreFactorySpi#canProcess(Map)}
050: */
051: public boolean canAccess(Object params) {
052: if (!(params instanceof Map)) {
053: return false;
054: }
055: try {
056: DataStore dataStore = DataStoreFinder
057: .getDataStore((Map) params);
058: return dataStore != null;
059: } catch (IOException e) {
060: return false;
061: }
062: }
063:
064: public boolean canCreateContent(Object arg0) {
065: return false;
066: }
067:
068: public DataAccess createAccess(Object params) throws IOException {
069: DataStore dataStore = DataStoreFinder
070: .getDataStore((Map) params);
071: if (dataStore instanceof DataAccess) {
072: return (DataAccess) dataStore;
073: }
074: SimpleFeatureFactory attributeFactory = new SimpleFeatureFactoryImpl();
075: FeatureAccessAdapter adapter = new FeatureAccessAdapter(
076: dataStore, attributeFactory);
077: return adapter;
078: }
079:
080: public Object createAccessBean() {
081: return new HashMap();
082: }
083:
084: public DataAccess createContent(Object bean) {
085: throw new UnsupportedOperationException();
086: }
087:
088: public Object createContentBean() {
089: throw new UnsupportedOperationException();
090: }
091:
092: public InternationalString getName() {
093: return new SimpleInternationalString(
094: "FeatureAccess adapter for DataStores");
095: }
096:
097: public boolean isAvailable() {
098: return true;
099: }
100:
101: public Map getImplementationHints() {
102: return Collections.EMPTY_MAP;
103: }
104:
105: }
|