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.notification;
025
026import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
027import microsoft.exchange.webservices.data.core.XmlElementNames;
028import microsoft.exchange.webservices.data.core.enumeration.notification.EventType;
029import microsoft.exchange.webservices.data.property.complex.FolderId;
030import microsoft.exchange.webservices.data.property.complex.ItemId;
031
032import java.util.Date;
033
034/**
035 * Represents an event that applies to an item.
036 */
037public final class ItemEvent extends NotificationEvent {
038
039  /**
040   * Id of the item this event applies to.
041   */
042  private ItemId itemId;
043
044  /**
045   * Id of the item that moved or copied. This is only meaningful when
046   * EventType is equal to either EventType.Moved or EventType.Copied. For all
047   * other event types, it's null.
048   */
049  private ItemId oldItemId;
050
051  /**
052   * Initializes a new instance.
053   *
054   * @param eventType the event type
055   * @param timestamp the timestamp
056   */
057  protected ItemEvent(EventType eventType, Date timestamp) {
058    super(eventType, timestamp);
059  }
060
061  /**
062   * Load from XML.
063   *
064   * @param reader the reader
065   * @throws Exception the exception
066   */
067  protected void internalLoadFromXml(EwsServiceXmlReader reader)
068      throws Exception {
069    super.internalLoadFromXml(reader);
070
071    this.itemId = new ItemId();
072    this.itemId.loadFromXml(reader, reader.getLocalName());
073
074    reader.read();
075
076    setParentFolderId(new FolderId());
077
078    getParentFolderId().loadFromXml(reader, XmlElementNames.ParentFolderId);
079
080    EventType eventType = getEventType();
081    switch (eventType) {
082      case Moved:
083      case Copied:
084        reader.read();
085
086        this.oldItemId = new ItemId();
087        this.oldItemId.loadFromXml(reader, reader.getLocalName());
088
089        reader.read();
090
091        setOldParentFolderId(new FolderId());
092        getOldParentFolderId().loadFromXml(reader, reader.getLocalName());
093        break;
094
095      default:
096        break;
097    }
098  }
099
100  /**
101   * Gets the Id of the item this event applies to.
102   *
103   * @return itemId
104   */
105  public ItemId getItemId() {
106    return itemId;
107  }
108
109  /**
110   * Gets the Id of the item that was moved or copied. OldItemId is only
111   * meaningful when EventType is equal to either EventType.Moved or
112   * EventType.Copied. For all other event types, OldItemId is null.
113   *
114   * @return the old item id
115   */
116  public ItemId getOldItemId() {
117    return oldItemId;
118  }
119
120}