001: package org.geotools.data.store;
002:
003: import java.io.IOException;
004: import java.util.ArrayList;
005: import java.util.Collection;
006: import java.util.Iterator;
007: import java.util.List;
008:
009: import org.geotools.data.FeatureReader;
010: import org.geotools.data.collection.DelegateFeatureReader;
011: import org.geotools.feature.CollectionListener;
012: import org.geotools.feature.FeatureCollection;
013: import org.geotools.feature.FeatureIterator;
014: import org.geotools.feature.FeatureList;
015: import org.geotools.feature.FeatureType;
016: import org.geotools.feature.IllegalAttributeException;
017: import org.geotools.feature.collection.DelegateFeatureIterator;
018: import org.geotools.feature.visitor.FeatureVisitor;
019: import org.geotools.geometry.jts.ReferencedEnvelope;
020: import org.geotools.util.ProgressListener;
021: import org.opengis.filter.Filter;
022: import org.opengis.filter.sort.SortBy;
023:
024: import com.vividsolutions.jts.geom.Envelope;
025: import com.vividsolutions.jts.geom.Geometry;
026:
027: /**
028: * FeatureCollection decorator which decorates a feature collection "re-typing"
029: * its schema based on attributes specified in a query.
030: *
031: * @author Justin Deoliveira, The Open Planning Project
032: *
033: */
034: public class ReTypingFeatureCollection implements FeatureCollection {
035:
036: FeatureCollection delegate;
037: FeatureType featureType;
038:
039: public ReTypingFeatureCollection(FeatureCollection delegate,
040: FeatureType featureType) {
041: this .delegate = delegate;
042: this .featureType = featureType;
043: }
044:
045: public FeatureReader reader() throws IOException {
046: return new DelegateFeatureReader(getSchema(), features());
047: }
048:
049: public FeatureIterator features() {
050: return new DelegateFeatureIterator(this , iterator());
051: }
052:
053: public void close(FeatureIterator close) {
054: close.close();
055: }
056:
057: public Iterator iterator() {
058: return new ReTypingIterator(delegate.iterator(), delegate
059: .getSchema(), featureType);
060: }
061:
062: public void close(Iterator close) {
063: ReTypingIterator reType = (ReTypingIterator) close;
064: delegate.close(reType.getDelegate());
065: }
066:
067: public void addListener(CollectionListener listener)
068: throws NullPointerException {
069: delegate.addListener(listener);
070: }
071:
072: public void removeListener(CollectionListener listener)
073: throws NullPointerException {
074: delegate.removeListener(listener);
075: }
076:
077: public FeatureType getFeatureType() {
078: return delegate.getFeatureType();
079: }
080:
081: public FeatureType getSchema() {
082: return featureType;
083: }
084:
085: public void accepts(FeatureVisitor visitor,
086: ProgressListener progress) throws IOException {
087: delegate.accepts(visitor, progress);
088: }
089:
090: public FeatureCollection subCollection(Filter filter) {
091: throw new UnsupportedOperationException();
092: }
093:
094: public FeatureList sort(SortBy order) {
095: throw new UnsupportedOperationException();
096: }
097:
098: public void purge() {
099: delegate.purge();
100: }
101:
102: public int size() {
103: return delegate.size();
104: }
105:
106: public void clear() {
107: delegate.clear();
108: }
109:
110: public boolean isEmpty() {
111: return delegate.isEmpty();
112: }
113:
114: public Object[] toArray() {
115: return toArray(new Object[size()]);
116: }
117:
118: public Object[] toArray(Object[] a) {
119: List list = new ArrayList();
120: Iterator i = iterator();
121: try {
122: while (i.hasNext()) {
123: list.add(i.next());
124: }
125:
126: return list.toArray(a);
127: } finally {
128: close(i);
129: }
130: }
131:
132: public boolean add(Object o) {
133: return delegate.add(o);
134: }
135:
136: public boolean contains(Object o) {
137: return delegate.add(o);
138: }
139:
140: public boolean remove(Object o) {
141: return delegate.remove(o);
142: }
143:
144: public boolean addAll(Collection c) {
145: return delegate.addAll(c);
146: }
147:
148: public boolean containsAll(Collection c) {
149: return delegate.containsAll(c);
150: }
151:
152: public boolean removeAll(Collection c) {
153: return delegate.removeAll(c);
154: }
155:
156: public boolean retainAll(Collection c) {
157: return delegate.retainAll(c);
158: }
159:
160: public String getID() {
161: return delegate.getID();
162: }
163:
164: public Object[] getAttributes(Object[] attributes) {
165: return delegate.getAttributes(attributes);
166: }
167:
168: public Object getAttribute(String xPath) {
169: return delegate.getAttribute(xPath);
170: }
171:
172: public Object getAttribute(int index) {
173: return delegate.getAttribute(index);
174: }
175:
176: public void setAttribute(int position, Object val)
177: throws IllegalAttributeException,
178: ArrayIndexOutOfBoundsException {
179: delegate.setAttribute(position, val);
180: }
181:
182: public int getNumberOfAttributes() {
183: return delegate.getNumberOfAttributes();
184: }
185:
186: public void setAttribute(String xPath, Object attribute)
187: throws IllegalAttributeException {
188: delegate.setAttribute(xPath, attribute);
189: }
190:
191: public Geometry getDefaultGeometry() {
192: return delegate.getDefaultGeometry();
193: }
194:
195: public void setDefaultGeometry(Geometry geometry)
196: throws IllegalAttributeException {
197: delegate.setDefaultGeometry(geometry);
198: }
199:
200: public ReferencedEnvelope getBounds() {
201: return delegate.getBounds();
202: }
203:
204: }
|