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.enumeration.notification.EventType;
028import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
029import microsoft.exchange.webservices.data.property.complex.FolderId;
030
031import java.util.Date;
032
033/**
034 * Represents an event as exposed by push and pull notification.
035 */
036public abstract class NotificationEvent {
037
038  /**
039   * Type of this event.
040   */
041  private EventType eventType;
042
043  /**
044   * Date and time when the event occurred.
045   */
046  private Date timestamp;
047
048  /**
049   * Id of parent folder of the item or folder this event applies to.
050   */
051  private FolderId parentFolderId;
052
053  /**
054   * Id of the old parent folder of the item or folder this event applies to.
055   * This property is only meaningful when EventType is equal to either
056   * EventType.Moved or EventType.Copied. For all other event types,
057   * oldParentFolderId will be null
058   */
059  private FolderId oldParentFolderId;
060
061  /**
062   * Initializes a new instance.
063   *
064   * @param eventType the event type
065   * @param timestamp the timestamp
066   */
067  protected NotificationEvent(EventType eventType, Date timestamp) {
068    this.eventType = eventType;
069    this.timestamp = timestamp;
070  }
071
072  /**
073   * Load from XML.
074   *
075   * @param reader the reader
076   * @throws Exception the exception
077   */
078  protected void internalLoadFromXml(EwsServiceXmlReader reader) throws Exception {
079  }
080
081  /**
082   * Loads this NotificationEvent from XML.
083   *
084   * @param reader         the reader
085   * @param xmlElementName the xml element name
086   * @throws Exception the exception
087   */
088  protected void loadFromXml(EwsServiceXmlReader reader,
089      String xmlElementName)
090      throws Exception {
091    this.internalLoadFromXml(reader);
092
093    reader.readEndElementIfNecessary(XmlNamespace.Types, xmlElementName);
094  }
095
096  /**
097   * gets the eventType.
098   *
099   * @return the eventType.
100   */
101  public EventType getEventType() {
102    return eventType;
103  }
104
105  /**
106   * gets the timestamp.
107   *
108   * @return the timestamp.
109   */
110  public Date getTimestamp() {
111    return timestamp;
112  }
113
114  /**
115   * gets the parentFolderId.
116   *
117   * @return the parentFolderId.
118   */
119  public FolderId getParentFolderId() {
120    return parentFolderId;
121  }
122
123  /**
124   * Sets the parentFolderId.
125   *
126   * @param parentFolderId the new parent folder id
127   */
128  protected void setParentFolderId(FolderId parentFolderId) {
129    this.parentFolderId = parentFolderId;
130  }
131
132  /**
133   * gets the oldParentFolderId.
134   *
135   * @return the oldParentFolderId.
136   */
137  public FolderId getOldParentFolderId() {
138    return oldParentFolderId;
139  }
140
141  /**
142   * Sets the oldParentFolderId.
143   *
144   * @param oldParentFolderId the new old parent folder id
145   */
146  protected void setOldParentFolderId(FolderId oldParentFolderId) {
147
148    this.oldParentFolderId = oldParentFolderId;
149  }
150
151}