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.EwsServiceXmlWriter;
027import microsoft.exchange.webservices.data.core.EwsUtilities;
028import microsoft.exchange.webservices.data.core.ExchangeService;
029import microsoft.exchange.webservices.data.core.XmlElementNames;
030import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling;
031import microsoft.exchange.webservices.data.core.response.ExpandGroupResponse;
032import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
033import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
034import microsoft.exchange.webservices.data.property.complex.EmailAddress;
035
036/**
037 * Represents an ExpandGroup request.
038 */
039public class ExpandGroupRequest extends
040    MultiResponseServiceRequest<ExpandGroupResponse> {
041
042  /**
043   * The email address.
044   */
045  private EmailAddress emailAddress;
046
047  /**
048   * Represents an ExpandGroup request.
049   *
050   * @throws Exception the exception
051   */
052  @Override
053  protected void validate() throws Exception {
054    super.validate();
055    EwsUtilities.validateParam(this.getEmailAddress(), "EmailAddress");
056  }
057
058  /**
059   * Creates the service response.
060   *
061   * @param service       the service
062   * @param responseIndex the response index
063   * @return Service response.
064   */
065  @Override
066  protected ExpandGroupResponse createServiceResponse(
067      ExchangeService service, int responseIndex) {
068    return new ExpandGroupResponse();
069  }
070
071  /**
072   * Gets the expected response message count.
073   *
074   * @return Number of expected response messages.
075   */
076  @Override
077  protected int getExpectedResponseMessageCount() {
078    return 1;
079  }
080
081  /**
082   * Gets the name of the XML element.
083   *
084   * @return XML element name
085   */
086  @Override public String getXmlElementName() {
087    return XmlElementNames.ExpandDL;
088  }
089
090  /**
091   * Gets the name of the response XML element.
092   *
093   * @return XML element name
094   */
095  @Override
096  protected String getResponseXmlElementName() {
097    return XmlElementNames.ExpandDLResponse;
098  }
099
100  /**
101   * Gets the name of the response message XML element.
102   *
103   * @return XML element name
104   */
105  @Override
106  protected String getResponseMessageXmlElementName() {
107    return XmlElementNames.ExpandDLResponseMessage;
108  }
109
110  /**
111   * writes XML elements.
112   *
113   * @param writer the writer
114   * @throws Exception the exception
115   */
116  @Override
117  protected void writeElementsToXml(EwsServiceXmlWriter writer)
118      throws Exception {
119    if (this.getEmailAddress() != null) {
120      this.getEmailAddress().writeToXml(writer, XmlNamespace.Messages,
121          XmlElementNames.Mailbox);
122    }
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 on error
140   */
141  public ExpandGroupRequest(ExchangeService service)
142      throws Exception {
143    super(service, ServiceErrorHandling.ThrowOnError);
144  }
145
146  /**
147   * Gets  the email address.
148   *
149   * @return the email address
150   */
151  public EmailAddress getEmailAddress() {
152    return this.emailAddress;
153  }
154
155  /**
156   * Sets the email address.
157   *
158   * @param emailAddress the new email address
159   */
160  public void setEmailAddress(EmailAddress emailAddress) {
161    this.emailAddress = emailAddress;
162  }
163}