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.XmlElementNames;
030 import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling;
031 import microsoft.exchange.webservices.data.core.response.GetServerTimeZonesResponse;
032 import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
033 import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
034 import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
035
036 import javax.xml.stream.XMLStreamException;
037
038 /**
039 * Represents a GetServerTimeZones request.
040 */
041 public final class GetServerTimeZonesRequest extends
042 MultiResponseServiceRequest<GetServerTimeZonesResponse> {
043
044 /**
045 * The ids.
046 */
047 private Iterable<String> ids;
048
049 /**
050 * Gets the XML element name associated with the transition.
051 *
052 * @throws Exception the exception
053 */
054 @Override
055 protected void validate() throws Exception {
056 super.validate();
057 if (this.ids != null) {
058 EwsUtilities.validateParamCollection(this.getIds().iterator(), "Ids");
059 }
060 }
061
062 /**
063 * Initializes a new instance of the "GetServerTimeZonesRequest" class.
064 *
065 * @param service the service
066 * @throws Exception
067 */
068 public GetServerTimeZonesRequest(ExchangeService service)
069 throws Exception {
070 super(service, ServiceErrorHandling.ThrowOnError);
071 }
072
073 /**
074 * Creates the service response.
075 *
076 * @param service the service
077 * @param responseIndex the response index
078 * @return Service response.
079 */
080 @Override
081 protected GetServerTimeZonesResponse createServiceResponse(
082 ExchangeService service, int responseIndex) {
083 return new GetServerTimeZonesResponse();
084 }
085
086 /**
087 * Gets the name of the response message XML element.
088 *
089 * @return XML element name,
090 */
091 @Override
092 protected String getResponseMessageXmlElementName() {
093 return XmlElementNames.GetServerTimeZonesResponseMessage;
094 }
095
096 /**
097 * Gets the expected response message count.
098 *
099 * @return Number of expected response messages.
100 */
101 @Override
102 protected int getExpectedResponseMessageCount() {
103 return 1;
104 }
105
106 /**
107 * Gets the name of the XML element.
108 *
109 * @return XML element name,
110 */
111 @Override public String getXmlElementName() {
112 return XmlElementNames.GetServerTimeZones;
113 }
114
115 /**
116 * Gets the name of the response XML element.
117 *
118 * @return XML element name,
119 */
120 @Override
121 protected String getResponseXmlElementName() {
122 return XmlElementNames.GetServerTimeZonesResponse;
123 }
124
125 /**
126 * Gets the minimum server version required to process this request.
127 *
128 * @return Exchange server version.
129 */
130 @Override
131 protected ExchangeVersion getMinimumRequiredServerVersion() {
132 return ExchangeVersion.Exchange2010;
133 }
134
135 /**
136 * Writes XML elements.
137 *
138 * @param writer the writer
139 * @throws ServiceXmlSerializationException the service xml serialization exception
140 * @throws XMLStreamException the XML stream exception
141 */
142 @Override
143 protected void writeElementsToXml(EwsServiceXmlWriter writer)
144 throws ServiceXmlSerializationException, XMLStreamException {
145 if (this.getIds() != null) {
146 writer
147 .writeStartElement(XmlNamespace.Messages,
148 XmlElementNames.Ids);
149
150 for (String id : this.getIds()) {
151 writer.writeElementValue(XmlNamespace.Types,
152 XmlElementNames.Id, id);
153 }
154
155 writer.writeEndElement(); // Ids
156 }
157 }
158
159 /**
160 * Gets the ids of the time zones that should be returned by the
161 * server.
162 *
163 * @return the ids
164 */
165 protected Iterable<String> getIds() {
166 return this.ids;
167 }
168
169 /**
170 * Sets the ids.
171 *
172 * @param ids the new ids
173 */
174 protected void setIds(Iterable<String> ids) {
175 this.ids = ids;
176 }
177 }