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    
024    package microsoft.exchange.webservices.data.property.complex.time;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
027    import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
028    import microsoft.exchange.webservices.data.core.EwsUtilities;
029    import microsoft.exchange.webservices.data.core.XmlAttributeNames;
030    import microsoft.exchange.webservices.data.core.XmlElementNames;
031    import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
032    import microsoft.exchange.webservices.data.misc.TimeSpan;
033    import microsoft.exchange.webservices.data.property.complex.ComplexProperty;
034    
035    /**
036     * Represents a time zone period as defined in the EWS schema.
037     */
038    public class TimeZonePeriod extends ComplexProperty {
039    
040      /**
041       * The Constant StandardPeriodId.
042       */
043      protected final static String StandardPeriodId = "Std";
044    
045      /**
046       * The Constant StandardPeriodName.
047       */
048      protected final static String StandardPeriodName = "Standard";
049    
050      /**
051       * The Constant DaylightPeriodId.
052       */
053      protected final static String DaylightPeriodId = "Dlt";
054    
055      /**
056       * The Constant DaylightPeriodName.
057       */
058      protected final static String DaylightPeriodName = "Daylight";
059    
060      /**
061       * The bias.
062       */
063      private TimeSpan bias;
064    
065      /**
066       * The name.
067       */
068      private String name;
069    
070      /**
071       * The id.
072       */
073      private String id;
074    
075      /**
076       * Reads the attribute from XML.
077       *
078       * @param reader the reader
079       * @throws Exception the exception
080       */
081      @Override
082      public void readAttributesFromXml(EwsServiceXmlReader reader)
083          throws Exception {
084        this.id = reader.readAttributeValue(XmlAttributeNames.Id);
085        this.name = reader.readAttributeValue(XmlAttributeNames.Name);
086        this.bias = EwsUtilities.getXSDurationToTimeSpan(reader.readAttributeValue(XmlAttributeNames.Bias));
087      }
088    
089      /**
090       * Writes the attribute to XML.
091       *
092       * @param writer the writer
093       * @throws ServiceXmlSerializationException the service xml serialization exception
094       */
095      @Override
096      public void writeAttributesToXml(EwsServiceXmlWriter writer)
097          throws ServiceXmlSerializationException {
098        writer.writeAttributeValue(XmlAttributeNames.Bias, EwsUtilities
099            .getTimeSpanToXSDuration(this.bias));
100        writer.writeAttributeValue(XmlAttributeNames.Name, this.name);
101        writer.writeAttributeValue(XmlAttributeNames.Id, this.id);
102      }
103    
104      /**
105       * Loads from XML.
106       *
107       * @param reader the reader
108       * @throws Exception the exception
109       */
110      public void loadFromXml(EwsServiceXmlReader reader) throws Exception {
111        this.loadFromXml(reader, XmlElementNames.Period);
112      }
113    
114      /**
115       * Writes to XML.
116       *
117       * @param writer the writer
118       * @throws Exception the exception
119       */
120      public void writeToXml(EwsServiceXmlWriter writer) throws Exception {
121        this.writeToXml(writer, XmlElementNames.Period);
122      }
123    
124      /**
125       * Initializes a new instance of the TimeZonePeriod class.
126       */
127      public TimeZonePeriod() {
128        super();
129      }
130    
131      /**
132       * Gets a value indicating whether this period represents the Standard
133       * period.
134       *
135       * @return true if this instance is standard period; otherwise, false
136       */
137      protected boolean isStandardPeriod() {
138        return this.name.equals(TimeZonePeriod.StandardPeriodName);
139      }
140    
141      /**
142       * Gets the bias to UTC associated with this period.
143       *
144       * @return the bias
145       */
146      protected TimeSpan getBias() {
147        return bias;
148      }
149    
150      /**
151       * Sets the bias.
152       *
153       * @param bias the new bias
154       */
155      protected void setBias(TimeSpan bias) {
156        this.bias = bias;
157      }
158    
159      /**
160       * Gets the name of this period.
161       *
162       * @return the name
163       */
164      protected String getName() {
165        return name;
166      }
167    
168      /**
169       * Sets the name.
170       *
171       * @param name the new name
172       */
173      protected void setName(String name) {
174        this.name = name;
175      }
176    
177      /**
178       * Gets the id of this period.
179       *
180       * @return the id
181       */
182      public String getId() {
183        return id;
184      }
185    
186      /**
187       * Sets the id.
188       *
189       * @param id the new id
190       */
191      protected void setId(String id) {
192        this.id = id;
193      }
194    
195    }