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.core.service.response; 025 026import microsoft.exchange.webservices.data.core.EwsUtilities; 027import microsoft.exchange.webservices.data.core.XmlElementNames; 028import microsoft.exchange.webservices.data.core.service.item.EmailMessage; 029import microsoft.exchange.webservices.data.core.service.item.Item; 030import microsoft.exchange.webservices.data.core.service.schema.EmailMessageSchema; 031import microsoft.exchange.webservices.data.core.service.schema.ItemSchema; 032import microsoft.exchange.webservices.data.core.service.schema.ResponseMessageSchema; 033import microsoft.exchange.webservices.data.core.service.schema.ResponseObjectSchema; 034import microsoft.exchange.webservices.data.core.service.schema.ServiceObjectSchema; 035import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion; 036import microsoft.exchange.webservices.data.core.enumeration.service.ResponseMessageType; 037import microsoft.exchange.webservices.data.property.complex.EmailAddressCollection; 038import microsoft.exchange.webservices.data.property.complex.MessageBody; 039 040/** 041 * The Class ResponseMessage. 042 */ 043public final class ResponseMessage extends ResponseObject<EmailMessage> { 044 045 /** 046 * Represents the base class for e-mail related response (Reply, Reply all 047 * and Forward). 048 */ 049 private ResponseMessageType responseType; 050 051 /** 052 * Initializes a new instance of the class. 053 * 054 * @param referenceItem the reference item 055 * @param responseType the response type 056 * @throws Exception the exception 057 */ 058 public ResponseMessage(Item referenceItem, ResponseMessageType responseType) 059 throws Exception { 060 super(referenceItem); 061 this.responseType = responseType; 062 } 063 064 /** 065 * Internal method to return the schema associated with this type of object. 066 * 067 * @return The schema associated with this type of object. 068 */ 069 @Override public ServiceObjectSchema getSchema() { 070 return ResponseMessageSchema.Instance; 071 } 072 073 /** 074 * Gets the minimum required server version. 075 * 076 * @return Earliest Exchange version in which this service object type is 077 * supported. 078 */ 079 @Override public ExchangeVersion getMinimumRequiredServerVersion() { 080 return ExchangeVersion.Exchange2007_SP1; 081 } 082 083 /** 084 * This methods lets subclasses of ServiceObject override the default 085 * mechanism by which the XML element name associated with their type is 086 * retrieved. 087 * 088 * @return The XML element name associated with this type. If this method 089 * returns null or empty, the XML element name associated with this 090 * type is determined by the EwsObjectDefinition attribute that 091 * decorates the type,if present. 092 */ 093 protected String getXmlElementNameOverride() { 094 095 if (this.responseType == ResponseMessageType.Reply) { 096 return XmlElementNames.ReplyToItem; 097 } else if (this.responseType == ResponseMessageType.ReplyAll) { 098 return XmlElementNames.ReplyAllToItem; 099 } else if (this.responseType == ResponseMessageType.Forward) { 100 return XmlElementNames.ForwardItem; 101 } else { 102 EwsUtilities.ewsAssert(false, "ResponseMessage.GetXmlElementNameOverride", 103 "An unexpected value for responseType could not be handled."); 104 return null; // Because the compiler wants it 105 } 106 107 } 108 109 /** 110 * Gets a value indicating the type of response this object represents. 111 * 112 * @return the response type 113 */ 114 public ResponseMessageType getResponseType() { 115 return this.responseType; 116 } 117 118 /** 119 * Gets the body of the response. 120 * 121 * @return the body 122 * @throws Exception the exception 123 */ 124 public MessageBody getBody() throws Exception { 125 return (MessageBody) this 126 .getObjectFromPropertyDefinition(ItemSchema.Body); 127 } 128 129 /** 130 * Sets the body. 131 * 132 * @param value the new body 133 * @throws Exception the exception 134 */ 135 public void setBody(MessageBody value) throws Exception { 136 this.getPropertyBag().setObjectFromPropertyDefinition(ItemSchema.Body, 137 value); 138 } 139 140 /** 141 * Gets a list of recipients the response will be sent to. 142 * 143 * @return the to recipients 144 * @throws Exception the exception 145 */ 146 public EmailAddressCollection getToRecipients() throws Exception { 147 return (EmailAddressCollection) this 148 .getObjectFromPropertyDefinition( 149 EmailMessageSchema.ToRecipients); 150 } 151 152 /** 153 * Gets a list of recipients the response will be sent to as Cc. 154 * 155 * @return the cc recipients 156 * @throws Exception the exception 157 */ 158 public EmailAddressCollection getCcRecipients() throws Exception { 159 return (EmailAddressCollection) this 160 .getObjectFromPropertyDefinition( 161 EmailMessageSchema.CcRecipients); 162 } 163 164 /** 165 * Gets a list of recipients the response will be sent to as Cc. 166 * 167 * @return the bcc recipients 168 * @throws Exception the exception 169 */ 170 public EmailAddressCollection getBccRecipients() throws Exception { 171 return (EmailAddressCollection) this 172 .getObjectFromPropertyDefinition( 173 EmailMessageSchema.BccRecipients); 174 } 175 176 /** 177 * Gets the subject of this response. 178 * 179 * @return the subject 180 * @throws Exception the exception 181 */ 182 public String getSubject() throws Exception { 183 return (String) this 184 .getObjectFromPropertyDefinition(EmailMessageSchema.Subject); 185 } 186 187 /** 188 * Sets the subject. 189 * 190 * @param value the new subject 191 * @throws Exception the exception 192 */ 193 public void setSubject(String value) throws Exception { 194 this.getPropertyBag().setObjectFromPropertyDefinition( 195 EmailMessageSchema.Subject, value); 196 } 197 198 /** 199 * Gets the body prefix of this response. The body prefix will be 200 * prepended to the original message's body when the response is created. 201 * 202 * @return the body prefix 203 * @throws Exception the exception 204 */ 205 public MessageBody getBodyPrefix() throws Exception { 206 return (MessageBody) this 207 .getObjectFromPropertyDefinition( 208 ResponseObjectSchema.BodyPrefix); 209 } 210 211 /** 212 * Sets the body prefix. 213 * 214 * @param value the new body prefix 215 * @throws Exception the exception 216 */ 217 public void setBodyPrefix(MessageBody value) throws Exception { 218 this.getPropertyBag().setObjectFromPropertyDefinition( 219 ResponseObjectSchema.BodyPrefix, value); 220 } 221 222}