001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-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: package org.geotools.feature.collection;
017:
018: import java.io.IOException;
019:
020: import org.geotools.data.FeatureReader;
021: import org.geotools.data.collection.DelegateFeatureReader;
022: import org.geotools.feature.CollectionListener;
023: import org.geotools.feature.FeatureCollection;
024: import org.geotools.feature.FeatureIterator;
025: import org.geotools.feature.FeatureList;
026: import org.geotools.feature.FeatureType;
027: import org.geotools.feature.IllegalAttributeException;
028: import org.geotools.feature.visitor.FeatureVisitor;
029: import org.opengis.filter.Filter;
030: import org.opengis.filter.sort.SortBy;
031: import org.geotools.geometry.jts.ReferencedEnvelope;
032:
033: import com.vividsolutions.jts.geom.Envelope;
034: import com.vividsolutions.jts.geom.Geometry;
035:
036: /**
037: * Implementation of FeatureList to get you started.
038: * You will need to provide a FeatureState for collection attributes, and
039: * implement the following:
040: * <ul>
041: * <li>features()
042: * <li>close(FeatureIterator)
043: * <li>getSchema()
044: * <li>accepts(FeatureVisitor)
045: * <li>subList(Filter)
046: * <li>subCollection(Filter)
047: * <li>sort(SortBy)
048: * </ul>
049: * @author Jody Garnett, Refractions Research Inc.
050: */
051: public abstract class AbstractFeatureList extends AbstractResourceList
052: implements FeatureList {
053: FeatureState state;
054:
055: /** Feature methods will be delegated to provided state */
056: protected AbstractFeatureList(FeatureState state) {
057: this .state = state;
058: }
059:
060: /** Feature methods will be delegated to provided state */
061: protected AbstractFeatureList(FeatureCollection collection) {
062: this .state = new SubFeatureState(collection, this );
063: }
064:
065: //
066: // FeatureCollection - Feature methods
067: //
068: public FeatureCollection getParent() {
069: return state.getParent();
070: }
071:
072: public void setParent(FeatureCollection collection) {
073: state.setParent(collection);
074: }
075:
076: public FeatureType getFeatureType() {
077: return state.getFeatureType();
078: }
079:
080: public String getID() {
081: return state.getId();
082: }
083:
084: public Object[] getAttributes(Object[] attributes) {
085: return state.getAttributes(attributes);
086: }
087:
088: public Object getAttribute(String xPath) {
089: return state.getAttribute(xPath);
090: }
091:
092: public Object getAttribute(int index) {
093: return state.getAttribute(index);
094: }
095:
096: public void setAttribute(int position, Object val)
097: throws IllegalAttributeException,
098: ArrayIndexOutOfBoundsException {
099: state.setAttribute(position, val);
100: }
101:
102: public int getNumberOfAttributes() {
103: return state.getNumberOfAttributes();
104: }
105:
106: public void setAttribute(String xPath, Object attribute)
107: throws IllegalAttributeException {
108: state.setAttribute(xPath, attribute);
109: }
110:
111: public Geometry getDefaultGeometry() {
112: return state.getDefaultGeometry();
113: }
114:
115: public void setDefaultGeometry(Geometry geometry)
116: throws IllegalAttributeException {
117: state.setDefaultGeometry(geometry);
118: }
119:
120: public ReferencedEnvelope getBounds() {
121: return ReferencedEnvelope.reference(state.getBounds());
122: }
123:
124: //
125: // FeatureCollection - Events
126: //
127: public void addListener(CollectionListener listener) {
128: state.addListener(listener);
129: }
130:
131: public void removeListener(CollectionListener listener)
132: throws NullPointerException {
133: state.removeListener(listener);
134: }
135:
136: //
137: // FeatureCollection - Feature Access
138: //
139: public FeatureIterator features() {
140: // TODO Auto-generated method stub
141: return null;
142: }
143:
144: public void close(FeatureIterator close) {
145: // TODO Auto-generated method stub
146: }
147:
148: public FeatureType getSchema() {
149: // TODO Auto-generated method stub
150: return null;
151: }
152:
153: public void accepts(FeatureVisitor visitor) throws IOException {
154: // TODO Auto-generated method stub
155: }
156:
157: //
158: // FeatureCollection - Collection API
159: //
160: public FeatureList subList(Filter filter) {
161: // TODO Auto-generated method stub
162: return null;
163: }
164:
165: public FeatureCollection subCollection(Filter filter) {
166: // TODO Auto-generated method stub
167: return null;
168: }
169:
170: public FeatureList sort(SortBy order) {
171: // TODO Auto-generated method stub
172: return null;
173: }
174:
175: //
176: // FeatureCollection - Legacy
177: //
178: public FeatureReader reader() throws IOException {
179: return new DelegateFeatureReader(getSchema(), features());
180: }
181:
182: public int getCount() throws IOException {
183: return size();
184: }
185:
186: public FeatureCollection collection() throws IOException {
187: return this;
188: }
189: }
|