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 024package microsoft.exchange.webservices.data.core.request; 025 026import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter; 027import microsoft.exchange.webservices.data.core.EwsUtilities; 028import microsoft.exchange.webservices.data.core.ExchangeService; 029import microsoft.exchange.webservices.data.core.XmlAttributeNames; 030import microsoft.exchange.webservices.data.core.XmlElementNames; 031import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling; 032import microsoft.exchange.webservices.data.core.response.ServiceResponse; 033import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion; 034import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace; 035import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException; 036import microsoft.exchange.webservices.data.misc.FolderIdWrapperList; 037 038/** 039 * Represents an EmptyFolder request. 040 */ 041public final class EmptyFolderRequest extends DeleteRequest<ServiceResponse> { 042 043 private FolderIdWrapperList folderIds = new FolderIdWrapperList(); 044 private boolean deleteSubFolders; 045 046 /** 047 * Initializes a new instance of the EmptyFolderRequest class. 048 * 049 * @param service The service. 050 * @param errorHandlingMode Indicates how errors should be handled. 051 * @throws Exception on error 052 */ 053 public EmptyFolderRequest(ExchangeService service, ServiceErrorHandling errorHandlingMode) 054 throws Exception { 055 super(service, errorHandlingMode); 056 } 057 058 /** 059 * Validates request. 060 * 061 * @throws Exception on error 062 */ 063 @Override 064 protected void validate() throws Exception { 065 super.validate(); 066 EwsUtilities.validateParam(this.getFolderIds(), "FolderIds"); 067 this.getFolderIds().validate(this.getService(). 068 getRequestedServerVersion()); 069 } 070 071 /** 072 * Gets the expected response message count. 073 * 074 * @return Number of expected response messages. 075 */ 076 @Override 077 protected int getExpectedResponseMessageCount() { 078 return this.getFolderIds().getCount(); 079 } 080 081 /** 082 * Creates the service response. 083 * 084 * @param service The service. 085 * @param responseIndex Index of the response. 086 * @return Service object 087 */ 088 @Override 089 protected ServiceResponse createServiceResponse(ExchangeService service, 090 int responseIndex) { 091 return new ServiceResponse(); 092 } 093 094 /** 095 * Gets the name of the XML element. 096 * 097 * @return XML element name. 098 */ 099 @Override public String getXmlElementName() { 100 return XmlElementNames.EmptyFolder; 101 } 102 103 /** 104 * Gets the name of the response XML element. 105 * 106 * @return XML element name. 107 */ 108 @Override 109 protected String getResponseXmlElementName() { 110 return XmlElementNames.EmptyFolderResponse; 111 } 112 113 /** 114 * Gets the name of the response message XML element. 115 * 116 * @return XML element name. 117 */ 118 @Override 119 protected String getResponseMessageXmlElementName() { 120 return XmlElementNames.EmptyFolderResponseMessage; 121 } 122 123 /** 124 * Writes XML elements. 125 * 126 * @param writer The writer. 127 * @throws Exception 128 */ 129 @Override 130 protected void writeElementsToXml(EwsServiceXmlWriter writer) 131 throws Exception { 132 this.getFolderIds().writeToXml( 133 writer, 134 XmlNamespace.Messages, 135 XmlElementNames.FolderIds); 136 } 137 138 /** 139 * Writes XML attribute. 140 * 141 * @param writer The writer. 142 * @throws ServiceXmlSerializationException 143 */ 144 @Override 145 protected void writeAttributesToXml(EwsServiceXmlWriter writer) 146 throws ServiceXmlSerializationException { 147 super.writeAttributesToXml(writer); 148 writer.writeAttributeValue(XmlAttributeNames.DeleteSubFolders, 149 this.deleteSubFolders); 150 } 151 152 /** 153 * Gets the request version. 154 * 155 * @return Earliest Exchange version in which this request is supported. 156 */ 157 @Override 158 protected ExchangeVersion getMinimumRequiredServerVersion() { 159 return ExchangeVersion.Exchange2010_SP1; 160 } 161 162 /** 163 * Gets the folder ids. 164 * 165 * @return The folder ids. 166 */ 167 public FolderIdWrapperList getFolderIds() { 168 return this.folderIds; 169 } 170 171 /** 172 * Gets a value indicating whether empty folder should also delete sub folder. 173 * 174 * @value true if empty folder should also delete sub folder, otherwise false. 175 */ 176 protected boolean getDeleteSubFolders() { 177 return deleteSubFolders; 178 } 179 180 /** 181 * Sets a value indicating whether empty folder should also delete sub folder. 182 * 183 * @value true if empty folder should also delete sub folder, otherwise false. 184 */ 185 public void setDeleteSubFolders(boolean value) { 186 this.deleteSubFolders = value; 187 } 188 189}