001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/wfs/operation/transaction/Insert.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.ogcwebservices.wfs.operation.transaction;
037    
038    import java.net.URI;
039    import java.util.ArrayList;
040    import java.util.HashSet;
041    import java.util.List;
042    import java.util.Set;
043    
044    import org.deegree.datatypes.QualifiedName;
045    import org.deegree.model.feature.Feature;
046    import org.deegree.model.feature.FeatureCollection;
047    
048    /**
049     * Represents an <code>Insert</code> operation as a part of a {@link Transaction} request.
050     *
051     * @author <a href="mailto:deshmukh@lat-lon.de">Anup Deshmukh </a>
052     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
053     * @author last edited by: $Author: mschneider $
054     *
055     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
056     */
057    public class Insert extends TransactionOperation {
058    
059        /**
060         * Generation strategies for feature ids.
061         */
062        public static enum ID_GEN {
063    
064            /** Use provided feature ids. */
065            USE_EXISTING,
066    
067            /** Use provided feature ids, generate new id if feature with same id already exists. */
068            REPLACE_DUPLICATE,
069    
070            /** Always generate new feature ids. */
071            GENERATE_NEW
072        }
073    
074        /** Always generate new feature ids. */
075        public static final String ID_GEN_GENERATE_NEW_STRING = "GenerateNew";
076    
077        /** Use provided feature ids. */
078        public static final String ID_GEN_USE_EXISTING_STRING = "UseExisting";
079    
080        /** Use provided feature ids, generate new id if feature with same id already exists. */
081        public static final String ID_GEN_REPLACE_DUPLICATE_STRING = "ReplaceDuplicate";
082    
083        private ID_GEN idGenMode;
084    
085        private URI srsName;
086    
087        private FeatureCollection fc;
088    
089        /**
090         * Creates a new <code>Insert</code> instance.
091         *
092         * @param handle
093         *            optional identifier for the operation (for error messsages)
094         * @param idGenMode
095         *            mode for feature id generation
096         * @param srsName
097         *            name of the spatial reference system
098         * @param fc
099         *            feature instances to be inserted, wrapped in a <code>FeatureCollection</code>
100         */
101        public Insert( String handle, ID_GEN idGenMode, URI srsName, FeatureCollection fc ) {
102            super( handle );
103            this.idGenMode = idGenMode;
104            this.srsName = srsName;
105            this.fc = fc;
106        }
107    
108        /**
109         * Returns the mode for id generation.
110         * <p>
111         * Must be one of the following:
112         * <ul>
113         * <li>ID_GEN.USE_EXISTING</li>
114         * <li>ID_GEN.REPLACE_DUPLICATE</li>
115         * <li>ID_GEN.GENERATE_NEW</li>
116         * </ul>
117         *
118         * @return the mode for id generation
119         */
120        public ID_GEN getIdGen() {
121            return this.idGenMode;
122        }
123    
124        /**
125         * Returns the asserted SRS of the features to be inserted.
126         *
127         * @return the asserted SRS of the features
128         */
129        public URI getSRSName() {
130            return this.srsName;
131        }
132    
133        /**
134         * Returns the feature instances to be inserted.
135         *
136         * @return the feature instances to be inserted
137         */
138        public FeatureCollection getFeatures() {
139            return this.fc;
140        }
141    
142        /**
143         * Sets the feature instances to be inserted.
144         *
145         * @param fc
146         *            feature instances to be inserted
147         */
148        public void setFeatureCollection( FeatureCollection fc ) {
149            this.fc = fc;
150        }
151    
152        /**
153         * Returns the names of the feature types that are affected by the operation.
154         *
155         * @return the names of the affected feature types
156         */
157        @Override
158        public List<QualifiedName> getAffectedFeatureTypes() {
159            Set<QualifiedName> featureTypeSet = new HashSet<QualifiedName>();
160            for ( int i = 0; i < this.fc.size(); i++ ) {
161                Feature feature = this.fc.getFeature( i );
162                featureTypeSet.add( feature.getName() );
163            }
164            List<QualifiedName> featureTypes = new ArrayList<QualifiedName>( featureTypeSet );
165            return featureTypes;
166        }
167    }