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.core.request;
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.ExchangeService;
030 import microsoft.exchange.webservices.data.core.XmlElementNames;
031 import microsoft.exchange.webservices.data.core.response.ServiceResponse;
032 import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
033 import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
034 import microsoft.exchange.webservices.data.property.complex.availability.OofSettings;
035
036 /**
037 * Represents a SetUserOofSettings request.
038 */
039 public final class SetUserOofSettingsRequest extends SimpleServiceRequestBase<ServiceResponse> {
040
041 /**
042 * The smtp address.
043 */
044 private String smtpAddress;
045
046 /**
047 * The oof settings.
048 */
049 private OofSettings oofSettings;
050
051 /**
052 * Gets the name of the XML element.
053 *
054 * @return XML element name.
055 */
056 @Override public String getXmlElementName() {
057 return XmlElementNames.SetUserOofSettingsRequest;
058 }
059
060 /**
061 * Validate request.
062 *
063 * @throws Exception the exception
064 */
065 @Override
066 protected void validate() throws Exception {
067 super.validate();
068
069 EwsUtilities.validateParam(this.getSmtpAddress(), "SmtpAddress");
070 EwsUtilities.validateParam(this.getOofSettings(), "OofSettings");
071 }
072
073 /**
074 * Writes the elements to XML.
075 *
076 * @param writer the writer
077 * @throws Exception the exception
078 */
079 @Override
080 protected void writeElementsToXml(EwsServiceXmlWriter writer)
081 throws Exception {
082 writer.writeStartElement(XmlNamespace.Types, XmlElementNames.Mailbox);
083 writer.writeElementValue(XmlNamespace.Types, XmlElementNames.Address,
084 this.getSmtpAddress());
085 writer.writeEndElement(); // Mailbox
086
087 this.getOofSettings().writeToXml(writer,
088 XmlElementNames.UserOofSettings);
089 }
090
091 /**
092 * Gets the name of the response XML element.
093 *
094 * @return XML element name
095 */
096 @Override
097 protected String getResponseXmlElementName() {
098 return XmlElementNames.SetUserOofSettingsResponse;
099 }
100
101 /**
102 * {@inheritDoc}
103 */
104 @Override
105 protected ServiceResponse parseResponse(EwsServiceXmlReader reader)
106 throws Exception {
107 ServiceResponse serviceResponse = new ServiceResponse();
108 serviceResponse.loadFromXml(reader, XmlElementNames.ResponseMessage);
109 return serviceResponse;
110 }
111
112 /**
113 * Gets the request version.
114 *
115 * @return Earliest Exchange version in which this request is supported.
116 */
117 @Override
118 protected ExchangeVersion getMinimumRequiredServerVersion() {
119 return ExchangeVersion.Exchange2007_SP1;
120 }
121
122 /**
123 * Initializes a new instance of the class.
124 *
125 * @param service the service
126 * @throws Exception
127 */
128 public SetUserOofSettingsRequest(ExchangeService service)
129 throws Exception {
130 super(service);
131 }
132
133 /**
134 * Executes this request.
135 *
136 * @return Service response
137 * @throws Exception the exception
138 */
139 public ServiceResponse execute() throws Exception {
140 ServiceResponse serviceResponse = internalExecute();
141 serviceResponse.throwIfNecessary();
142 return serviceResponse;
143 }
144
145 /**
146 * Gets the SMTP address.
147 *
148 * @return the smtp address
149 */
150 public String getSmtpAddress() {
151 return this.smtpAddress;
152 }
153
154 /**
155 * Sets the smtp address.
156 *
157 * @param smtpAddress the new smtp address
158 */
159 public void setSmtpAddress(String smtpAddress) {
160 this.smtpAddress = smtpAddress;
161 }
162
163 /**
164 * Gets the oof settings.
165 *
166 * @return the oof settings
167 */
168 public OofSettings getOofSettings() {
169 return this.oofSettings;
170 }
171
172 /**
173 * Sets the oof settings.
174 *
175 * @param oofSettings the new oof settings
176 */
177 public void setOofSettings(OofSettings oofSettings) {
178 this.oofSettings = oofSettings;
179 }
180
181 }