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    
024    package microsoft.exchange.webservices.data.core.request;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
027    import microsoft.exchange.webservices.data.core.EwsUtilities;
028    import microsoft.exchange.webservices.data.core.ExchangeService;
029    import microsoft.exchange.webservices.data.core.PropertySet;
030    import microsoft.exchange.webservices.data.core.XmlElementNames;
031    import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling;
032    import microsoft.exchange.webservices.data.core.response.SyncFolderHierarchyResponse;
033    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
034    import microsoft.exchange.webservices.data.core.enumeration.service.ServiceObjectType;
035    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
036    import microsoft.exchange.webservices.data.property.complex.FolderId;
037    
038    /**
039     * Represents a SyncFolderHierarchy request.
040     */
041    public class SyncFolderHierarchyRequest extends
042        MultiResponseServiceRequest<SyncFolderHierarchyResponse> {
043    
044      /**
045       * The property set.
046       */
047      private PropertySet propertySet;
048    
049      /**
050       * The sync folder id.
051       */
052      private FolderId syncFolderId;
053    
054      /**
055       * The sync state.
056       */
057      private String syncState;
058    
059      /**
060       * Initializes a new instance of the class.
061       *
062       * @param service the service
063       * @throws Exception
064       */
065      public SyncFolderHierarchyRequest(ExchangeService service)
066          throws Exception {
067        super(service, ServiceErrorHandling.ThrowOnError);
068      }
069    
070      /**
071       * Creates the service response.
072       *
073       * @param service       the service
074       * @param responseIndex the response index
075       * @return Service response.
076       */
077      @Override
078      protected SyncFolderHierarchyResponse createServiceResponse(
079          ExchangeService service, int responseIndex) {
080        return new SyncFolderHierarchyResponse(this.getPropertySet());
081      }
082    
083      /**
084       * Gets the expected response message count.
085       *
086       * @return Number of expected response
087       */
088      @Override
089      protected int getExpectedResponseMessageCount() {
090        return 1;
091      }
092    
093      /**
094       * Gets the name of the XML element.
095       *
096       * @return XML element name
097       */
098      @Override public String getXmlElementName() {
099        return XmlElementNames.SyncFolderHierarchy;
100      }
101    
102      /**
103       * Gets the name of the response XML element.
104       *
105       * @return XML element name
106       */
107      @Override
108      protected String getResponseXmlElementName() {
109        return XmlElementNames.SyncFolderHierarchyResponse;
110      }
111    
112      /**
113       * Gets the name of the response message XML element.
114       *
115       * @return XML element name
116       */
117      @Override
118      protected String getResponseMessageXmlElementName() {
119        return XmlElementNames.SyncFolderHierarchyResponseMessage;
120      }
121    
122      /**
123       * Validates request.
124       *
125       * @throws Exception the exception
126       */
127      @Override
128      protected void validate() throws Exception {
129        super.validate();
130        EwsUtilities.validateParam(this.getPropertySet(), "PropertySet");
131        if (this.getSyncFolderId() != null) {
132          this.getSyncFolderId().validate(
133              this.getService().getRequestedServerVersion());
134        }
135    
136        this.getPropertySet()
137            .validateForRequest(this, false /* summaryPropertiesOnly */);
138      }
139    
140      /**
141       * Writes XML elements.
142       *
143       * @param writer the writer
144       * @throws Exception the exception
145       */
146      @Override
147      protected void writeElementsToXml(EwsServiceXmlWriter writer)
148          throws Exception {
149        this.getPropertySet().writeToXml(writer, ServiceObjectType.Folder);
150    
151        if (this.getSyncFolderId() != null) {
152          writer.writeStartElement(XmlNamespace.Messages,
153              XmlElementNames.SyncFolderId);
154          this.getSyncFolderId().writeToXml(writer);
155          writer.writeEndElement();
156        }
157    
158        writer.writeElementValue(XmlNamespace.Messages,
159            XmlElementNames.SyncState, this.getSyncState());
160      }
161    
162      /**
163       * Gets the request version.
164       *
165       * @return Earliest Exchange version in which this request is supported.
166       */
167      @Override
168      protected ExchangeVersion getMinimumRequiredServerVersion() {
169        return ExchangeVersion.Exchange2007_SP1;
170      }
171    
172      /**
173       * Gets or sets the property set. <value>The property set.</value>
174       *
175       * @return the property set
176       */
177      public PropertySet getPropertySet() {
178        return this.propertySet;
179      }
180    
181      /**
182       * Sets the property set.
183       *
184       * @param value the new property set
185       */
186      public void setPropertySet(PropertySet value) {
187        this.propertySet = value;
188      }
189    
190      /**
191       * Gets or sets the property set. <value>The property set.</value>
192       *
193       * @return the sync folder id
194       */
195      public FolderId getSyncFolderId() {
196        return this.syncFolderId;
197      }
198    
199      /**
200       * Sets the sync folder id.
201       *
202       * @param value the new sync folder id
203       */
204      public void setSyncFolderId(FolderId value) {
205        this.syncFolderId = value;
206      }
207    
208      /**
209       * Gets or sets the state of the sync. <value>The state of the
210       * sync.</value>
211       *
212       * @return the sync state
213       */
214      public String getSyncState() {
215        return this.syncState;
216      }
217    
218      /**
219       * Sets the sync state.
220       *
221       * @param value the new sync state
222       */
223      public void setSyncState(String value) {
224        this.syncState = value;
225      }
226    
227    }