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.net.URI;
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: import org.geotools.catalog.ServiceInfo;
025: import org.geotools.data.DataStore;
026: import org.geotools.data.FeatureReader;
027: import org.geotools.data.FeatureSource;
028: import org.geotools.data.FeatureWriter;
029: import org.geotools.data.LockingManager;
030: import org.geotools.data.Query;
031: import org.geotools.data.Source;
032: import org.geotools.data.Transaction;
033: import org.geotools.data.feature.FeatureAccess;
034: import org.geotools.data.feature.FeatureSource2;
035: import org.geotools.feature.FeatureType;
036: import org.geotools.feature.SchemaException;
037: import org.geotools.feature.iso.Types;
038: import org.opengis.feature.simple.SimpleFeatureFactory;
039: import org.opengis.feature.type.AttributeDescriptor;
040: import org.opengis.feature.type.Name;
041: import org.opengis.filter.Filter;
042:
043: /**
044: *
045: * @author Gabriel Roldan, Axios Engineering
046: * @version $Id: FeatureAccessAdapter.java 26649 2007-08-22 09:55:31Z groldan $
047: * @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/FeatureAccessAdapter.java $
048: * @since 2.4
049: */
050: public class FeatureAccessAdapter implements FeatureAccess {
051:
052: private DataStore store;
053:
054: private SimpleFeatureFactory attributeFactory;
055:
056: public FeatureAccessAdapter(DataStore dataStore,
057: SimpleFeatureFactory attributeFactory) {
058: if (dataStore == null) {
059: throw new NullPointerException("dataStore");
060: }
061: this .attributeFactory = attributeFactory;
062: this .store = dataStore;
063: }
064:
065: public void createSchema(FeatureType featureType)
066: throws IOException {
067: store.createSchema(featureType);
068: }
069:
070: public FeatureReader getFeatureReader(Query query,
071: Transaction transaction) throws IOException {
072: return store.getFeatureReader(query, transaction);
073: }
074:
075: public FeatureSource getFeatureSource(String typeName)
076: throws IOException {
077: return store.getFeatureSource(typeName);
078: }
079:
080: public FeatureWriter getFeatureWriter(String typeName,
081: Filter filter, Transaction transaction) throws IOException {
082: return store.getFeatureWriter(typeName, filter, transaction);
083: }
084:
085: public FeatureWriter getFeatureWriter(String typeName,
086: Transaction transaction) throws IOException {
087: return store.getFeatureWriter(typeName, transaction);
088: }
089:
090: public FeatureWriter getFeatureWriterAppend(String typeName,
091: Transaction transaction) throws IOException {
092: return store.getFeatureWriterAppend(typeName, transaction);
093: }
094:
095: public LockingManager getLockingManager() {
096: return store.getLockingManager();
097: }
098:
099: public FeatureType getSchema(String typeName) throws IOException {
100: return store.getSchema(typeName);
101: }
102:
103: public String[] getTypeNames() throws IOException {
104: return store.getTypeNames();
105: }
106:
107: public FeatureSource getView(Query query) throws IOException,
108: SchemaException {
109: return store.getView(query);
110: }
111:
112: public void updateSchema(String typeName, FeatureType featureType)
113: throws IOException {
114: store.updateSchema(typeName, featureType);
115: }
116:
117: // ///////////////////////////////////////////////////
118:
119: public Source access(Name typeName) {
120: FeatureSource2 source;
121: if (store instanceof FeatureAccess) {
122: FeatureAccess faccess = (FeatureAccess) store;
123: source = (FeatureSource2) faccess.access(typeName);
124: } else {
125: try {
126: String localPart = typeName.getLocalPart();
127: FeatureSource featureSource = store
128: .getFeatureSource(localPart);
129: source = new FeatureSource2Adapter(this , featureSource,
130: attributeFactory);
131: } catch (IOException e) {
132: e.printStackTrace();
133: throw (RuntimeException) new RuntimeException(e
134: .getMessage()).initCause(e);
135: }
136: }
137: return source;
138: }
139:
140: public Object describe(Name typeName) {
141: AttributeDescriptor descriptor;
142: if (store instanceof FeatureAccess) {
143: FeatureAccess faccess = (FeatureAccess) store;
144: descriptor = (AttributeDescriptor) faccess
145: .describe(typeName);
146: } else {
147: Source source = access(typeName);
148: descriptor = (AttributeDescriptor) source.describe();
149: }
150: return descriptor;
151: }
152:
153: public void dispose() {
154: if (store instanceof FeatureAccess) {
155: FeatureAccess faccess = (FeatureAccess) store;
156: faccess.dispose();
157: }
158: }
159:
160: public ServiceInfo getInfo() {
161: if (store instanceof FeatureAccess) {
162: FeatureAccess faccess = (FeatureAccess) store;
163: return faccess.getInfo();
164: }
165: throw new UnsupportedOperationException("Not yet implemented");
166: }
167:
168: public List getNames() {
169: if (store instanceof FeatureAccess) {
170: FeatureAccess faccess = (FeatureAccess) store;
171: return faccess.getNames();
172: }
173:
174: String[] typeNames;
175: try {
176: typeNames = getTypeNames();
177: } catch (IOException e) {
178: throw (RuntimeException) new RuntimeException()
179: .initCause(e);
180: }
181: int len = typeNames.length;
182: List names = new ArrayList(len);
183: try {
184: for (int i = 0; i < i; i++) {
185: String featureName = typeNames[i];
186: FeatureType schema;
187: schema = getSchema(featureName);
188: URI namespace = schema.getNamespace();
189: String nsUri = namespace == null ? null : namespace
190: .toString();
191: Name name = Types.typeName(nsUri, featureName);
192: names.add(name);
193: }
194: } catch (IOException e) {
195: throw (RuntimeException) new RuntimeException()
196: .initCause(e);
197: }
198: return names;
199: }
200:
201: }
|