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;
025
026 /**
027 * Represents Exchange server information.
028 */
029 public final class ExchangeServerInfo {
030
031 /**
032 * The major version.
033 */
034 private int majorVersion;
035
036 /**
037 * The minor version.
038 */
039 private int minorVersion;
040
041 /**
042 * The major build number.
043 */
044 private int majorBuildNumber;
045
046 /**
047 * The minor build number.
048 */
049 private int minorBuildNumber;
050
051 /**
052 * The version string.
053 */
054 private String versionString;
055
056 /*
057 * Default constructor
058 */
059
060 /**
061 * Instantiates a new exchange server info.
062 */
063 public ExchangeServerInfo() {
064
065 }
066
067 /**
068 * Parse current element to extract server information.
069 *
070 * @param reader EwsServiceXmlReader
071 * @return ExchangeServerInfo
072 * @throws Exception the exception
073 */
074 public static ExchangeServerInfo parse(EwsServiceXmlReader reader)
075 throws Exception {
076 EwsUtilities.ewsAssert(reader.hasAttributes(), "ExchangeServerVersion.Parse",
077 "Current element doesn't have attribute");
078
079 ExchangeServerInfo info = new ExchangeServerInfo();
080 info.majorVersion = reader.readAttributeValue(Integer.class,
081 "MajorVersion");
082 info.minorVersion = reader.readAttributeValue(Integer.class,
083 "MinorVersion");
084 info.majorBuildNumber = reader.readAttributeValue(Integer.class,
085 "MajorBuildNumber");
086 info.minorBuildNumber = reader.readAttributeValue(Integer.class,
087 "MinorBuildNumber");
088 info.versionString = reader.readAttributeValue("Version");
089 return info;
090 }
091
092 /**
093 * Gets the Major Exchange server version number.
094 *
095 * @return the major version
096 */
097 public int getMajorVersion() {
098 return this.majorVersion;
099 }
100
101 /**
102 * Sets the major version.
103 *
104 * @param majorVersion the new major version
105 */
106 public void setMajorVersion(int majorVersion) {
107 this.majorVersion = majorVersion;
108 }
109
110 /**
111 * Gets the Minor Exchange server version number.
112 *
113 * @return the minor version
114 */
115 public int getMinorVersion() {
116 return minorVersion;
117 }
118
119 /**
120 * Sets the minor version.
121 *
122 * @param minorVersion the new minor version
123 */
124 public void setMinorVersion(int minorVersion) {
125 this.minorVersion = minorVersion;
126 }
127
128 /**
129 * Gets the Major Exchange server build number.
130 *
131 * @return the major build number
132 */
133 public int getMajorBuildNumber() {
134 return majorBuildNumber;
135 }
136
137 /**
138 * Sets the major build number.
139 *
140 * @param majorBuildNumber the new major build number
141 */
142 public void setMajorBuildNumber(int majorBuildNumber) {
143 this.majorBuildNumber = majorBuildNumber;
144 }
145
146 /**
147 * Gets the Minor Exchange server build number.
148 *
149 * @return the minor build number
150 */
151 public int getMinorBuildNumber() {
152 return minorBuildNumber;
153 }
154
155 /**
156 * Sets the minor build number.
157 *
158 * @param minorBuildNumber the new minor build number
159 */
160 public void setMinorBuildNumber(int minorBuildNumber) {
161 this.minorBuildNumber = minorBuildNumber;
162 }
163
164 /**
165 * Gets the Exchange server version string (e.g. "Exchange2010")
166 *
167 * @return the version string
168 */
169 // / The version is a string rather than an enum since its possible for the
170 // client to
171 // / be connected to a later server for which there would be no appropriate
172 // enum value.
173 public String getVersionString() {
174 return versionString;
175 }
176
177 /**
178 * Sets the version string.
179 *
180 * @param versionString the new version string
181 */
182 public void setVersionString(String versionString) {
183 this.versionString = versionString;
184 }
185
186 /**
187 * Override ToString method.
188 *
189 * @return the string
190 */
191 @Override
192 public String toString() {
193 return String
194 .format("%d,%2d,%4d,%3d", this.majorVersion, this.minorVersion,
195 this.majorBuildNumber, this.minorBuildNumber);
196 }
197 }