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.EwsServiceXmlReader;
027import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
028import microsoft.exchange.webservices.data.core.XmlAttributeNames;
029import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlDeserializationException;
030import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
031
032import javax.xml.stream.XMLStreamException;
033
034/**
035 * Defines the EwsXmlReader class.
036 */
037public final class InternetMessageHeader extends ComplexProperty {
038
039  /**
040   * The name.
041   */
042  private String name;
043
044  /**
045   * The value.
046   */
047  private String value;
048
049  /**
050   * Initializes a new instance of the EwsXmlReader class.
051   */
052  protected InternetMessageHeader() {
053  }
054
055  /**
056   * Reads the attribute from XML.
057   *
058   * @param reader the reader
059   * @throws Exception the exception
060   */
061  public void readAttributesFromXml(EwsServiceXmlReader reader)
062      throws Exception {
063    this.name = reader.readAttributeValue(XmlAttributeNames.HeaderName);
064  }
065
066  /**
067   * Reads the text value from XML.
068   *
069   * @param reader the reader
070   * @throws XMLStreamException the XML stream exception
071   * @throws ServiceXmlDeserializationException the service xml deserialization exception
072   */
073  public void readTextValueFromXml(EwsServiceXmlReader reader)
074      throws XMLStreamException, ServiceXmlDeserializationException {
075    this.value = reader.readValue();
076  }
077
078  /**
079   * Writes the attribute to XML.
080   *
081   * @param writer the writer
082   * @throws ServiceXmlSerializationException the service xml serialization exception
083   */
084  public void writeAttributesToXml(EwsServiceXmlWriter writer)
085      throws ServiceXmlSerializationException {
086    writer.writeAttributeValue(XmlAttributeNames.HeaderName, this.name);
087  }
088
089  /**
090   * Writes elements to XML.
091   *
092   * @param writer the writer
093   * @throws ServiceXmlSerializationException the service xml serialization exception
094   */
095  public void writeElementsToXml(EwsServiceXmlWriter writer)
096      throws ServiceXmlSerializationException {
097    writer.writeValue(this.value, this.name);
098  }
099
100  /**
101   * Obtains a string representation of the header.
102   *
103   * @return The string representation of the header.
104   */
105  public String toString() {
106    return String.format("%s=%s", this.name, this.value);
107  }
108
109  /**
110   * The name of the header.
111   *
112   * @param name the new name
113   */
114  public void setName(String name) {
115    this.name = name;
116  }
117
118  /**
119   * Gets the name.
120   *
121   * @return the name
122   */
123  public String getName() {
124    return name;
125  }
126
127  /**
128   * The value of the header.
129   *
130   * @return the value
131   */
132  public String getValue() {
133    return value;
134  }
135
136  /**
137   * Sets the value.
138   *
139   * @param value the value to set
140   */
141  public void setValue(String value) {
142    this.value = value;
143  }
144
145}