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.definition; 025 026import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter; 027import microsoft.exchange.webservices.data.core.ExchangeService; 028import microsoft.exchange.webservices.data.core.PropertyBag; 029import microsoft.exchange.webservices.data.core.XmlElementNames; 030import microsoft.exchange.webservices.data.core.service.schema.AppointmentSchema; 031import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion; 032import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags; 033import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException; 034import microsoft.exchange.webservices.data.property.complex.MeetingTimeZone; 035import microsoft.exchange.webservices.data.property.complex.time.TimeZoneDefinition; 036 037import javax.xml.stream.XMLStreamException; 038 039import java.util.EnumSet; 040import java.util.List; 041 042/** 043 * Represents a property definition for property of type TimeZoneInfo. 044 */ 045public class StartTimeZonePropertyDefinition extends TimeZonePropertyDefinition { 046 047 /** 048 * Initializes a new instance of the StartTimeZonePropertyDefinition 049 * class. 050 * 051 * @param xmlElementName the xml element name 052 * @param uri the uri 053 * @param flags the flags 054 * @param version the version 055 */ 056 public StartTimeZonePropertyDefinition(String xmlElementName, String uri, 057 EnumSet<PropertyDefinitionFlags> flags, ExchangeVersion version) { 058 super(xmlElementName, uri, flags, version); 059 } 060 061 /** 062 * Registers associated internal property. 063 * 064 * @param properties the property 065 */ 066 protected void registerAssociatedInternalProperties( 067 List<PropertyDefinition> properties) { 068 super.registerAssociatedInternalProperties(properties); 069 070 properties.add(AppointmentSchema.MeetingTimeZone); 071 } 072 073 /** 074 * Writes to XML. 075 * 076 * @param writer the writer 077 * @param propertyBag the property bag 078 * @param isUpdateOperation the is update operation 079 * @throws Exception the exception 080 */ 081 public void writePropertyValueToXml(EwsServiceXmlWriter writer, PropertyBag propertyBag, 082 boolean isUpdateOperation) 083 throws Exception { 084 Object value = propertyBag.getObjectFromPropertyDefinition(this); 085 086 if (value != null) { 087 final ExchangeService service = (ExchangeService) writer.getService(); 088 if (service.getRequestedServerVersion() == ExchangeVersion.Exchange2007_SP1) { 089 if (!service.getExchange2007CompatibilityMode()) { 090 MeetingTimeZone meetingTimeZone = new MeetingTimeZone((TimeZoneDefinition) value); 091 meetingTimeZone.writeToXml(writer, XmlElementNames.MeetingTimeZone); 092 } 093 } else { 094 super.writePropertyValueToXml(writer, propertyBag, isUpdateOperation); 095 } 096 } 097 } 098 099 /** 100 * Writes to XML. 101 * 102 * @param writer the writer 103 * @throws XMLStreamException the XML stream exception 104 * @throws ServiceXmlSerializationException the service xml serialization exception 105 */ 106 public void writeToXml(EwsServiceXmlWriter writer) 107 throws XMLStreamException, ServiceXmlSerializationException { 108 if (writer.getService().getRequestedServerVersion() == ExchangeVersion.Exchange2007_SP1) { 109 AppointmentSchema.MeetingTimeZone.writeToXml(writer); 110 } else { 111 super.writeToXml(writer); 112 } 113 } 114 115 /** 116 * Determines whether the specified flag is set. 117 * 118 * @param flag The flag. 119 * @param version Requested version. 120 * @return <c>true</c> if the specified 121 * flag is set; otherwise, <c>false</c>. 122 */ 123 @Override public boolean hasFlag(PropertyDefinitionFlags flag, ExchangeVersion version) { 124 if (version != null && (version == ExchangeVersion.Exchange2007_SP1)) { 125 return AppointmentSchema.MeetingTimeZone.hasFlag(flag, version); 126 } else { 127 return super.hasFlag(flag, version); 128 } 129 } 130 131}