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.response;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
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.service.ServiceObject;
031    import microsoft.exchange.webservices.data.core.service.folder.Folder;
032    import microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException;
033    import org.apache.commons.logging.Log;
034    import org.apache.commons.logging.LogFactory;
035    
036    import java.util.List;
037    
038    /**
039     * Represents the base response class for individual folder move and copy
040     * operations.
041     */
042    public final class MoveCopyFolderResponse extends ServiceResponse implements
043                                                                      IGetObjectInstanceDelegate<ServiceObject> {
044    
045      private static final Log LOG = LogFactory.getLog(MoveCopyFolderResponse.class);
046    
047      /**
048       * The folder.
049       */
050      private Folder folder;
051    
052      /**
053       * Initializes a new instance of the MoveCopyFolderResponse class.
054       */
055      public MoveCopyFolderResponse() {
056        super();
057      }
058    
059      /**
060       * Gets Folder instance.
061       *
062       * @param service        The service.
063       * @param xmlElementName Name of the XML element.
064       * @return folder
065       * @throws Exception the exception
066       */
067      private Folder getObjectInstance(ExchangeService service,
068          String xmlElementName) throws Exception {
069        return EwsUtilities.createEwsObjectFromXmlElementName(Folder.class, service, xmlElementName);
070      }
071    
072      /**
073       * Reads response elements from XML.
074       *
075       * @param reader The reader.
076       * @throws Exception the exception
077       */
078      @Override
079      protected void readElementsFromXml(EwsServiceXmlReader reader)
080          throws Exception {
081        super.readElementsFromXml(reader);
082    
083        List<Folder> folders;
084        try {
085          folders = reader.readServiceObjectsCollectionFromXml(
086    
087              XmlElementNames.Folders, this, false,/* clearPropertyBag */
088              null, /* requestedPropertySet */
089              false); /* summaryPropertiesOnly */
090    
091          this.folder = folders.get(0);
092        } catch (ServiceLocalException e) {
093          LOG.error(e);
094        }
095    
096      }
097    
098      /**
099       * Gets the new (moved or copied) folder.
100       *
101       * @return the folder
102       */
103      public Folder getFolder() {
104        return folder;
105      }
106    
107      /**
108       * Gets the object instance delegate.
109       *
110       * @param service        accepts ExchangeService
111       * @param xmlElementName accepts String
112       * @return Object
113       * @throws Exception throws Exception
114       */
115      @Override
116      public ServiceObject getObjectInstanceDelegate(ExchangeService service,
117          String xmlElementName) throws Exception {
118        return this.getObjectInstance(service, xmlElementName);
119      }
120    
121    }