All Downloads are FREE. Search and download functionalities are using the official Maven repository.

microsoft.exchange.webservices.data.notification.ItemEvent Maven / Gradle / Ivy

There is a newer version: 2.15
Show newest version
/*
 * The MIT License
 * Copyright (c) 2012 Microsoft Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package microsoft.exchange.webservices.data.notification;

import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
import microsoft.exchange.webservices.data.core.XmlElementNames;
import microsoft.exchange.webservices.data.core.enumeration.notification.EventType;
import microsoft.exchange.webservices.data.property.complex.FolderId;
import microsoft.exchange.webservices.data.property.complex.ItemId;

import java.util.Date;

/**
 * Represents an event that applies to an item.
 */
public final class ItemEvent extends NotificationEvent {

  /**
   * Id of the item this event applies to.
   */
  private ItemId itemId;

  /**
   * Id of the item that moved or copied. This is only meaningful when
   * EventType is equal to either EventType.Moved or EventType.Copied. For all
   * other event types, it's null.
   */
  private ItemId oldItemId;

  /**
   * Initializes a new instance.
   *
   * @param eventType the event type
   * @param timestamp the timestamp
   */
  protected ItemEvent(EventType eventType, Date timestamp) {
    super(eventType, timestamp);
  }

  /**
   * Initializes a new instance.
   *
   * @param eventType the event type
   * @param itemId of the item that this event refers to
   * @param parentFolderId of the item this event refers to
   */
  public ItemEvent(EventType eventType, ItemId itemId, FolderId parentFolderId) {
    super(eventType, null);
    this.itemId = itemId;
    setParentFolderId(parentFolderId);
  }

  /**
   * Load from XML.
   *
   * @param reader the reader
   * @throws Exception the exception
   */
  protected void internalLoadFromXml(EwsServiceXmlReader reader)
      throws Exception {
    super.internalLoadFromXml(reader);

    this.itemId = new ItemId();
    this.itemId.loadFromXml(reader, reader.getLocalName());

    reader.read();

    setParentFolderId(new FolderId());

    getParentFolderId().loadFromXml(reader, XmlElementNames.ParentFolderId);

    EventType eventType = getEventType();
    switch (eventType) {
      case Moved:
      case Copied:
        reader.read();

        this.oldItemId = new ItemId();
        this.oldItemId.loadFromXml(reader, reader.getLocalName());

        reader.read();

        setOldParentFolderId(new FolderId());
        getOldParentFolderId().loadFromXml(reader, reader.getLocalName());
        break;

      default:
        break;
    }
  }

  /**
   * Gets the Id of the item this event applies to.
   *
   * @return itemId
   */
  public ItemId getItemId() {
    return itemId;
  }

  /**
   * Gets the Id of the item that was moved or copied. OldItemId is only
   * meaningful when EventType is equal to either EventType.Moved or
   * EventType.Copied. For all other event types, OldItemId is null.
   *
   * @return the old item id
   */
  public ItemId getOldItemId() {
    return oldItemId;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy