001    /*
002     * The MIT License
003     * Copyright (c) 2012 Microsoft Corporation
004     *
005     * Permission is hereby granted, free of charge, to any person obtaining a copy
006     * of this software and associated documentation files (the "Software"), to deal
007     * in the Software without restriction, including without limitation the rights
008     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009     * copies of the Software, and to permit persons to whom the Software is
010     * furnished to do so, subject to the following conditions:
011     *
012     * The above copyright notice and this permission notice shall be included in
013     * all copies or substantial portions of the Software.
014     *
015     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021     * THE SOFTWARE.
022     */
023    
024    package microsoft.exchange.webservices.data.core.request;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
027    import microsoft.exchange.webservices.data.core.EwsUtilities;
028    import microsoft.exchange.webservices.data.core.ExchangeService;
029    import microsoft.exchange.webservices.data.core.XmlAttributeNames;
030    import microsoft.exchange.webservices.data.core.XmlElementNames;
031    import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling;
032    import microsoft.exchange.webservices.data.core.response.ServiceResponse;
033    import microsoft.exchange.webservices.data.core.enumeration.service.calendar.AffectedTaskOccurrence;
034    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
035    import microsoft.exchange.webservices.data.core.enumeration.service.SendCancellationsMode;
036    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
037    import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
038    import microsoft.exchange.webservices.data.misc.ItemIdWrapperList;
039    
040    /**
041     * Represents a DeleteItem request.
042     */
043    public final class DeleteItemRequest extends DeleteRequest<ServiceResponse> {
044    
045      /**
046       * The item ids.
047       */
048      private ItemIdWrapperList itemIds = new ItemIdWrapperList();
049    
050      /**
051       * The affected task occurrences.
052       */
053      private AffectedTaskOccurrence affectedTaskOccurrences;
054    
055      /**
056       * The send cancellations mode.
057       */
058      private SendCancellationsMode sendCancellationsMode;
059    
060      /**
061       * Initializes a new instance of the class.
062       *
063       * @param service           the service
064       * @param errorHandlingMode the error handling mode
065       * @throws Exception
066       */
067      public DeleteItemRequest(ExchangeService service, ServiceErrorHandling errorHandlingMode)
068          throws Exception {
069        super(service, errorHandlingMode);
070      }
071    
072      /**
073       * Validate request.
074       *
075       * @throws Exception the exception
076       */
077      @Override
078      protected void validate() throws Exception {
079        super.validate();
080        EwsUtilities.validateParam(this.itemIds, "ItemIds");
081      }
082    
083      /**
084       * Gets the expected response message count.
085       *
086       * @return Number of expected response messages
087       */
088      @Override
089      protected int getExpectedResponseMessageCount() {
090        return this.itemIds.getCount();
091      }
092    
093      /**
094       * Creates the service response.
095       *
096       * @param service       the service
097       * @param responseIndex the response index
098       * @return Service response.
099       */
100      @Override
101      protected ServiceResponse createServiceResponse(ExchangeService service,
102          int responseIndex) {
103        return new ServiceResponse();
104      }
105    
106      /**
107       * Gets the name of the XML element.
108       *
109       * @return XML element name
110       */
111      @Override public String getXmlElementName() {
112        return XmlElementNames.DeleteItem;
113      }
114    
115      /**
116       * Gets the name of the response XML element.
117       *
118       * @return XML element name
119       */
120      @Override
121      protected String getResponseXmlElementName() {
122        return XmlElementNames.DeleteItemResponse;
123      }
124    
125      /**
126       * Gets the name of the response message XML element.
127       *
128       * @return XML element name
129       */
130      @Override
131      protected String getResponseMessageXmlElementName() {
132        return XmlElementNames.DeleteItemResponseMessage;
133      }
134    
135      /**
136       * Writes XML attribute.
137       *
138       * @param writer the writer
139       * @throws ServiceXmlSerializationException the service xml serialization exception
140       */
141      @Override
142      protected void writeAttributesToXml(EwsServiceXmlWriter writer)
143          throws ServiceXmlSerializationException {
144        super.writeAttributesToXml(writer);
145    
146        if (this.affectedTaskOccurrences != null) {
147          writer.writeAttributeValue(
148              XmlAttributeNames.AffectedTaskOccurrences, this
149                  .getAffectedTaskOccurrences());
150        }
151    
152        if (this.sendCancellationsMode != null) {
153          writer.writeAttributeValue(
154              XmlAttributeNames.SendMeetingCancellations, this
155                  .getSendCancellationsMode());
156        }
157      }
158    
159      /**
160       * Writes XML elements.
161       *
162       * @param writer the writer
163       * @throws Exception the exception
164       */
165      @Override
166      protected void writeElementsToXml(EwsServiceXmlWriter writer)
167          throws Exception {
168        this.itemIds.writeToXml(writer, XmlNamespace.Messages,
169            XmlElementNames.ItemIds);
170      }
171    
172      /**
173       * Gets the request version.
174       *
175       * @return Earliest Exchange version in which this request is supported.
176       */
177      @Override
178      protected ExchangeVersion getMinimumRequiredServerVersion() {
179        return ExchangeVersion.Exchange2007_SP1;
180      }
181    
182      /**
183       * Gets the item ids.
184       *
185       * @return the item ids
186       */
187      public ItemIdWrapperList getItemIds() {
188        return this.itemIds;
189      }
190    
191      /**
192       * Gets the affected task occurrences.
193       *
194       * @return the affected task occurrences
195       */
196      AffectedTaskOccurrence getAffectedTaskOccurrences() {
197        return this.affectedTaskOccurrences;
198      }
199    
200      /**
201       * Sets the affected task occurrences.
202       *
203       * @param affectedTaskOccurrences the new affected task occurrences
204       */
205      public void setAffectedTaskOccurrences(AffectedTaskOccurrence affectedTaskOccurrences) {
206        this.affectedTaskOccurrences = affectedTaskOccurrences;
207      }
208    
209      /**
210       * Gets the send cancellations.
211       *
212       * @return the send cancellations mode
213       */
214      SendCancellationsMode getSendCancellationsMode() {
215        return this.sendCancellationsMode;
216      }
217    
218      /**
219       * Sets the send cancellations mode.
220       *
221       * @param sendCancellationsMode the new send cancellations mode
222       */
223      public void setSendCancellationsMode(SendCancellationsMode sendCancellationsMode) {
224        this.sendCancellationsMode = sendCancellationsMode;
225      }
226    
227    }