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.EwsUtilities; 029import microsoft.exchange.webservices.data.core.XmlAttributeNames; 030import microsoft.exchange.webservices.data.core.XmlElementNames; 031import microsoft.exchange.webservices.data.core.enumeration.property.BodyType; 032import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlDeserializationException; 033import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException; 034 035import javax.xml.stream.XMLStreamException; 036 037/** 038 * Represents the body part of an item that is unique to the conversation the 039 * item is part of. 040 */ 041public final class UniqueBody extends ComplexProperty { 042 043 /** 044 * The body type. 045 */ 046 private BodyType bodyType; 047 048 /** 049 * The text. 050 */ 051 private String text; 052 053 /** 054 * Initializes a new instance. 055 */ 056 public UniqueBody() { 057 } 058 059 /** 060 * Defines an implicit conversion of UniqueBody into a string. 061 * 062 * @param messageBody the message body 063 * @return string containing the text of the UniqueBody 064 * @throws Exception the exception 065 */ 066 public static String getStringFromUniqueBody(UniqueBody messageBody) 067 throws Exception { 068 EwsUtilities.validateParam(messageBody, "messageBody"); 069 return messageBody.text; 070 } 071 072 /** 073 * Reads attribute from XML. 074 * 075 * @param reader the reader 076 * @throws Exception the exception 077 */ 078 public void readAttributesFromXml(EwsServiceXmlReader reader) 079 throws Exception { 080 this.bodyType = reader.readAttributeValue(BodyType.class, 081 XmlAttributeNames.BodyType); 082 } 083 084 /** 085 * Reads attribute from XML. 086 * 087 * @param reader the reader 088 * @throws XMLStreamException the xml stream exception 089 * @throws ServiceXmlDeserializationException the service xml deserialization exception 090 */ 091 public void readTextValueFromXml(EwsServiceXmlReader reader) 092 throws XMLStreamException, ServiceXmlDeserializationException { 093 this.text = reader.readValue(); 094 } 095 096 /** 097 * Writes attributes from XML. 098 * 099 * @param writer the writer 100 * @throws ServiceXmlSerializationException the service xml serialization exception 101 */ 102 public void writeAttributesToXml(EwsServiceXmlWriter writer) 103 throws ServiceXmlSerializationException { 104 writer.writeAttributeValue(XmlAttributeNames.BodyType, this.bodyType); 105 } 106 107 /** 108 * Writes elements to XML. 109 * 110 * @param writer the writer 111 * @throws ServiceXmlSerializationException the service xml serialization exception 112 */ 113 public void writeElementsToXml(EwsServiceXmlWriter writer) 114 throws ServiceXmlSerializationException { 115 if (!(this.text == null || this.text.isEmpty())) { 116 writer.writeValue(this.text, XmlElementNames.UniqueBody); 117 } 118 } 119 120 /** 121 * Gets the type of the unique body's text. 122 * 123 * @return bodytype 124 */ 125 public BodyType getBodyType() { 126 return this.bodyType; 127 } 128 129 /** 130 * Gets the text of the unique body. 131 * 132 * @return text 133 */ 134 public String getText() { 135 return this.text; 136 } 137 138 /* 139 * (non-Javadoc) 140 * 141 * @see java.lang.Object#toString() 142 */ 143 @Override 144 public String toString() { 145 return (this.getText() == null) ? "" : this.getText(); 146 } 147 148}