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