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.misc.availability;
025
026import microsoft.exchange.webservices.data.ISelfValidate;
027import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
028import microsoft.exchange.webservices.data.core.EwsUtilities;
029import microsoft.exchange.webservices.data.core.XmlElementNames;
030import microsoft.exchange.webservices.data.core.enumeration.availability.MeetingAttendeeType;
031import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
032
033/**
034 * Represents information about an attendee for which to request availability
035 * information.
036 */
037public final class AttendeeInfo implements ISelfValidate {
038
039  /**
040   * The smtp address.
041   */
042  private String smtpAddress;
043
044  /**
045   * The attendee type.
046   */
047  private MeetingAttendeeType attendeeType = MeetingAttendeeType.Required;
048
049  /**
050   * The exclude conflicts.
051   */
052  private boolean excludeConflicts;
053
054  /**
055   * Initializes a new instance of the AttendeeInfo class.
056   */
057  public AttendeeInfo() {
058  }
059
060  /**
061   * Initializes a new instance of the AttendeeInfo class.
062   *
063   * @param smtpAddress      the smtp address
064   * @param attendeeType     the attendee type
065   * @param excludeConflicts the exclude conflicts
066   */
067  public AttendeeInfo(String smtpAddress, MeetingAttendeeType attendeeType,
068      boolean excludeConflicts) {
069    this();
070    this.smtpAddress = smtpAddress;
071    this.attendeeType = attendeeType;
072    this.excludeConflicts = excludeConflicts;
073  }
074
075  /**
076   * Initializes a new instance of the AttendeeInfo class.
077   *
078   * @param smtpAddress the smtp address
079   */
080  public AttendeeInfo(String smtpAddress) {
081    this(smtpAddress, MeetingAttendeeType.Required, false);
082    this.smtpAddress = smtpAddress;
083  }
084
085  /**
086   * Defines an implicit conversion between a string representing an SMTP
087   * address and AttendeeInfo.
088   *
089   * @param smtpAddress the smtp address
090   * @return An AttendeeInfo initialized with the specified SMTP address.
091   */
092  public static AttendeeInfo getAttendeeInfoFromString(String smtpAddress) {
093    return new AttendeeInfo(smtpAddress);
094  }
095
096  /**
097   * Writes to XML.
098   *
099   * @param writer the writer
100   * @throws Exception the exception
101   */
102  public void writeToXml(EwsServiceXmlWriter writer) throws Exception {
103    writer.writeStartElement(XmlNamespace.Types,
104        XmlElementNames.MailboxData);
105
106    writer.writeStartElement(XmlNamespace.Types, XmlElementNames.Email);
107    writer.writeElementValue(XmlNamespace.Types, XmlElementNames.Address,
108        this.smtpAddress);
109    writer.writeEndElement(); // Email
110
111    writer.writeElementValue(XmlNamespace.Types,
112        XmlElementNames.AttendeeType, this.attendeeType);
113
114    writer.writeElementValue(XmlNamespace.Types,
115        XmlElementNames.ExcludeConflicts, this.excludeConflicts);
116
117    writer.writeEndElement(); // MailboxData
118  }
119
120  /**
121   * Gets the SMTP address of this attendee.
122   *
123   * @return the smtp address
124   */
125  public String getSmtpAddress() {
126    return smtpAddress;
127  }
128
129  /**
130   * Sets the smtp address.
131   *
132   * @param smtpAddress the new smtp address
133   */
134  public void setSmtpAddress(String smtpAddress) {
135    this.smtpAddress = smtpAddress;
136  }
137
138  /**
139   * Gets the type of this attendee.
140   *
141   * @return the attendee type
142   */
143  public MeetingAttendeeType getAttendeeType() {
144    return attendeeType;
145  }
146
147  /**
148   * Sets the attendee type.
149   *
150   * @param attendeeType the new attendee type
151   */
152  public void setAttendeeType(MeetingAttendeeType attendeeType) {
153    this.attendeeType = attendeeType;
154  }
155
156  /**
157   * Gets a value indicating whether times when this attendee is not
158   * available should be returned.
159   *
160   * @return true, if is exclude conflicts
161   */
162  public boolean isExcludeConflicts() {
163    return excludeConflicts;
164  }
165
166  /**
167   * Sets the exclude conflicts.
168   *
169   * @param excludeConflicts the new exclude conflicts
170   */
171  public void setExcludeConflicts(boolean excludeConflicts) {
172    this.excludeConflicts = excludeConflicts;
173  }
174
175  /**
176   * Validates this instance.
177   *
178   * @throws Exception the exception
179   */
180  public void validate() throws Exception {
181    EwsUtilities.validateParam(this.smtpAddress, "SmtpAddress");
182  }
183}