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.request;
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.ExchangeService;
030import microsoft.exchange.webservices.data.core.XmlElementNames;
031import microsoft.exchange.webservices.data.core.response.GetUserOofSettingsResponse;
032import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
033import microsoft.exchange.webservices.data.core.enumeration.property.OofExternalAudience;
034import microsoft.exchange.webservices.data.core.enumeration.misc.error.ServiceError;
035import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
036import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
037import microsoft.exchange.webservices.data.property.complex.availability.OofSettings;
038
039import javax.xml.stream.XMLStreamException;
040
041/**
042 * Represents a GetUserOofSettings request.
043 */
044public final class GetUserOofSettingsRequest extends SimpleServiceRequestBase<GetUserOofSettingsResponse> {
045
046  /**
047   * The smtp address.
048   */
049  private String smtpAddress;
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.GetUserOofSettingsRequest;
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  }
071
072  /**
073   * Validate request.
074   *
075   * @param writer the writer
076   * @throws XMLStreamException the XML stream exception
077   * @throws ServiceXmlSerializationException the service xml serialization exception
078   */
079  @Override
080  protected void writeElementsToXml(EwsServiceXmlWriter writer)
081      throws XMLStreamException, ServiceXmlSerializationException {
082    writer.writeStartElement(XmlNamespace.Types, XmlElementNames.Mailbox);
083    writer.writeElementValue(XmlNamespace.Types, XmlElementNames.Address,
084        this.getSmtpAddress());
085    writer.writeEndElement(); // Mailbox
086  }
087
088  /**
089   * Gets the name of the response XML element.
090   *
091   * @return XML element name
092   */
093  @Override
094  protected String getResponseXmlElementName() {
095    return XmlElementNames.GetUserOofSettingsResponse;
096  }
097
098  /**
099   * {@inheritDoc}
100   */
101  @Override
102  protected GetUserOofSettingsResponse parseResponse(EwsServiceXmlReader reader)
103      throws Exception {
104    GetUserOofSettingsResponse serviceResponse =
105        new GetUserOofSettingsResponse();
106
107    serviceResponse.loadFromXml(reader, XmlElementNames.ResponseMessage);
108    if (serviceResponse.getErrorCode() == ServiceError.NoError) {
109      reader.readStartElement(XmlNamespace.Types,
110          XmlElementNames.OofSettings);
111
112      serviceResponse.setOofSettings(new OofSettings());
113      serviceResponse.getOofSettings().loadFromXml(reader,
114          reader.getLocalName());
115
116      serviceResponse.getOofSettings().setAllowExternalOof(
117          reader.readElementValue(OofExternalAudience.class,
118              XmlNamespace.Messages,
119              XmlElementNames.AllowExternalOof));
120    }
121
122    return serviceResponse;
123  }
124
125  /**
126   * Gets the request version.
127   *
128   * @return Earliest Exchange version in which this request is supported
129   */
130  @Override
131  protected ExchangeVersion getMinimumRequiredServerVersion() {
132    return ExchangeVersion.Exchange2007_SP1;
133  }
134
135  /**
136   * Initializes a new instance of the class.
137   *
138   * @param service the service
139   * @throws Exception
140   */
141  public GetUserOofSettingsRequest(ExchangeService service)
142      throws Exception {
143    super(service);
144  }
145
146  /**
147   * Executes this request.
148   *
149   * @return Service response.
150   * @throws Exception the exception
151   */
152  public GetUserOofSettingsResponse execute() throws Exception {
153    GetUserOofSettingsResponse serviceResponse = internalExecute();
154    serviceResponse.throwIfNecessary();
155    return serviceResponse;
156  }
157
158  /**
159   * Gets  the SMTP address.
160   *
161   * @return the smtp address
162   */
163  protected String getSmtpAddress() {
164    return this.smtpAddress;
165  }
166
167  /**
168   * Sets the smtp address.
169   *
170   * @param smtpAddress the new smtp address
171   */
172  public void setSmtpAddress(String smtpAddress) {
173    this.smtpAddress = smtpAddress;
174  }
175
176}