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.core.enumeration.misc.XmlNamespace; 030import microsoft.exchange.webservices.data.property.complex.FolderId; 031 032import java.util.Date; 033 034/** 035 * Represents an event that applies to a folder. 036 */ 037public class FolderEvent extends NotificationEvent { 038 039 /** 040 * The folder id. 041 */ 042 private FolderId folderId; 043 044 /** 045 * The old folder id. 046 */ 047 private FolderId oldFolderId; 048 049 /** 050 * The new number of unread messages. This is is only meaningful when 051 * EventType is equal to EventType.Modified. For all other event types, it's 052 * null. 053 */ 054 private int unreadCount; 055 056 /** 057 * Initializes a new instance. 058 * 059 * @param eventType the event type 060 * @param timestamp the timestamp 061 */ 062 protected FolderEvent(EventType eventType, Date timestamp) { 063 super(eventType, timestamp); 064 } 065 066 /** 067 * Initializes a new instance. 068 * 069 * @param eventType the event type 070 * @param folderId of the folder that this event refers to 071 * @param parentFolderId of the folder this event refers to 072 */ 073 public FolderEvent(EventType eventType, FolderId folderId, FolderId parentFolderId) { 074 super(eventType, null); 075 this.folderId = folderId; 076 setParentFolderId(parentFolderId); 077 } 078 079 /** 080 * Load from XML. 081 * 082 * @param reader the reader 083 * @throws Exception the exception 084 */ 085 protected void internalLoadFromXml(EwsServiceXmlReader reader) 086 throws Exception { 087 super.internalLoadFromXml(reader); 088 089 this.folderId = new FolderId(); 090 this.folderId.loadFromXml(reader, reader.getLocalName()); 091 092 reader.read(); 093 094 setParentFolderId(new FolderId()); 095 getParentFolderId().loadFromXml(reader, XmlElementNames.ParentFolderId); 096 097 switch (getEventType()) { 098 case Moved: 099 case Copied: 100 reader.read(); 101 102 this.oldFolderId = new FolderId(); 103 this.oldFolderId.loadFromXml(reader, reader.getLocalName()); 104 105 reader.read(); 106 107 setOldParentFolderId(new FolderId()); 108 getOldParentFolderId().loadFromXml(reader, reader.getLocalName()); 109 break; 110 111 case Modified: 112 reader.read(); 113 if (reader.isStartElement()) { 114 reader.ensureCurrentNodeIsStartElement(XmlNamespace.Types, 115 XmlElementNames.UnreadCount); 116 String str = reader.readValue(); 117 this.unreadCount = Integer.parseInt(str); 118 } 119 break; 120 121 default: 122 break; 123 } 124 } 125 126 /** 127 * Gets the Id of the folder this event applies to. 128 * 129 * @return folderId 130 */ 131 public FolderId getFolderId() { 132 return folderId; 133 } 134 135 /** 136 * gets the Id of the folder that was moved or copied. OldFolderId is only 137 * meaningful when EventType is equal to either EventType.Moved or 138 * EventType.Copied. For all other event types, OldFolderId is null. 139 * 140 * @return oldFolderId 141 */ 142 public FolderId getOldFolderId() { 143 return oldFolderId; 144 } 145 146 /** 147 * Gets the new number of unread messages. This is is only meaningful when 148 * EventType is equal to EventType.Modified. For all other event types, 149 * UnreadCount is null. 150 * 151 * @return unreadCount 152 */ 153 public int getUnreadCount() { 154 return unreadCount; 155 } 156 157}