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.property.complex; 025 026import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter; 027import microsoft.exchange.webservices.data.core.XmlAttributeNames; 028import microsoft.exchange.webservices.data.core.XmlElementNames; 029import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException; 030 031/** 032 * Represents the Id of an occurrence of a recurring appointment. 033 */ 034public final class AppointmentOccurrenceId extends ItemId { 035 036 /** 037 * Index of the occurrence. 038 */ 039 private int occurrenceIndex; 040 041 /** 042 * Initializes a new instance. 043 * 044 * @param recurringMasterUniqueId the recurring master unique id 045 * @param occurrenceIndex the occurrence index 046 * @throws Exception the exception 047 */ 048 public AppointmentOccurrenceId(String recurringMasterUniqueId, 049 int occurrenceIndex) throws Exception { 050 super(recurringMasterUniqueId); 051 this.occurrenceIndex = occurrenceIndex; 052 } 053 054 /** 055 * Gets the index of the occurrence. Note that the occurrence index 056 * starts at one not zero. 057 * 058 * @return the occurrence index 059 */ 060 public int getOccurrenceIndex() { 061 return occurrenceIndex; 062 } 063 064 /** 065 * Sets the occurrence index. 066 * 067 * @param occurrenceIndex the new occurrence index 068 */ 069 public void setOccurrenceIndex(int occurrenceIndex) { 070 if (occurrenceIndex < 1) { 071 throw new IllegalArgumentException("OccurrenceIndex must be greater than 0."); 072 } 073 this.occurrenceIndex = occurrenceIndex; 074 } 075 076 /** 077 * Gets the name of the XML element. 078 * 079 * @return XML element name 080 */ 081 @Override 082 public String getXmlElementName() { 083 return XmlElementNames.OccurrenceItemId; 084 } 085 086 /** 087 * Gets the name of the XML element. 088 * 089 * @param writer the writer 090 * @throws ServiceXmlSerializationException the service xml serialization exception 091 */ 092 public void writeAttributesToXml(EwsServiceXmlWriter writer) 093 throws ServiceXmlSerializationException { 094 writer.writeAttributeValue(XmlAttributeNames.RecurringMasterId, this 095 .getUniqueId()); 096 writer.writeAttributeValue(XmlAttributeNames.InstanceIndex, this 097 .getOccurrenceIndex()); 098 } 099 100}