001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wfs/operation/transaction/Update.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.List;
040    import java.util.Map;
041    
042    import org.deegree.datatypes.QualifiedName;
043    import org.deegree.model.feature.Feature;
044    import org.deegree.model.feature.FeatureProperty;
045    import org.deegree.model.filterencoding.Filter;
046    import org.deegree.ogcbase.PropertyPath;
047    import org.w3c.dom.Node;
048    
049    /**
050     * Represents an <code>Update</code> operation as a part of a {@link Transaction} request.
051     * <p>
052     * WFS Specification OBC 04-094 (#12.2.5 Pg.68)
053     * <p>
054     * The <code>Update</code> element describes one update operation that is to be applied to a <code>Feature</code> or a
055     * set of <code>Feature</code>s of a single <code>FeatureType</code>.
056     * <p>
057     * Multiple <code>Update</code> operations can be contained in a single <code>Transaction</code> request. An
058     * <code>Update</code> element contains one or more <b>Property</b> elements that specify the name and replacement value
059     * for a property that belongs to the <code>FeatureType</code> specified using the <b>mandatory typeName</b> attribute.
060     * <p>
061     * Additionally, a deegree specific addition to this specification is supported:<br>
062     * Instead of a number of properties, it is also possible to specify a root feature that will replace the feature that
063     * is matched by the filter. In this case, the filter must match exactly one (or zero) feature instances.
064     * 
065     * @author <a href="mailto:deshmukh@lat-lon.de">Anup Deshmukh </a>
066     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
067     * @author last edited by: $Author: aionita $
068     * 
069     * @version $Revision: 23794 $, $Date: 2010-04-23 15:05:33 +0200 (Fr, 23 Apr 2010) $
070     */
071    public class Update extends TransactionOperation {
072    
073        private QualifiedName typeName;
074    
075        private Feature replacementFeature;
076    
077        private Map<PropertyPath, FeatureProperty> replacementProps;
078    
079        private Filter filter;
080    
081        private Map<PropertyPath, Node> rawProps;
082    
083        /**
084         * Creates a new <code>Update</code> instance.
085         * 
086         * @param handle
087         *            optional identifier for the operation (for error messsages)
088         * @param typeName
089         *            the name of the targeted feature type
090         * @param replacementProps
091         *            property paths and their replacement values
092         * @param filter
093         *            selects the feature instances to be updated
094         */
095        public Update( String handle, QualifiedName typeName, Map<PropertyPath, FeatureProperty> replacementProps,
096                       Filter filter ) {
097            super( handle );
098            this.typeName = typeName;
099            this.replacementProps = replacementProps;
100            this.filter = filter;
101        }
102    
103        /**
104         * Creates a new <code>Update</code> instance.
105         * <p>
106         * NOTE: This constructor will be removed in the future, because it makes the DOM representation available and
107         * breaks the layering (DOM should not be used on this level).
108         * 
109         * @param handle
110         *            optional identifier for the operation (for error messsages)
111         * @param typeName
112         *            the name of the targeted feature type
113         * @param replacementProps
114         *            property paths and their replacement values
115         * @param rawProps
116         *            property paths and their DOM nodes
117         * @param filter
118         *            selects the feature instances to be updated
119         * @deprecated This method breaks the layering -- it makes the DOM representation available.
120         */
121        @Deprecated
122        Update( String handle, QualifiedName typeName, Map<PropertyPath, FeatureProperty> replacementProps,
123                Map<PropertyPath, Node> rawProps, Filter filter ) {
124            super( handle );
125            this.typeName = typeName;
126            this.replacementProps = replacementProps;
127            this.rawProps = rawProps;
128            this.filter = filter;
129        }
130    
131        /**
132         * Creates a new <code>Update</code> instance.
133         * 
134         * @param handle
135         *            optional identifier for the operation (for error messsages)
136         * @param typeName
137         *            the name of the targeted feature type
138         * @param replacementFeature
139         *            property names and their replacement values
140         * @param filter
141         *            selects the (single) feature instance to be replaced
142         */
143        public Update( String handle, QualifiedName typeName, Feature replacementFeature, Filter filter ) {
144            super( handle );
145            this.typeName = typeName;
146            this.replacementFeature = replacementFeature;
147            this.filter = filter;
148        }
149    
150        /**
151         * Returns the name of the targeted feature type.
152         * 
153         * @return the name of the targeted feature type.
154         */
155        public QualifiedName getTypeName() {
156            return this.typeName;
157        }
158    
159        /**
160         * TypeName setter method
161         * 
162         * @param typeName
163         *            a {@QualifiedName}
164         */
165        public void setTypeName( QualifiedName typeName ) {
166            this.typeName = typeName;
167        }
168    
169        /**
170         * Returns the filter that selects the feature instances to be updated.
171         * 
172         * @return the filter that selects the feature instances to be updated
173         */
174        public Filter getFilter() {
175            return this.filter;
176        }
177    
178        /**
179         * Sets the filter that determines the features that are affected by the operation.
180         * 
181         * @param filter
182         *            determines the features that are affected by the operation
183         */
184        public void setFilter( Filter filter ) {
185            this.filter = filter;
186        }
187    
188        /**
189         * Returns the feature that will replace the matched feature instance. If the returned value is null, this is a
190         * "standard" update operation that updates a number of flat properties instead.
191         * 
192         * @return the feature that will replace the (single) matched feature instance
193         */
194        public Feature getFeature() {
195            return this.replacementFeature;
196        }
197    
198        /**
199         * Return the properties and their replacement values that are targeted by this update operation.
200         * 
201         * @return the properties and their replacement values
202         */
203        public Map<PropertyPath, FeatureProperty> getReplacementProperties() {
204            return this.replacementProps;
205        }
206    
207        /**
208         * Setter method for replacement properties
209         * 
210         * @param replacementProps
211         *            a map between {@link PropertyPath}s and {@link FeatureProperty}s
212         */
213        public void setReplacementProperties( Map<PropertyPath, FeatureProperty> replacementProps ) {
214            this.replacementProps = replacementProps;
215        }
216    
217        /**
218         * Return the properties and their replacement values (as DOM representation).
219         * 
220         * NOTE: This constructor will be removed in the future, because it makes the DOM representation available and
221         * breaks the layering (DOM should not be used on this level).
222         * 
223         * @return the properties and their replacement values (as Nodes)
224         * @deprecated This method breaks the layering -- it makes the DOM representation available.
225         */
226        @Deprecated
227        public Map<PropertyPath, Node> getRawProperties() {
228            return this.rawProps;
229        }
230    
231        @Override
232        public List<QualifiedName> getAffectedFeatureTypes() {
233            List<QualifiedName> featureTypes = new ArrayList<QualifiedName>( 1 );
234            featureTypes.add( this.typeName );
235            return featureTypes;
236        }
237    }