001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/model/feature/AbstractFeatureCollection.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 org.deegree.datatypes.QualifiedName; 039 import org.deegree.datatypes.Types; 040 import org.deegree.datatypes.UnknownTypeException; 041 import org.deegree.framework.log.ILogger; 042 import org.deegree.framework.log.LoggerFactory; 043 import org.deegree.model.feature.schema.PropertyType; 044 import org.deegree.model.spatialschema.Geometry; 045 import org.deegree.model.spatialschema.GeometryFactory; 046 import org.deegree.ogcbase.CommonNamespaces; 047 048 /** 049 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a> 050 * @author last edited by: $Author: apoth $ 051 * 052 * @version $Revision: 27011 $, $Date: 2010-09-24 15:49:08 +0200 (Fr, 24 Sep 2010) $ 053 */ 054 public abstract class AbstractFeatureCollection extends AbstractFeature implements FeatureCollection { 055 056 private static final ILogger LOG = LoggerFactory.getLogger( AbstractFeatureCollection.class ); 057 058 /** 059 * @param id 060 */ 061 public AbstractFeatureCollection( String id ) { 062 this( id, null ); 063 } 064 065 /** 066 * @param id 067 * @param name 068 * of the feature collection if <code>null</code> it will be set to wfs:FeatureCollection 069 */ 070 public AbstractFeatureCollection( String id, QualifiedName name ) { 071 super( id, null ); 072 073 PropertyType[] ftp = new PropertyType[1]; 074 if ( name == null ) { 075 name = new QualifiedName( CommonNamespaces.WFS_PREFIX, "FeatureCollection", CommonNamespaces.WFSNS ); 076 } 077 try { 078 ftp[0] = FeatureFactory.createPropertyType( new QualifiedName( "features" ), 079 Types.FEATURE_ARRAY_PROPERTY_NAME, true ); 080 } catch ( UnknownTypeException e ) { 081 LOG.logError( "Unreachable point reached.", e ); 082 } 083 this.featureType = FeatureFactory.createFeatureType( name, false, ftp ); 084 085 } 086 087 /** 088 * returns a Point with position 0/0 and no CRS 089 * 090 * @return a geometry 091 */ 092 public Geometry getDefaultGeometryPropertyValue() { 093 return GeometryFactory.createPoint( 0, 0, null ); 094 } 095 096 /** 097 * returns the value of a feature collection geometry properties 098 * 099 * @return array of all geometry property values 100 */ 101 public Geometry[] getGeometryPropertyValues() { 102 return new Geometry[0]; 103 } 104 105 /** 106 * returns all properties of a feature collection 107 * 108 * @return all properties of a feature 109 */ 110 public FeatureProperty[] getProperties() { 111 return new FeatureProperty[0]; 112 } 113 114 /** 115 * returns the properties of a feature collection at the passed index position 116 * 117 * @param index 118 * @return properties at the passed index position 119 */ 120 public FeatureProperty[] getProperties( int index ) { 121 // TODO 122 // a FeatureCollection may also have properties? 123 return null; 124 } 125 126 /** 127 * returns the default property of a feature collection with the passed name 128 * 129 * @param name 130 * @return named default property 131 */ 132 public FeatureProperty getDefaultProperty( QualifiedName name ) { 133 // TODO 134 // a FeatureCollection may also have properties? 135 return null; 136 } 137 138 /** 139 * returns the named properties of a feature collection 140 * 141 * @param name 142 * @return named properties 143 */ 144 public FeatureProperty[] getProperties( QualifiedName name ) { 145 // TODO 146 // a FeatureCollection may also have properties? 147 return null; 148 } 149 150 /** 151 * sets a property of a feature collection.<br> 152 * !!! this method is not implemented yet !!! 153 * 154 * @param property 155 */ 156 public void setProperty( FeatureProperty property ) { 157 // TODO 158 // a FeatureCollection may also have properties? 159 } 160 161 /** 162 * @see org.deegree.model.feature.FeatureCollection#addAll(org.deegree.model.feature.Feature[]) 163 */ 164 @Deprecated 165 public void addAll( Feature[] feature ) { 166 for ( int i = 0; i < feature.length; i++ ) { 167 add( feature[i] ); 168 } 169 } 170 171 public void addAllUncontained( Feature[] feature ) { 172 for ( int i = 0; i < feature.length; i++ ) { 173 Feature f = feature[i]; 174 Feature f2 = getFeature( f.getId() ); 175 if ( f2 == null || !f2.getId().equals( f.getId() ) ) { 176 add( feature[i] ); 177 } 178 } 179 } 180 181 /** 182 * @see org.deegree.model.feature.FeatureCollection#addAll(org.deegree.model.feature.FeatureCollection) 183 */ 184 @Deprecated 185 public void addAll( FeatureCollection fc ) { 186 int size = fc.size(); 187 for ( int i = 0; i < size; i++ ) { 188 add( fc.getFeature( i ) ); 189 } 190 } 191 192 public void addAllUncontained( FeatureCollection fc ) { 193 int size = fc.size(); 194 for ( int i = 0; i < size; i++ ) { 195 Feature f = fc.getFeature( i ); 196 Feature f2 = getFeature( f.getId() ); 197 if ( f2 == null || !f2.getId().equals( f.getId() ) ) { 198 add( f ); 199 } 200 } 201 } 202 203 /** 204 * removes a feature identified by its ID from the feature collection. If no feature with the passed ID is available 205 * nothing happens and <tt>null</tt> will be returned 206 * 207 * @param id 208 * @return the removed feature 209 */ 210 public Feature remove( String id ) { 211 Feature feat = getFeature( id ); 212 return remove( feat ); 213 } 214 215 }