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.notification;
025
026import microsoft.exchange.webservices.data.attribute.EditorBrowsable;
027import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
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.enumeration.attribute.EditorBrowsableState;
032import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
033
034/**
035 * Represents the base class for event subscriptions.
036 */
037@EditorBrowsable(state = EditorBrowsableState.Never)
038public abstract class SubscriptionBase {
039
040  /**
041   * The service.
042   */
043  private ExchangeService service;
044
045  /**
046   * The id.
047   */
048  private String id;
049
050  /**
051   * The watermark.
052   */
053  private String watermark;
054
055  /**
056   * Instantiates a new subscription base.
057   *
058   * @param service the service
059   * @throws Exception the exception
060   */
061  protected SubscriptionBase(ExchangeService service) throws Exception {
062    EwsUtilities.validateParam(service, "service");
063    // EwsUtilities.validateParam(service, "service");
064
065    this.service = service;
066  }
067
068  /**
069   * Instantiates a new subscription base.
070   *
071   * @param service the service
072   * @param id      the id
073   * @throws Exception the exception
074   */
075  protected SubscriptionBase(ExchangeService service, String id)
076      throws Exception {
077    this(service);
078    EwsUtilities.validateParam(id, "id");
079
080    this.id = id;
081  }
082
083  /**
084   * Instantiates a new subscription base.
085   *
086   * @param service   the service
087   * @param id        the id
088   * @param watermark the watermark
089   * @throws Exception the exception
090   */
091  protected SubscriptionBase(ExchangeService service, String id,
092      String watermark) throws Exception {
093    this(service, id);
094    this.watermark = watermark;
095  }
096
097  /**
098   * Load from xml.
099   *
100   * @param reader the reader
101   * @throws Exception the exception
102   */
103  public void loadFromXml(EwsServiceXmlReader reader) throws Exception {
104    this.id = reader.readElementValue(XmlNamespace.Messages,
105        XmlElementNames.SubscriptionId);
106    if (this.getUsesWatermark()) {
107      this.watermark = reader.readElementValue(XmlNamespace.Messages,
108          XmlElementNames.Watermark);
109    }
110
111  }
112
113  /**
114   * Gets the session.
115   *
116   * @return the session
117   */
118  protected ExchangeService getService() {
119    return this.service;
120  }
121
122  /**
123   * Gets the id.
124   *
125   * @return the id
126   */
127  public String getId() {
128    return id;
129  }
130
131  /**
132   * Sets the id.
133   *
134   * @param id the new id
135   */
136  protected void setId(String id) {
137    this.id = id;
138  }
139
140  /**
141   * Sets the water mark.
142   *
143   * @param watermark the new water mark
144   */
145  protected void setWaterMark(String watermark) {
146    this.watermark = watermark;
147  }
148
149  /**
150   * Gets the water mark.
151   *
152   * @return the water mark
153   */
154  public String getWaterMark() {
155    return this.watermark;
156  }
157
158  /**
159   * Gets whether or not this subscription uses watermarks.
160   */
161  protected boolean getUsesWatermark() {
162    return true;
163  }
164
165}