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.autodiscover;
025
026import microsoft.exchange.webservices.data.core.EwsXmlReader;
027import microsoft.exchange.webservices.data.core.XmlElementNames;
028import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
029import microsoft.exchange.webservices.data.security.XmlNodeType;
030
031/**
032 * Defines the AlternateMailbox class.
033 */
034public final class AlternateMailbox {
035
036  /**
037   * The type.
038   */
039  private String type;
040
041  /**
042   * The display name.
043   */
044  private String displayName;
045
046  /**
047   * The legacy dn.
048   */
049  private String legacyDN;
050
051  /**
052   * The server.
053   */
054  private String server;
055
056  /**
057   * The SMTP address of alternate mailbox. It is only set if it is available
058   * for the given type. E.g. type 'Delegate' has one type 'Archive' not.
059   */
060  private String smtpAddress;
061
062
063  /**
064   * The SMTP address of the owner of this alternate mailbox.
065   */
066  private String ownerSmtpAddress;
067
068  /**
069   * Initializes a new instance of the AlternateMailbox class.
070   */
071  private AlternateMailbox() {}
072
073  /**
074   * PLoads AlternateMailbox instance from XML.
075   *
076   * @param reader the reader
077   * @return AlternateMailbox
078   * @throws Exception the exception
079   */
080  public static AlternateMailbox loadFromXml(final EwsXmlReader reader)
081      throws Exception {
082    final AlternateMailbox altMailbox = new AlternateMailbox();
083
084    do {
085      reader.read();
086
087      if (reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) {
088        if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.Type)) {
089          altMailbox.setType(reader.readElementValue(String.class));
090        } else if (reader.getLocalName()
091            .equalsIgnoreCase(XmlElementNames.DisplayName)) {
092          altMailbox.setDisplayName(reader.readElementValue(String.class));
093        } else if (reader.getLocalName()
094            .equalsIgnoreCase(XmlElementNames.LegacyDN)) {
095          altMailbox.setLegacyDN(reader.readElementValue(String.class));
096        } else
097          if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.Server)) {
098          altMailbox.setServer(reader.readElementValue(String.class));
099        } else if (reader.getLocalName()
100            .equalsIgnoreCase(XmlElementNames.SmtpAddress)) {
101          altMailbox.setSmtpAddress(reader.readElementValue(String.class));
102        } else if (reader.getLocalName()
103            .equalsIgnoreCase(XmlElementNames.OwnerSmtpAddress)) {
104          altMailbox.setOwnerSmtpAddress(reader.readElementValue(String.class));
105        }
106      }
107    } while (!reader.isEndElement(XmlNamespace.Autodiscover,
108        XmlElementNames.AlternateMailbox));
109
110    return altMailbox;
111  }
112
113  /**
114   * Gets the alternate mailbox type.
115   *
116   * @return the type
117   */
118  public String getType() {
119    return type;
120  }
121
122  /**
123   * Sets the type.
124   *
125   * @param type the new type
126   */
127  protected void setType(final String type) {
128    this.type = type;
129  }
130
131  /**
132   * Gets the alternate mailbox display name.
133   *
134   * @return the display name
135   */
136  public String getDisplayName() {
137    return displayName;
138  }
139
140  /**
141   * Sets the display name.
142   *
143   * @param displayName the new display name
144   */
145  protected void setDisplayName(final String displayName) {
146    this.displayName = displayName;
147  }
148
149  /**
150   * Gets the alternate mailbox legacy DN.
151   *
152   * @return the legacy dn
153   */
154  public String getLegacyDN() {
155    return legacyDN;
156  }
157
158  /**
159   * Sets the legacy dn.
160   *
161   * @param legacyDN the new legacy dn
162   */
163  protected void setLegacyDN(final String legacyDN) {
164    this.legacyDN = legacyDN;
165  }
166
167  /**
168   * Gets the alernate mailbox server.
169   *
170   * @return the server
171   */
172  public String getServer() {
173    return server;
174  }
175
176  /**
177   * Sets the server.
178   *
179   * @param server the new server.
180   */
181  protected void setServer(final String server) {
182    this.server = server;
183  }
184
185  /**
186   * Gets the SMTP address.
187   *
188   * @return the SMTP address if available for the mailbox type otherwise null
189   *         is returned.
190   */
191  public String getSmtpAddress() {
192    return smtpAddress;
193  }
194
195  /**
196   * Sets the SMTP address.
197   *
198   * @param smtpAddress the new SMTP address.
199   */
200  protected void setSmtpAddress(final String smtpAddress) {
201    this.smtpAddress = smtpAddress;
202  }
203
204  /**
205   * Gets the owner SMTP address.
206   *
207   * @return the SMTP address of the owner of this mailbox.
208   */
209  public String getOwnerSmtpAddress() {
210    return ownerSmtpAddress;
211  }
212
213  /**
214   * Sets the owner SMTP address.
215   *
216   * @param ownerSmtpAddress the new owner SMTP address
217   */
218  protected void setOwnerSmtpAddress(final String ownerSmtpAddress) {
219    this.ownerSmtpAddress = ownerSmtpAddress;
220  }
221
222}