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.search;
025
026import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
027import microsoft.exchange.webservices.data.core.EwsUtilities;
028import microsoft.exchange.webservices.data.core.XmlAttributeNames;
029import microsoft.exchange.webservices.data.core.XmlElementNames;
030import microsoft.exchange.webservices.data.core.request.ServiceRequestBase;
031import microsoft.exchange.webservices.data.core.enumeration.search.ItemTraversal;
032import microsoft.exchange.webservices.data.core.enumeration.search.OffsetBasePoint;
033import microsoft.exchange.webservices.data.core.enumeration.service.ServiceObjectType;
034import microsoft.exchange.webservices.data.core.exception.service.local.ServiceValidationException;
035import microsoft.exchange.webservices.data.core.exception.service.local.ServiceVersionException;
036import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
037
038import javax.xml.stream.XMLStreamException;
039
040/**
041 * Represents the view settings in a folder search operation.
042 */
043public final class ItemView extends PagedView {
044
045  /**
046   * The traversal.
047   */
048  private ItemTraversal traversal = ItemTraversal.Shallow;
049
050  /**
051   * The order by.
052   */
053  private OrderByCollection orderBy = new OrderByCollection();
054
055  /**
056   * Gets the name of the view XML element.
057   *
058   * @return XML element name.
059   */
060  @Override
061  protected String getViewXmlElementName() {
062    return XmlElementNames.IndexedPageItemView;
063  }
064
065  /**
066   * Gets the type of service object this view applies to.
067   *
068   * @return A ServiceObjectType value.
069   */
070  @Override
071  protected ServiceObjectType getServiceObjectType() {
072    return ServiceObjectType.Item;
073  }
074
075  /**
076   * Validates this view.
077   *
078   * @param request the request
079   * @throws ServiceVersionException    the service version exception
080   * @throws ServiceValidationException the service validation exception
081   */
082  @Override public void internalValidate(ServiceRequestBase request)
083      throws ServiceVersionException, ServiceValidationException {
084    super.internalValidate(request);
085
086    EwsUtilities.validateEnumVersionValue(this.traversal, request.getService().getRequestedServerVersion());
087  }
088
089  /**
090   * Writes the attribute to XML.
091   *
092   * @param writer the writer
093   * @throws ServiceXmlSerializationException the service xml serialization exception
094   */
095  @Override public void writeAttributesToXml(EwsServiceXmlWriter writer)
096      throws ServiceXmlSerializationException {
097    writer.writeAttributeValue(XmlAttributeNames.Traversal, this.traversal);
098  }
099
100  /**
101   * Internals the write search settings to XML.
102   *
103   * @param writer  the writer
104   * @param groupBy the group by
105   * @throws XMLStreamException the XML stream exception
106   * @throws ServiceXmlSerializationException the service xml serialization exception
107   */
108  @Override
109  protected void internalWriteSearchSettingsToXml(EwsServiceXmlWriter writer,
110      Grouping groupBy) throws XMLStreamException,
111      ServiceXmlSerializationException {
112    super.internalWriteSearchSettingsToXml(writer, groupBy);
113  }
114
115  /**
116   * Writes OrderBy property to XML.
117   *
118   * @param writer the writer
119   * @throws XMLStreamException the XML stream exception
120   * @throws ServiceXmlSerializationException the service xml serialization exception
121   */
122  @Override public void writeOrderByToXml(EwsServiceXmlWriter writer)
123      throws XMLStreamException, ServiceXmlSerializationException {
124    this.orderBy.writeToXml(writer, XmlElementNames.SortOrder);
125  }
126
127  /**
128   * Initializes a new instance of the ItemView class.
129   *
130   * @param pageSize the page size
131   */
132  public ItemView(int pageSize) {
133    super(pageSize);
134  }
135
136  /**
137   * Initializes a new instance of the ItemView class.
138   *
139   * @param pageSize the page size
140   * @param offset   the offset
141   */
142  public ItemView(int pageSize, int offset) {
143    super(pageSize, offset);
144    this.setOffset(offset);
145  }
146
147  /**
148   * Initializes a new instance of the ItemView class.
149   *
150   * @param pageSize        the page size
151   * @param offset          the offset
152   * @param offsetBasePoint the offset base point
153   */
154  public ItemView(int pageSize, int offset, OffsetBasePoint offsetBasePoint) {
155    super(pageSize, offset, offsetBasePoint);
156  }
157
158  /**
159   * Gets  the search traversal mode. Defaults to
160   * ItemTraversal.Shallow.
161   *
162   * @return the traversal
163   */
164  public ItemTraversal getTraversal() {
165    return this.traversal;
166  }
167
168  /**
169   * Sets the traversal.
170   *
171   * @param value the new traversal
172   */
173  public void setTraversal(ItemTraversal value) {
174    this.traversal = value;
175  }
176
177  /**
178   * Gets the property against which the returned item should be ordered.
179   *
180   * @return the order by
181   */
182  public OrderByCollection getOrderBy() {
183    return this.orderBy;
184  }
185}