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.ExchangeService;
029import microsoft.exchange.webservices.data.core.XmlElementNames;
030import microsoft.exchange.webservices.data.core.response.GetInboxRulesResponse;
031import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
032import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
033import microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException;
034import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
035
036import javax.xml.stream.XMLStreamException;
037
038/**
039 * Represents a GetInboxRules request.
040 */
041public final class GetInboxRulesRequest extends SimpleServiceRequestBase<GetInboxRulesResponse> {
042
043  /**
044   * The smtp address of the mailbox from which to get the inbox rules.
045   */
046  private String mailboxSmtpAddress;
047
048  /**
049   * Initializes a new instance of the GetInboxRulesRequest class.
050   *
051   * @param service The service.
052   * @throws Exception
053   */
054  public GetInboxRulesRequest(ExchangeService service) throws Exception {
055    super(service);
056  }
057
058  /**
059   * Gets or sets the address of the mailbox
060   * from which to get the inbox rules.
061   *
062   * @return the mailboxSmtpAddress
063   */
064  protected String getmailboxSmtpAddress() {
065    return this.mailboxSmtpAddress;
066  }
067
068  /**
069   * sets the address of the mailbox from which to get the inbox rules.
070   */
071  public void setmailboxSmtpAddress(String value) {
072    this.mailboxSmtpAddress = value;
073  }
074
075  /**
076   * Gets the name of the XML element.
077   *
078   * @return XML element name.
079   */
080  @Override public String getXmlElementName() {
081    return XmlElementNames.GetInboxRules;
082  }
083
084  /**
085   * Writes XML elements.
086   *
087   * @param writer The writer.
088   * @throws XMLStreamException the XML stream exception
089   * @throws ServiceXmlSerializationException
090   */
091  @Override
092  protected void writeElementsToXml(EwsServiceXmlWriter writer)
093      throws ServiceXmlSerializationException, XMLStreamException {
094    if (!(this.mailboxSmtpAddress == null ||
095        this.mailboxSmtpAddress.isEmpty())) {
096      writer.writeElementValue(
097          XmlNamespace.Messages,
098          XmlElementNames.MailboxSmtpAddress,
099          this.mailboxSmtpAddress);
100    }
101  }
102
103  /**
104   * Gets the name of the response XML element.
105   *
106   * @return XML element name.
107   */
108  @Override
109  protected String getResponseXmlElementName() {
110    return XmlElementNames.GetInboxRulesResponse;
111  }
112
113  /**
114   * {@inheritDoc}
115   */
116  @Override
117  protected GetInboxRulesResponse parseResponse(EwsServiceXmlReader reader)
118      throws Exception {
119    GetInboxRulesResponse response = new GetInboxRulesResponse();
120    response.loadFromXml(reader, XmlElementNames.GetInboxRulesResponse);
121    return response;
122  }
123
124  /**
125   * Gets the request version.
126   *
127   * @return Earliest Exchange version in which this request is supported.
128   */
129  @Override
130  protected ExchangeVersion getMinimumRequiredServerVersion() {
131    return ExchangeVersion.Exchange2010_SP1;
132  }
133
134  /**
135   * Executes this request.
136   *
137   * @return Service response.
138   * @throws Exception
139   * @throws ServiceLocalException
140   */
141  public GetInboxRulesResponse execute()
142      throws ServiceLocalException, Exception {
143    GetInboxRulesResponse serviceResponse = internalExecute();
144    serviceResponse.throwIfNecessary();
145    return serviceResponse;
146  }
147}