001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/model/feature/schema/DefaultFeatureType.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 037 package org.deegree.model.feature.schema; 038 039 import java.io.Serializable; 040 import java.net.URI; 041 import java.util.ArrayList; 042 import java.util.List; 043 044 import org.deegree.datatypes.QualifiedName; 045 import org.deegree.datatypes.Types; 046 047 /** 048 * Default implementation for GML feature types. 049 * 050 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a> 051 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a> 052 * 053 * @author last edited by: $Author: mschneider $ 054 * 055 * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $ 056 */ 057 public class DefaultFeatureType implements FeatureType, Serializable { 058 059 private static final long serialVersionUID = -4774232985192401467L; 060 061 private QualifiedName name; 062 063 private boolean isAbstract; 064 065 private URI schemaLocation; 066 067 private PropertyType[] properties; 068 069 private GeometryPropertyType[] geometryProperties; 070 071 /** 072 * Creates a new instance of <code>DefaultFeatureType</code> from the given parameters. 073 * 074 * @param name 075 * @param isAbstract 076 * @param properties 077 */ 078 public DefaultFeatureType( QualifiedName name, boolean isAbstract, PropertyType[] properties ) { 079 this.name = name; 080 this.isAbstract = isAbstract; 081 this.properties = properties; 082 } 083 084 /** 085 * Creates a new instance of <code>DefaultFeatureType</code> from the given parameters. 086 * 087 * @param name 088 * @param isAbstract 089 * @param schemaLocation 090 * @param properties 091 */ 092 public DefaultFeatureType( QualifiedName name, boolean isAbstract, URI schemaLocation, PropertyType[] properties ) { 093 this( name, isAbstract, properties ); 094 this.schemaLocation = schemaLocation; 095 } 096 097 /** 098 * returns the name of the FeatureType 099 */ 100 public QualifiedName getName() { 101 return this.name; 102 } 103 104 /** 105 * Returns whether this feature type is abstract or not. 106 * 107 * @return true, if the feature type is abstract, false otherwise 108 */ 109 public boolean isAbstract() { 110 return this.isAbstract; 111 } 112 113 /** 114 * returns the namespace of the feature type (maybe null) 115 * 116 * @return the namespace of the feature type (maybe <code>null</code>) 117 */ 118 public URI getNameSpace() { 119 return this.name.getNamespace(); 120 } 121 122 /** 123 * returns the location of the XML schema defintion assigned to a namespace 124 * 125 * @return the location of the XML schema defintion assigned to a namespace 126 */ 127 public URI getSchemaLocation() { 128 return this.schemaLocation; 129 } 130 131 /** 132 * returns the name of the property a the passed index position 133 */ 134 public QualifiedName getPropertyName( int index ) { 135 return this.properties[index].getName(); 136 } 137 138 /** 139 * returns the properties of this feature type 140 * 141 */ 142 public PropertyType[] getProperties() { 143 return this.properties; 144 } 145 146 /** 147 * returns a property of this feature type identified by its name 148 */ 149 public PropertyType getProperty( QualifiedName name ) { 150 PropertyType ftp = null; 151 // TODO use Map for improved lookup 152 for ( int i = 0; i < this.properties.length; i++ ) { 153 if ( this.properties[i].getName().getLocalName().equals( name.getLocalName() ) ) { 154 URI u1 = this.properties[i].getName().getNamespace(); 155 URI u2 = name.getNamespace(); 156 if ( ( u1 == null && u2 == null ) || ( u1 != null && u1.equals( u2 ) ) ) { 157 ftp = this.properties[i]; 158 break; 159 } 160 } 161 } 162 return ftp; 163 } 164 165 /** 166 * @param name 167 * @param quirk 168 * if true, only the local names are considered (and namespaces are ignored) 169 * @return the property, or null, if none was found 170 */ 171 public PropertyType getProperty( QualifiedName name, boolean quirk ) { 172 if ( !quirk ) { 173 return getProperty( name ); 174 } 175 176 PropertyType ftp = null; 177 // TODO use Map for improved lookup 178 for ( int i = 0; i < this.properties.length; i++ ) { 179 if ( this.properties[i].getName().getLocalName().equals( name.getLocalName() ) ) { 180 return properties[i]; 181 } 182 } 183 return ftp; 184 } 185 186 /** 187 * Returns the spatial properties of the feature type. 188 * 189 * @return the spatial properties of the feature type. 190 */ 191 public GeometryPropertyType[] getGeometryProperties() { 192 if ( this.geometryProperties == null ) { 193 List<PropertyType> geometryPropertyList = new ArrayList<PropertyType>(); 194 for ( int i = 0; i < properties.length; i++ ) { 195 if ( properties[i].getType() == Types.GEOMETRY ) { 196 geometryPropertyList.add( properties[i] ); 197 } 198 } 199 200 this.geometryProperties = new GeometryPropertyType[geometryPropertyList.size()]; 201 this.geometryProperties = geometryPropertyList.toArray( this.geometryProperties ); 202 203 } 204 return this.geometryProperties; 205 } 206 207 /** 208 * returns true if the passed FeatureType equals this FeatureType. Two FeatureTypes are equal if they have the same 209 * qualified name 210 * 211 * @return <code>true</code> if the passed FeatureType equals this FeatureType. 212 */ 213 public boolean equals( FeatureType featureType ) { 214 return featureType.getName().equals( this.name ); 215 } 216 217 /** 218 * returns true if <code>other</code> is of type 219 * 220 * @see FeatureType and #equals(FeatureType) is true 221 */ 222 @Override 223 public boolean equals( Object other ) { 224 if ( other instanceof FeatureType ) { 225 return equals( (FeatureType) other ); 226 } 227 return false; 228 } 229 230 @Override 231 public String toString() { 232 String ret = ""; 233 ret += "name = " + name + "\n"; 234 ret += "properties = "; 235 for ( int i = 0; i < properties.length; i++ ) { 236 ret += properties[i].getName() + " " + properties[i].getType() + "\n"; 237 } 238 return ret; 239 } 240 }