001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/wfs/operation/transaction/Delete.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.util.ArrayList;
039    import java.util.Iterator;
040    import java.util.List;
041    import java.util.Map;
042    
043    import org.deegree.datatypes.QualifiedName;
044    import org.deegree.model.feature.Feature;
045    import org.deegree.model.filterencoding.Filter;
046    
047    /**
048     * Represents a <code>Delete</code> operation as a part of a {@link Transaction} request.
049     * <p>
050     * WFS Specification OGC 04-094 (#12.2.6 Pg.71):
051     * <p>
052     * The <code>Delete</code> element is used to indicate that one of more feature instances should
053     * be deleted. The scope of the delete operation is constrained by using the <code>Filter</code>
054     * element as described in the <b>Filter Encoding Specification[3]</b>.<br>
055     * In the event, that the {@link Filter} element does not identify any {@link Feature}
056     * instances to <code>Delete</code>, the <code>Delete</code> action will simply have no effect.
057     * <br>
058     * <b>This is not an exception condition</b>.
059     *
060     * @author <a href="mailto:deshmukh@lat-lon.de">Anup Deshmukh </a>
061     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
062     * @author last edited by: $Author: mschneider $
063     *
064     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
065     */
066    public class Delete extends TransactionOperation {
067    
068        private QualifiedName typeName;
069    
070        private Filter filter;
071    
072        /**
073         * Creates a new <code>Delete<code> instance.
074         *
075         * @param handle
076         *            optional identifier for the operation (for error messsages)
077         * @param typeName
078         *            name of the targeted feature type
079         * @param filter
080         *            selects the feature instances to be deleted
081         */
082        public Delete( String handle, QualifiedName typeName, Filter filter ) {
083            super (handle);
084            this.typeName = typeName;
085            this.filter = filter;
086        }
087    
088        /**
089         * Returns the name of the targeted feature type.
090         *
091         * @return the name of the targeted feature type.
092         */
093        public QualifiedName getTypeName() {
094            return this.typeName;
095        }
096    
097        /**
098         * Return <code>Filter</code>.
099         *
100         * @return Filter filter
101         */
102        public Filter getFilter() {
103            return this.filter;
104        }
105    
106        /**
107         * sets the filter condition for an delete operation. This method may be use
108         * by classes/moduls that need to manipulate an update operation e.g. to
109         * ensure security constraints.
110         * @param filter
111         */
112        public void setFilter(Filter filter) {
113            this.filter = filter;
114        }
115    
116        /**
117         * Returns the names of the feature types that are affected by the operation.
118         * <p>
119         * For the <code>Delete</code> operation, this is a list with a single entry - the
120         * value of the "typeName" attribute.
121         *
122         * @return the names of the affected feature types.
123         */
124        @Override
125        public List<QualifiedName> getAffectedFeatureTypes () {
126            List<QualifiedName> featureTypes = new ArrayList<QualifiedName> (1);
127            featureTypes.add(this.typeName);
128            return featureTypes;
129        }
130    
131        /**
132         * Creates <code>Delete</code> instances from a KVP request.
133         *
134         * @param typeFilter
135         * @return Delete instances
136         */
137        protected static List<Delete> create( Map<QualifiedName, Filter> typeFilter ) {
138    
139            List<Delete> deletes = new ArrayList<Delete>();
140            if ( typeFilter != null ) {
141                Iterator<QualifiedName> iter = typeFilter.keySet().iterator();
142                while (iter.hasNext()) {
143                    QualifiedName typeName = iter.next();
144                    Filter filter = typeFilter.get( typeName );
145                    deletes.add(new Delete( null, typeName, filter ));
146                }
147            }
148            return deletes;
149        }
150    }