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.response; 025 026import microsoft.exchange.webservices.data.core.EwsServiceXmlReader; 027import microsoft.exchange.webservices.data.core.EwsUtilities; 028import microsoft.exchange.webservices.data.core.ExchangeService; 029import microsoft.exchange.webservices.data.core.XmlElementNames; 030import microsoft.exchange.webservices.data.core.service.ServiceObject; 031import microsoft.exchange.webservices.data.core.service.folder.Folder; 032import microsoft.exchange.webservices.data.core.enumeration.service.ServiceResult; 033 034import java.util.List; 035 036/** 037 * Represents the response to an individual folder creation operation. 038 */ 039public final class CreateFolderResponse extends ServiceResponse implements 040 IGetObjectInstanceDelegate<ServiceObject> { 041 042 /** 043 * The folder. 044 */ 045 private Folder folder; 046 047 /** 048 * Initializes a new instance of the CreateFolderResponse class. 049 * 050 * @param folder The folder. 051 */ 052 public CreateFolderResponse(Folder folder) { 053 super(); 054 this.folder = folder; 055 } 056 057 /** 058 * Gets the object instance. 059 * 060 * @param service The service. 061 * @param xmlElementName Name of the XML element. 062 * @return Folder 063 * @throws Exception the exception 064 */ 065 private Folder getObjectInstance(ExchangeService service, 066 String xmlElementName) throws Exception { 067 if (this.folder != null) { 068 return this.folder; 069 } else { 070 return EwsUtilities.createEwsObjectFromXmlElementName(Folder.class, service, xmlElementName); 071 } 072 } 073 074 /** 075 * Reads response elements from XML. 076 * 077 * @param reader The reader 078 * @throws Exception the exception 079 */ 080 @Override 081 protected void readElementsFromXml(EwsServiceXmlReader reader) 082 throws Exception { 083 super.readElementsFromXml(reader); 084 085 List<Folder> folders = reader.readServiceObjectsCollectionFromXml( 086 XmlElementNames.Folders, this, false, /* clearPropertyBag */ 087 null, /* requestedPropertySet */ 088 false); /* summaryPropertiesOnly */ 089 090 this.folder = folders.get(0); 091 } 092 093 /** 094 * Gets the object instance delegate. 095 * 096 * @param service the service 097 * @param xmlElementName the xml element name 098 * @return the object instance delegate 099 * @throws Exception the exception 100 */ 101 @Override 102 public ServiceObject getObjectInstanceDelegate(ExchangeService service, 103 String xmlElementName) throws Exception { 104 return this.getObjectInstance(service, xmlElementName); 105 } 106 107 /** 108 * Clears the change log of the created folder if the creation succeeded. 109 */ 110 @Override 111 protected void loaded() { 112 if (this.getResult() == ServiceResult.Success) { 113 this.folder.clearChangeLog(); 114 } 115 } 116 117}