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.GetEventsResponse;
032import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
033import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
034import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
035
036import javax.xml.stream.XMLStreamException;
037
038/**
039 * GetEvents request.
040 */
041public class GetEventsRequest extends MultiResponseServiceRequest<GetEventsResponse> {
042
043  /**
044   * The subscription id.
045   */
046  private String subscriptionId;
047
048  /**
049   * The watermark.
050   */
051  private String watermark;
052
053  /**
054   * Initializes a new instance.
055   *
056   * @param service the service
057   * @throws Exception
058   */
059  public GetEventsRequest(ExchangeService service)
060      throws Exception {
061    super(service, ServiceErrorHandling.ThrowOnError);
062  }
063
064  /**
065   * Creates the service response.
066   *
067   * @param service       the service
068   * @param responseIndex the response index
069   * @return Service response
070   */
071  @Override
072  protected GetEventsResponse createServiceResponse(ExchangeService service,
073      int responseIndex) {
074    return new GetEventsResponse();
075  }
076
077  /**
078   * Gets the expected response message count.
079   *
080   * @return Response count
081   */
082  @Override
083  protected int getExpectedResponseMessageCount() {
084    return 1;
085  }
086
087  /**
088   * Gets the name of the XML element.
089   *
090   * @return XML element name
091   */
092  @Override public String getXmlElementName() {
093    return XmlElementNames.GetEvents;
094  }
095
096  /**
097   * Gets the name of the response XML element.
098   *
099   * @return XML element name
100   */
101  @Override
102  protected String getResponseXmlElementName() {
103    return XmlElementNames.GetEventsResponse;
104  }
105
106  /**
107   * Gets the name of the response message XML element.
108   *
109   * @return XML element name
110   */
111  @Override
112  protected String getResponseMessageXmlElementName() {
113    return XmlElementNames.GetEventsResponseMessage;
114  }
115
116  /**
117   * Validates the request.
118   *
119   * @throws Exception the exception
120   */
121  protected void validate() throws Exception {
122    super.validate();
123    EwsUtilities.validateNonBlankStringParam(this.
124        getSubscriptionId(), "SubscriptionId");
125    EwsUtilities.validateNonBlankStringParam(this.
126        getWatermark(), "Watermark");
127  }
128
129  /**
130   * Writes the elements to XML writer.
131   *
132   * @param writer the writer
133   * @throws XMLStreamException the XML stream exception
134   * @throws ServiceXmlSerializationException the service xml serialization exception
135   */
136  @Override
137  protected void writeElementsToXml(EwsServiceXmlWriter writer)
138      throws XMLStreamException, ServiceXmlSerializationException {
139    writer.writeElementValue(XmlNamespace.Messages,
140        XmlElementNames.SubscriptionId, this.getSubscriptionId());
141    writer.writeElementValue(XmlNamespace.Messages,
142        XmlElementNames.Watermark, this.getWatermark());
143  }
144
145  /**
146   * Gets the request version.
147   *
148   * @return Earliest Exchange version in which this request is supported
149   */
150  @Override
151  protected ExchangeVersion getMinimumRequiredServerVersion() {
152    return ExchangeVersion.Exchange2007_SP1;
153  }
154
155  /**
156   * gets the subscriptionId.
157   *
158   * @return the subscriptionId.
159   */
160  public String getSubscriptionId() {
161    return subscriptionId;
162  }
163
164  /**
165   * Sets the subscriptionId.
166   *
167   * @param subscriptionId the subscriptionId.
168   */
169  public void setSubscriptionId(String subscriptionId) {
170    this.subscriptionId = subscriptionId;
171  }
172
173  /**
174   * gets the watermark.
175   *
176   * @return the watermark.
177   */
178  public String getWatermark() {
179    return watermark;
180  }
181
182  /**
183   * Sets the watermark.
184   *
185   * @param watermark the new watermark
186   */
187  public void setWatermark(String watermark) {
188    this.watermark = watermark;
189  }
190}