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.EwsUtilities; 027import microsoft.exchange.webservices.data.core.ExchangeService; 028import microsoft.exchange.webservices.data.core.XmlElementNames; 029import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling; 030import microsoft.exchange.webservices.data.core.response.CreateFolderResponse; 031import microsoft.exchange.webservices.data.core.response.ServiceResponse; 032import microsoft.exchange.webservices.data.core.service.folder.Folder; 033import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion; 034 035import java.util.Collection; 036 037/** 038 * Represents a CreateFolder request. 039 */ 040public final class CreateFolderRequest extends CreateRequest<Folder, ServiceResponse> { 041 042 /** 043 * Initializes a new instance of the CreateFolderRequest class. 044 * 045 * @param service The service 046 * @param errorHandlingMode Indicates how errors should be handled. 047 * @throws Exception 048 */ 049 public CreateFolderRequest(ExchangeService service, ServiceErrorHandling errorHandlingMode) 050 throws Exception { 051 super(service, errorHandlingMode); 052 } 053 054 /** 055 * Validate request. 056 * 057 * @throws Exception the exception 058 */ 059 @Override 060 protected void validate() throws Exception { 061 super.validate(); 062 EwsUtilities.validateParam(this.getFolders(), "Folders"); 063 064 // Validate each folder. 065 for (Folder folder : this.getFolders()) { 066 folder.validate(); 067 } 068 } 069 070 /** 071 * Creates the service response. 072 * 073 * @param service the service 074 * @param responseIndex Index of the response. 075 * @return Service response. 076 */ 077 @Override 078 protected ServiceResponse createServiceResponse(ExchangeService service, 079 int responseIndex) { 080 return new CreateFolderResponse((Folder) EwsUtilities 081 .getEnumeratedObjectAt(this.getFolders(), responseIndex)); 082 } 083 084 /** 085 * Gets the name of the XML element. 086 * 087 * @return Xml element name 088 */ 089 @Override public String getXmlElementName() { 090 return XmlElementNames.CreateFolder; 091 } 092 093 /** 094 * Gets the name of the response XML element. 095 * 096 * @return Xml element name 097 */ 098 @Override 099 protected String getResponseXmlElementName() { 100 return XmlElementNames.CreateFolderResponse; 101 } 102 103 /** 104 * Gets the name of the response message XML element. 105 * 106 * @return Xml element name 107 */ 108 @Override 109 protected String getResponseMessageXmlElementName() { 110 return XmlElementNames.CreateFolderResponseMessage; 111 } 112 113 /** 114 * Gets the name of the parent folder XML element. 115 * 116 * @return Xml element name 117 */ 118 @Override 119 protected String getParentFolderXmlElementName() { 120 return XmlElementNames.ParentFolderId; 121 } 122 123 /** 124 * Gets the name of the object collection XML element. 125 * 126 * @return Xml element name 127 */ 128 @Override 129 protected String getObjectCollectionXmlElementName() { 130 return XmlElementNames.Folders; 131 } 132 133 /** 134 * Gets the request version. Earliest Exchange version in which this request 135 * is supported. 136 * 137 * @return the minimum required server version 138 */ 139 @Override 140 protected ExchangeVersion getMinimumRequiredServerVersion() { 141 return ExchangeVersion.Exchange2007_SP1; 142 } 143 144 /** 145 * Gets the folder. 146 * 147 * @return the folder 148 */ 149 public Iterable<Folder> getFolders() { 150 return this.getObjects(); 151 } 152 153 /** 154 * Sets the folder. 155 * 156 * @param folder the new folder 157 */ 158 public void setFolders(Iterable<Folder> folder) { 159 this.setObjects((Collection<Folder>) folder); 160 } 161 162}