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.property.complex;
025
026 import microsoft.exchange.webservices.data.attribute.EditorBrowsable;
027 import microsoft.exchange.webservices.data.core.EwsUtilities;
028 import microsoft.exchange.webservices.data.core.XmlElementNames;
029 import microsoft.exchange.webservices.data.core.enumeration.attribute.EditorBrowsableState;
030
031 /**
032 * Represents a collection of attendees.
033 */
034 @EditorBrowsable(state = EditorBrowsableState.Never)
035 public final class AttendeeCollection extends ComplexPropertyCollection<Attendee> {
036
037 /**
038 * Initializes a new instance of the AttendeeCollection class.
039 */
040 public AttendeeCollection() {
041 super();
042 }
043
044 /**
045 * Adds an attendee to the collection.
046 *
047 * @param attendee the attendee
048 */
049 public void add(Attendee attendee) {
050 this.internalAdd(attendee);
051 }
052
053 /**
054 * Adds an attendee to the collection.
055 *
056 * @param smtpAddress the smtp address
057 * @return An Attendee instance initialized with the provided SMTP address.
058 * @throws Exception the exception
059 */
060 public Attendee add(String smtpAddress) throws Exception {
061 Attendee result = new Attendee(smtpAddress);
062
063 this.internalAdd(result);
064
065 return result;
066 }
067
068 /**
069 * Adds an attendee to the collection.
070 *
071 * @param name the name
072 * @param smtpAddress the smtp address
073 * @return An Attendee instance initialized with the provided name and SMTP
074 * address.
075 */
076 public Attendee add(String name, String smtpAddress) {
077 Attendee result = new Attendee(name, smtpAddress);
078
079 this.internalAdd(result);
080
081 return result;
082 }
083
084 /**
085 * Clears the collection.
086 */
087 public void clear() {
088 this.internalClear();
089 }
090
091 /**
092 * Removes an attendee from the collection.
093 *
094 * @param index the index
095 */
096 public void removeAt(int index) {
097 if (index < 0 || index >= this.getCount()) {
098 throw new IllegalArgumentException("parameter \'index\' : " + "index is out of range.");
099 }
100
101 this.internalRemoveAt(index);
102 }
103
104 /**
105 * Removes an attendee from the collection.
106 *
107 * @param attendee the attendee
108 * @return True if the attendee was successfully removed from the
109 * collection, false otherwise.
110 * @throws Exception the exception
111 */
112 public boolean remove(Attendee attendee) throws Exception {
113 EwsUtilities.validateParam(attendee, "attendee");
114
115 return this.internalRemove(attendee);
116 }
117
118 /**
119 * Creates an Attendee object from an XML element name.
120 *
121 * @param xmlElementName the xml element name
122 * @return An Attendee object.
123 */
124 @Override
125 protected Attendee createComplexProperty(String xmlElementName) {
126 if (xmlElementName.equalsIgnoreCase(XmlElementNames.Attendee)) {
127 return new Attendee();
128 } else {
129 return null;
130 }
131 }
132
133 /**
134 * Retrieves the XML element name corresponding to the provided Attendee
135 * object.
136 *
137 * @param attendee the attendee
138 * @return The XML element name corresponding to the provided Attendee
139 * object.
140 */
141 @Override
142 protected String getCollectionItemXmlElementName(Attendee attendee) {
143 return XmlElementNames.Attendee;
144 }
145 }