001: package org.geotools.feature.iso.collection;
002:
003: import java.util.Collection;
004: import java.util.Iterator;
005: import java.util.List;
006:
007: import org.geotools.util.NullProgressListener;
008: import org.opengis.feature.Feature;
009: import org.opengis.feature.FeatureCollection;
010: import org.opengis.feature.FeatureVisitor;
011: import org.opengis.feature.GeometryAttribute;
012: import org.opengis.feature.type.AttributeDescriptor;
013: import org.opengis.feature.type.AttributeType;
014: import org.opengis.feature.type.FeatureCollectionType;
015: import org.opengis.feature.type.Name;
016: import org.opengis.feature.type.PropertyDescriptor;
017: import org.opengis.geometry.BoundingBox;
018: import org.opengis.referencing.crs.CoordinateReferenceSystem;
019: import org.opengis.util.ProgressListener;
020:
021: /**
022: * Abstract feature collection to be used as base for FeatureCollection
023: * implementations. <br>
024: * <p>
025: * Subclasses must implement the following methods:
026: * <ul>
027: * <li>{@link Collection#size()}
028: * <li>{@link org.geotools.feature.collection.AbstractResourceCollection#openIterator()}
029: * <li>{@link org.geotools.feature.collection.AbstractResourceCollection#closeIterator(Iterator)}
030: * </ul>
031: * </p>
032: * <br>
033: * <p>
034: * This implementation of FeatureCollection uses a delegate to satisfy the
035: * methods of the {@link Feature} interface.
036: * </p>
037: *
038: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
039: *
040: */
041: public abstract class AbstractFeatureCollection extends
042: AbstractResourceCollection implements FeatureCollection {
043:
044: private FeatureState delegate;
045:
046: protected AbstractFeatureCollection(Collection values,
047: AttributeDescriptor descriptor, String id) {
048: this .delegate = new FeatureState(values, descriptor, id, this );
049: }
050:
051: protected AbstractFeatureCollection(Collection values,
052: FeatureCollectionType type, String id) {
053: this .delegate = new FeatureState(values, type, id, this );
054: }
055:
056: public FeatureCollection subCollection(
057: org.opengis.filter.Filter filter) {
058: // TODO: inject a filter factory
059: return new SubFeatureCollection(this , filter, null);
060: }
061:
062: public FeatureCollection sort(org.opengis.filter.sort.SortBy order) {
063: throw new UnsupportedOperationException();
064: }
065:
066: public Collection memberTypes() {
067: return ((FeatureCollectionType) getType()).getMembers();
068: }
069:
070: public void putUserData(Object key, Object value) {
071: delegate.putUserData(key, value);
072: }
073:
074: public Object getUserData(Object key) {
075: return delegate.getUserData(key);
076: }
077:
078: public AttributeType getType() {
079: return delegate.getType();
080: }
081:
082: public boolean nillable() {
083: return delegate.nillable();
084: }
085:
086: public String getID() {
087: return delegate.getID();
088: }
089:
090: public CoordinateReferenceSystem getCRS() {
091: return delegate.getCRS();
092: }
093:
094: public void setCRS(CoordinateReferenceSystem crs) {
095: delegate.setCRS(crs);
096: }
097:
098: public BoundingBox getBounds() {
099: return delegate.getBounds();
100: }
101:
102: public GeometryAttribute getDefaultGeometry() {
103: return delegate.getDefaultGeometry();
104: }
105:
106: public void setDefaultGeometry(GeometryAttribute geom) {
107: delegate.setDefaultGeometry(geom);
108: }
109:
110: public void setValue(List newValue) throws IllegalArgumentException {
111: delegate.setValue(newValue);
112: }
113:
114: public List get(Name name) {
115: return delegate.get(name);
116: }
117:
118: public AttributeDescriptor getDescriptor() {
119: return delegate.getDescriptor();
120: }
121:
122: public PropertyDescriptor descriptor() {
123: return delegate.descriptor();
124: }
125:
126: public Name name() {
127: return delegate.name();
128: }
129:
130: public Object getValue() {
131: return delegate.getValue();
132: }
133:
134: public Collection attributes() {
135: return delegate.attributes();
136: }
137:
138: public Collection associations() {
139: return delegate.associations();
140: }
141:
142: public void setValue(Object newValue)
143: throws IllegalArgumentException {
144: delegate.setValue(newValue);
145: }
146:
147: /**
148: * Accepts a visitor, which then visits each feature in the collection.
149: */
150: public void accepts(FeatureVisitor visitor,
151: ProgressListener progress) {
152: Iterator iterator = null;
153: if (progress == null)
154: progress = new NullProgressListener();
155: try {
156: float size = size();
157: float position = 0;
158: progress.started();
159: for (iterator = iterator(); !progress.isCanceled()
160: && iterator.hasNext(); progress.progress(position++
161: / size)) {
162: try {
163: Feature feature = (Feature) iterator.next();
164: visitor.visit(feature);
165: } catch (Exception erp) {
166: progress.exceptionOccurred(erp);
167: }
168: }
169: } finally {
170: progress.complete();
171: close(iterator);
172: }
173: }
174:
175: public Object operation(Name arg0, List arg1) {
176: throw new UnsupportedOperationException(
177: "operation not supported yet");
178: }
179: }
|