001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/io/datastore/schema/MappedGMLId.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 package org.deegree.io.datastore.schema;
044
045 import org.deegree.io.datastore.DatastoreTransaction;
046 import org.deegree.io.datastore.FeatureId;
047 import org.deegree.io.datastore.idgenerator.IdGenerationException;
048 import org.deegree.io.datastore.idgenerator.IdGenerator;
049 import org.deegree.io.datastore.schema.content.MappingField;
050
051 /**
052 * Defines how values for "gml:id" attributes for a certain feature type are generated and
053 * which columns are used to store it.
054 *
055 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
056 * @author last edited by: $Author: apoth $
057 *
058 * @version $Revision: 9342 $, $Date: 2007-12-27 13:32:57 +0100 (Do, 27 Dez 2007) $
059 */
060 public class MappedGMLId {
061
062 /**
063 * Used to represent the 'identityPart' information.
064 */
065 public static enum IDPART_INFO {
066
067 /**
068 * No 'identityPart' information available.
069 */
070 noIDInfo,
071
072 /**
073 * Feature id determines feature identity solely.
074 */
075 isIDPart,
076
077 /**
078 * Feature id is not part of the feature identity -> property values determine if
079 * two features are 'equal'.
080 */
081 notIDPart
082 }
083
084 private String prefix;
085
086 private MappingField[] idFields;
087
088 private String separator;
089
090 private IdGenerator idGenerator;
091
092 private IDPART_INFO idPartInfo;
093
094 private boolean isIdentityPart;
095
096 /**
097 * Creates a new instance of <code>MappedGMLId</code> from the given parameters.
098 *
099 * @param prefix
100 * @param separator
101 * @param idFields
102 * @param idGenerator
103 * @param idPartInfo
104 */
105 public MappedGMLId( String prefix, String separator, MappingField[] idFields,
106 IdGenerator idGenerator, IDPART_INFO idPartInfo ) {
107 this.prefix = prefix;
108 this.separator = separator;
109 this.idFields = idFields;
110 this.idGenerator = idGenerator;
111 this.idPartInfo = idPartInfo;
112 if (this.idPartInfo == IDPART_INFO.isIDPart) {
113 setIdentityPart(true);
114 }
115 }
116
117 /**
118 * Returns the number of <code>MappingField</code>s that constitute the "gml:id".
119 *
120 * @return the number of MappingFields
121 */
122 public int getKeySize() {
123 return this.idFields.length;
124 }
125
126 /**
127 * Returns the <code>MappingField</code>s that are used to build the "gml:id".
128 *
129 * @return the id fields
130 */
131 public MappingField[] getIdFields() {
132 return this.idFields;
133 }
134
135 /**
136 * Returns the prefix.
137 *
138 * @return the prefix
139 */
140 public String getPrefix() {
141 return this.prefix;
142 }
143
144 /**
145 * Returns the separator.
146 *
147 * @return the separator
148 */
149 public String getSeparator() {
150 return separator;
151 }
152
153 /**
154 * Returns whether the configuration explicitly defines that the id has to be considered when
155 * two features are checked for equality.
156 *
157 * @return 'identityPart' information
158 */
159 public IDPART_INFO getIdPartInfo () {
160 return this.idPartInfo;
161 }
162
163 /**
164 * Returns whether the id has to be considered when two features are checked for equality.
165 *
166 * @return true, if the feature id is part of the feature's identity
167 */
168 public boolean isIdentityPart () {
169 return this.isIdentityPart;
170 }
171
172 /**
173 * Sets the 'identiyPart' information.
174 *
175 * @param isIdentityPart
176 * set to true, if feature id should determine feature's identity solely
177 */
178 public void setIdentityPart (boolean isIdentityPart) {
179 this.isIdentityPart = isIdentityPart;
180 }
181
182 /**
183 * TODO remove this. Just a quick hack to make ParentIdGenerator work...
184 *
185 * @return IdGenerator that is used to generate new feature ids
186 */
187 public IdGenerator getIdGenerator () {
188 return this.idGenerator;
189 }
190
191 /**
192 * Generates a new and unique feature identifier.
193 *
194 * @param ft
195 * @param ta
196 * @return a new and unique feature identifier.
197 * @throws IdGenerationException
198 */
199 FeatureId generateFid (MappedFeatureType ft, DatastoreTransaction ta) throws IdGenerationException {
200 return this.idGenerator.getNewId(ft, ta);
201 }
202 }