001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/model/feature/schema/DefaultFeatureType.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstraße 19
030: 53177 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042: ---------------------------------------------------------------------------*/
043:
044: package org.deegree.model.feature.schema;
045:
046: import java.io.Serializable;
047: import java.net.URI;
048: import java.util.ArrayList;
049: import java.util.List;
050:
051: import org.deegree.datatypes.QualifiedName;
052: import org.deegree.datatypes.Types;
053:
054: /**
055: * Default implementation for GML feature types.
056: *
057: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
058: * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
059: *
060: * @author last edited by: $Author: apoth $
061: *
062: * @version 2.0, $Revision: 9343 $, $Date: 2007-12-27 05:30:32 -0800 (Thu, 27 Dec 2007) $
063: */
064: public class DefaultFeatureType implements FeatureType, Serializable {
065:
066: private static final long serialVersionUID = -4774232985192401467L;
067:
068: private QualifiedName name;
069:
070: private boolean isAbstract;
071:
072: private URI schemaLocation;
073:
074: private PropertyType[] properties;
075:
076: private GeometryPropertyType[] geometryProperties;
077:
078: /**
079: * Creates a new instance of <code>DefaultFeatureType</code> from the given parameters.
080: *
081: * @param name
082: * @param isAbstract
083: * @param properties
084: */
085: public DefaultFeatureType(QualifiedName name, boolean isAbstract,
086: PropertyType[] properties) {
087: this .name = name;
088: this .isAbstract = isAbstract;
089: this .properties = properties;
090: }
091:
092: /**
093: * Creates a new instance of <code>DefaultFeatureType</code> from the given parameters.
094: *
095: * @param name
096: * @param isAbstract
097: * @param schemaLocation
098: * @param properties
099: */
100: public DefaultFeatureType(QualifiedName name, boolean isAbstract,
101: URI schemaLocation, PropertyType[] properties) {
102: this (name, isAbstract, properties);
103: this .schemaLocation = schemaLocation;
104: }
105:
106: /**
107: * returns the name of the FeatureType
108: */
109: public QualifiedName getName() {
110: return this .name;
111: }
112:
113: /**
114: * Returns whether this feature type is abstract or not.
115: *
116: * @return true, if the feature type is abstract, false otherwise
117: */
118: public boolean isAbstract() {
119: return this .isAbstract;
120: }
121:
122: /**
123: * returns the namespace of the feature type (maybe null)
124: *
125: * @return the namespace of the feature type (maybe <code>null</code>)
126: */
127: public URI getNameSpace() {
128: return this .name.getNamespace();
129: }
130:
131: /**
132: * returns the location of the XML schema defintion assigned to a namespace
133: *
134: * @return the location of the XML schema defintion assigned to a namespace
135: */
136: public URI getSchemaLocation() {
137: return this .schemaLocation;
138: }
139:
140: /**
141: * returns the name of the property a the passed index position
142: */
143: public QualifiedName getPropertyName(int index) {
144: return this .properties[index].getName();
145: }
146:
147: /**
148: * returns the properties of this feature type
149: *
150: */
151: public PropertyType[] getProperties() {
152: return this .properties;
153: }
154:
155: /**
156: * returns a property of this feature type identified by its name
157: */
158: public PropertyType getProperty(QualifiedName name) {
159: PropertyType ftp = null;
160: // TODO use Map for improved lookup
161: for (int i = 0; i < this .properties.length; i++) {
162: if (this .properties[i].getName().getLocalName().equals(
163: name.getLocalName())) {
164: URI u1 = this .properties[i].getName().getNamespace();
165: URI u2 = name.getNamespace();
166: if ((u1 == null && u2 == null)
167: || (u1 != null && u1.equals(u2))) {
168: ftp = this .properties[i];
169: break;
170: }
171: }
172: }
173: return ftp;
174: }
175:
176: /**
177: * Returns the spatial properties of the feature type.
178: *
179: * @return the spatial properties of the feature type.
180: */
181: public GeometryPropertyType[] getGeometryProperties() {
182: if (this .geometryProperties == null) {
183: List geometryPropertyList = new ArrayList();
184: for (int i = 0; i < properties.length; i++) {
185: if (properties[i].getType() == Types.GEOMETRY) {
186: geometryPropertyList.add(properties[i]);
187: }
188: }
189:
190: this .geometryProperties = new GeometryPropertyType[geometryPropertyList
191: .size()];
192: this .geometryProperties = (GeometryPropertyType[]) geometryPropertyList
193: .toArray(this .geometryProperties);
194:
195: }
196: return this .geometryProperties;
197: }
198:
199: /**
200: * returns true if the passed FeatureType equals this FeatureType. Two FeatureTypes are equal if
201: * they have the same qualified name
202: *
203: * @return <code>true</code> if the passed FeatureType equals this FeatureType.
204: */
205: public boolean equals(FeatureType featureType) {
206: return featureType.getName().equals(this .name);
207: }
208:
209: /**
210: * returns true if <code>other</code> is of type
211: *
212: * @see FeatureType and #equals(FeatureType) is true
213: */
214: public boolean equals(Object other) {
215: if (other instanceof FeatureType) {
216: return equals((FeatureType) other);
217: }
218: return false;
219: }
220:
221: public String toString() {
222: String ret = "";
223: ret += "name = " + name + "\n";
224: ret += "properties = ";
225: for (int i = 0; i < properties.length; i++) {
226: ret += properties[i].getName() + " "
227: + properties[i].getType() + "\n";
228: }
229: return ret;
230: }
231: }
|