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.ExchangeService;
028 import microsoft.exchange.webservices.data.core.XmlAttributeNames;
029 import microsoft.exchange.webservices.data.core.XmlElementNames;
030 import microsoft.exchange.webservices.data.core.response.GetDelegateResponse;
031 import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
032 import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
033 import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
034 import microsoft.exchange.webservices.data.property.complex.UserId;
035
036 import java.util.ArrayList;
037 import java.util.List;
038
039 /**
040 * Represents a GetDelegate request.
041 */
042 public class GetDelegateRequest extends
043 DelegateManagementRequestBase<GetDelegateResponse> {
044
045 /**
046 * The user ids.
047 */
048 private List<UserId> userIds = new ArrayList<UserId>();
049
050 /**
051 * The include permissions.
052 */
053 private boolean includePermissions;
054
055 /**
056 * Initializes a new instance of the class.
057 *
058 * @param service the service
059 * @throws Exception
060 */
061 public GetDelegateRequest(ExchangeService service)
062 throws Exception {
063 super(service);
064 }
065
066 /**
067 * Creates the response.
068 *
069 * @return Service response.
070 */
071 @Override
072 protected GetDelegateResponse createResponse() {
073 return new GetDelegateResponse(true);
074 }
075
076 /**
077 * Writes XML attribute.
078 *
079 * @param writer the writer
080 * @throws ServiceXmlSerializationException the service xml serialization exception
081 */
082 @Override
083 protected void writeAttributesToXml(EwsServiceXmlWriter writer)
084 throws ServiceXmlSerializationException {
085 super.writeAttributesToXml(writer);
086 writer.writeAttributeValue(XmlAttributeNames.IncludePermissions, this
087 .getIncludePermissions());
088 }
089
090 /**
091 * Writes the elements to XML.
092 *
093 * @param writer the writer
094 * @throws Exception the exception
095 */
096 @Override
097 protected void writeElementsToXml(EwsServiceXmlWriter writer)
098 throws Exception {
099 super.writeElementsToXml(writer);
100
101 if (this.getUserIds().size() > 0) {
102 writer.writeStartElement(XmlNamespace.Messages,
103 XmlElementNames.UserIds);
104
105 for (UserId userId : this.getUserIds()) {
106 userId.writeToXml(writer, XmlElementNames.UserId);
107 }
108
109 writer.writeEndElement(); // UserIds
110 }
111 }
112
113 /**
114 * Gets the name of the response XML element.
115 *
116 * @return XML element name
117 */
118 @Override
119 protected String getResponseXmlElementName() {
120 return XmlElementNames.GetDelegateResponse;
121 }
122
123 /**
124 * Gets the name of the XML element.
125 *
126 * @return XML element name
127 */
128 @Override public String getXmlElementName() {
129 return XmlElementNames.GetDelegate;
130 }
131
132 /**
133 * Gets the request version.
134 *
135 * @return Earliest Exchange version in which this request is supported
136 */
137 @Override
138 protected ExchangeVersion getMinimumRequiredServerVersion() {
139 return ExchangeVersion.Exchange2007_SP1;
140 }
141
142 /**
143 * Gets the user ids. <value>The user ids.</value>
144 *
145 * @return the user ids
146 */
147 public List<UserId> getUserIds() {
148 return this.userIds;
149 }
150
151 /**
152 * Gets a value indicating whether permissions are included.
153 *
154 * @return the include permissions
155 */
156 public boolean getIncludePermissions() {
157 return this.includePermissions;
158
159 }
160
161 /**
162 * Sets the include permissions.
163 *
164 * @param includePermissions the new include permissions
165 */
166 public void setIncludePermissions(boolean includePermissions) {
167 this.includePermissions = includePermissions;
168 }
169 }