001    //$HeadURL: svn+ssh://mschneider@svn.wald.intevation.org/deegree/base/trunk/src/org/deegree/model/feature/DefaultFeatureCollection.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    package org.deegree.model.feature;
037    
038    import java.io.Serializable;
039    import java.util.HashSet;
040    import java.util.Iterator;
041    import java.util.List;
042    import java.util.Set;
043    
044    import org.deegree.datatypes.QualifiedName;
045    import org.deegree.io.datastore.PropertyPathResolvingException;
046    import org.deegree.model.spatialschema.Envelope;
047    import org.deegree.model.spatialschema.GeometryException;
048    import org.deegree.ogcbase.PropertyPath;
049    
050    /**
051     * Represents a {@link FeatureCollection} that only contains <code>wfs:featureTuple</code> elements (as introduced by
052     * the draft WFS 1.2 spec).
053     * <p>
054     * NOTE: Some concepts of ordinary feature collections (like adding and removing of features) do not match well to this
055     * special kind of feature collection, mostly because it uses a <code>FeatureArrayPropertyType</code> for the
056     * <code>wfs:featureTuple</code> element. Thus, many methods inherited from {@link AbstractFeatureCollection} have no
057     * clear semantic and are not available.
058     *
059     * !!!Please note that most methods are not implemented yet!!!
060     *
061     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
062     * @version $Revision: 6840 $ $Date: 2007-05-07 10:27:43 +0200 (Mo, 07 Mai 2007) $
063     */
064    public class FeatureTupleCollection extends AbstractFeatureCollection implements Serializable {
065    
066        private static final long serialVersionUID = 2651676067288914826L;
067    
068        private int tupleLength;
069    
070        private List<Feature[]> tuples;
071    
072        private Set<Feature> allFeatures = new HashSet<Feature>();
073    
074        private Envelope envelope;
075    
076        FeatureTupleCollection( String id, List<Feature[]> tuples, int tupleLength ) {
077            super( id );
078            this.tuples = tuples;
079            this.tupleLength = tupleLength;
080            for ( Feature[] features : tuples ) {
081                assert features.length == tupleLength;
082                for ( Feature feature : features ) {
083                    allFeatures.add( feature );
084                }
085            }
086        }
087    
088        /*
089         * (non-Javadoc)
090         *
091         * @see org.deegree.model.feature.FeatureCollection#clear()
092         */
093        public void clear() {
094            allFeatures.clear();
095        }
096    
097        /**
098         * Returns the feature tuple at the given index.
099         *
100         * @param index
101         * @return the feature tuple at the given index
102         */
103        public Feature[] getTuple( int index ) {
104            return this.tuples.get( index );
105        }
106    
107        /**
108         * Returns the number of feature tuples contained in this collection.
109         *
110         * @return the number of feature tuples contained in this collection
111         */
112        public int numTuples() {
113            return this.tuples.size();
114        }
115    
116        /**
117         * Returns the length (number of features) of each tuple.
118         *
119         * @return the length (number of features) of each tuple.
120         */
121        public int tupleLength() {
122            return this.tupleLength;
123        }
124    
125        @Override
126        public synchronized Envelope getBoundedBy()
127                                throws GeometryException {
128    
129            Envelope combinedEnvelope = this.envelope;
130    
131            if ( combinedEnvelope == null && this.allFeatures.size() > 0 ) {
132                for ( Feature feature : this.allFeatures ) {
133                    Envelope nextFeatureEnvelope = feature.getBoundedBy();
134                    if ( combinedEnvelope == null ) {
135                        combinedEnvelope = nextFeatureEnvelope;
136                    } else if ( nextFeatureEnvelope != null ) {
137                        combinedEnvelope = combinedEnvelope.merge( nextFeatureEnvelope );
138                    }
139                }
140                this.envelope = combinedEnvelope;
141            }
142            return combinedEnvelope;
143        }
144    
145        public int size() {
146            return this.tuples.size();
147        }
148    
149        public void add( Feature feature ) {
150            throw new NoSuchMethodError();
151        }
152    
153        public Feature getFeature( int index ) {
154            return null;
155        }
156    
157        public Feature getFeature( String id ) {
158            throw new NoSuchMethodError();
159        }
160    
161        public Iterator<Feature> iterator() {
162            throw new NoSuchMethodError();
163        }
164    
165        public Feature remove( Feature feature ) {
166            throw new NoSuchMethodError();
167        }
168    
169        public Feature remove( int index ) {
170            throw new NoSuchMethodError();
171        }
172    
173        public Feature[] toArray() {
174            throw new NoSuchMethodError();
175        }
176    
177        public void addProperty( FeatureProperty property ) {
178            throw new NoSuchMethodError();
179        }
180    
181        public FeatureProperty getDefaultProperty( PropertyPath path )
182                                throws PropertyPathResolvingException {
183            throw new NoSuchMethodError();
184        }
185    
186        public void removeProperty( QualifiedName propertyName ) {
187            throw new NoSuchMethodError();
188        }
189    
190        public void replaceProperty( FeatureProperty oldProperty, FeatureProperty newProperty ) {
191            throw new NoSuchMethodError();
192        }
193    
194        public void setProperty( FeatureProperty property, int index ) {
195            throw new NoSuchMethodError();
196        }
197    
198        /*
199         * (non-Javadoc)
200         *
201         * @see org.deegree.model.feature.Feature#cloneDeep()
202         */
203        public Feature cloneDeep()
204                                throws CloneNotSupportedException {
205            throw new CloneNotSupportedException();
206        }
207    
208    }