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.XmlElementNames;
030    import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling;
031    import microsoft.exchange.webservices.data.core.response.ServiceResponse;
032    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
033    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
034    import microsoft.exchange.webservices.data.misc.FolderIdWrapperList;
035    import org.apache.commons.logging.Log;
036    import org.apache.commons.logging.LogFactory;
037    
038    /**
039     * Represents a DeleteFolder request.
040     */
041    public final class DeleteFolderRequest extends DeleteRequest<ServiceResponse> {
042      private static final Log LOG = LogFactory.getLog(DeleteFolderRequest.class);
043      /**
044       * The folder ids.
045       */
046      private FolderIdWrapperList folderIds = new FolderIdWrapperList();
047    
048      /**
049       * Initializes a new instance of the DeleteFolderRequest class.
050       *
051       * @param service           the service
052       * @param errorHandlingMode the error handling mode
053       * @throws Exception
054       */
055      public DeleteFolderRequest(ExchangeService service, ServiceErrorHandling errorHandlingMode)
056          throws Exception {
057        super(service, errorHandlingMode);
058      }
059    
060      /**
061       * Validate request.
062       *
063       * @throws Exception the exception
064       */
065      @Override
066      protected void validate() throws Exception {
067        super.validate();
068        EwsUtilities.validateParam(this.getFolderIds(), "FolderIds");
069        this.getFolderIds().validate(
070            this.getService().getRequestedServerVersion());
071      }
072    
073      /**
074       * Gets the expected response message count.
075       *
076       * @return Number of expected response messages.
077       */
078      @Override
079      protected int getExpectedResponseMessageCount() {
080        return this.getFolderIds().getCount();
081      }
082    
083      /**
084       * Creates the service response.
085       *
086       * @param service       The service.
087       * @param responseIndex Index of the response.
088       * @return Service object.
089       */
090      @Override
091      protected ServiceResponse createServiceResponse(ExchangeService service,
092          int responseIndex) {
093        return new ServiceResponse();
094      }
095    
096      /**
097       * Gets the name of the XML element.
098       *
099       * @return Xml element name
100       */
101      @Override public String getXmlElementName() {
102        return XmlElementNames.DeleteFolder;
103      }
104    
105      /**
106       * Gets the name of the response XML element.
107       *
108       * @return Xml element name
109       */
110      @Override
111      protected String getResponseXmlElementName() {
112        return XmlElementNames.DeleteFolderResponse;
113      }
114    
115      /**
116       * Gets the name of the response message XML element.
117       *
118       * @return Xml element name
119       */
120      @Override
121      protected String getResponseMessageXmlElementName() {
122        return XmlElementNames.DeleteFolderResponseMessage;
123      }
124    
125      /**
126       * Writes XML elements.
127       *
128       * @param writer The writer
129       */
130      @Override
131      protected void writeElementsToXml(EwsServiceXmlWriter writer) {
132        try {
133          this.getFolderIds().writeToXml(writer, XmlNamespace.Messages,
134              XmlElementNames.FolderIds);
135        } catch (Exception e) {
136          LOG.error(e);
137        }
138      }
139    
140      /**
141       * Gets the request version.
142       *
143       * @return Earliest Exchange version in which this request is supported.
144       */
145      @Override
146      protected ExchangeVersion getMinimumRequiredServerVersion() {
147        return ExchangeVersion.Exchange2007_SP1;
148      }
149    
150      /**
151       * Gets the folder ids.
152       *
153       * @return The folder ids.
154       */
155      public FolderIdWrapperList getFolderIds() {
156        return this.folderIds;
157      }
158    
159    }