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.EwsServiceXmlReader;
027import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
028import microsoft.exchange.webservices.data.core.PropertyBag;
029import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
030import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags;
031import microsoft.exchange.webservices.data.property.complex.time.TimeZoneDefinition;
032
033import java.util.EnumSet;
034import java.util.TimeZone;
035
036/**
037 * Represents a property definition for property of type TimeZoneInfo.
038 */
039public class TimeZonePropertyDefinition extends PropertyDefinition {
040
041  /**
042   * Initializes a new instance of the TimeZonePropertyDefinition class.
043   *
044   * @param xmlElementName the xml element name
045   * @param uri            the uri
046   * @param flags          the flags
047   * @param version        the version
048   */
049  public TimeZonePropertyDefinition(String xmlElementName, String uri, EnumSet<PropertyDefinitionFlags> flags,
050      ExchangeVersion version) {
051    super(xmlElementName, uri, flags, version);
052  }
053
054  /**
055   * Loads from XML.
056   *
057   * @param reader      the reader
058   * @param propertyBag the property bag
059   * @throws Exception the exception
060   */
061  public void loadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag) throws Exception {
062    TimeZoneDefinition timeZoneDefinition = new TimeZoneDefinition();
063    timeZoneDefinition.loadFromXml(reader, this.getXmlElement());
064    propertyBag.setObjectFromPropertyDefinition(this, timeZoneDefinition);
065  }
066
067  /**
068   * Writes to XML.
069   *
070   * @param writer            the writer
071   * @param propertyBag       the property bag
072   * @param isUpdateOperation the is update operation
073   * @throws Exception the exception
074   */
075  public void writePropertyValueToXml(EwsServiceXmlWriter writer, PropertyBag propertyBag,
076      boolean isUpdateOperation) throws Exception {
077    TimeZoneDefinition timeZoneDefinition = propertyBag.getObjectFromPropertyDefinition(this);
078
079    if (timeZoneDefinition != null) {
080      // We emit time zone property only if we have not emitted the time
081      // zone SOAP header
082      // or if this time zone is different from that of the service
083      // through which the request
084      // is being emitted.
085      if (!writer.isTimeZoneHeaderEmitted())// || value !=
086      // writer.getService().getTimeZone())
087      {
088        timeZoneDefinition.writeToXml(writer, this.getXmlElement());
089      }
090    }
091  }
092
093  /**
094   * Gets the property type.
095   */
096  @Override
097  public Class<TimeZone> getType() {
098    return TimeZone.class;
099  }
100}