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.response;
025
026 import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
027 import microsoft.exchange.webservices.data.core.XmlElementNames;
028 import microsoft.exchange.webservices.data.core.enumeration.availability.FreeBusyViewType;
029 import microsoft.exchange.webservices.data.core.enumeration.property.LegacyFreeBusyStatus;
030 import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
031 import microsoft.exchange.webservices.data.property.complex.availability.CalendarEvent;
032 import microsoft.exchange.webservices.data.property.complex.availability.WorkingHours;
033
034 import java.util.ArrayList;
035 import java.util.Collection;
036
037 /**
038 * Represents the availability of an individual attendee.
039 */
040 public final class AttendeeAvailability extends ServiceResponse {
041
042 /**
043 * The calendar events.
044 */
045 private Collection<CalendarEvent> calendarEvents =
046 new ArrayList<CalendarEvent>();
047
048 /**
049 * The merged free busy status.
050 */
051 private Collection<LegacyFreeBusyStatus> mergedFreeBusyStatus =
052 new ArrayList<LegacyFreeBusyStatus>();
053
054 /**
055 * The view type.
056 */
057 private FreeBusyViewType viewType;
058
059 /**
060 * The working hours.
061 */
062 private WorkingHours workingHours;
063
064 /**
065 * Initializes a new instance of the AttendeeAvailability class.
066 */
067 public AttendeeAvailability() {
068 super();
069 }
070
071 /**
072 * Loads the free busy view from XML.
073 *
074 * @param reader the reader
075 * @param viewType the view type
076 * @throws Exception the exception
077 */
078 public void loadFreeBusyViewFromXml(EwsServiceXmlReader reader, FreeBusyViewType viewType) throws Exception {
079 reader.readStartElement(XmlNamespace.Messages,
080 XmlElementNames.FreeBusyView);
081
082 String viewTypeString = reader.readElementValue(XmlNamespace.Types,
083 XmlElementNames.FreeBusyViewType);
084
085 for (Object o : FreeBusyViewType.class.getEnumConstants()) {
086 if (o.toString().equals(viewTypeString)) {
087 this.viewType = (FreeBusyViewType) o;
088 break;
089 }
090 }
091 do {
092 reader.read();
093
094 if (reader.isStartElement()) {
095 if (reader.getLocalName()
096 .equals(XmlElementNames.MergedFreeBusy)) {
097 String mergedFreeBusy = reader.readElementValue();
098
099 for (int i = 0; i < mergedFreeBusy.length(); i++) {
100
101 Byte b = Byte.parseByte(mergedFreeBusy.charAt(i) + "");
102 for (LegacyFreeBusyStatus legacyStatus : LegacyFreeBusyStatus.values()) {
103 if (b == legacyStatus.getBusyStatus()) {
104 this.mergedFreeBusyStatus.add(legacyStatus);
105 break;
106 }
107 }
108
109 }
110
111 } else if (reader.getLocalName().equals(
112 XmlElementNames.CalendarEventArray)) {
113 do {
114 reader.read();
115
116 if (reader.isStartElement(XmlNamespace.Types,
117 XmlElementNames.CalendarEvent)) {
118 CalendarEvent calendarEvent = new CalendarEvent();
119
120 calendarEvent.loadFromXml(reader,
121 XmlElementNames.CalendarEvent);
122
123 this.calendarEvents.add(calendarEvent);
124 }
125 } while (!reader.isEndElement(XmlNamespace.Types,
126 XmlElementNames.CalendarEventArray));
127
128 } else if (reader.getLocalName().equals(
129 XmlElementNames.WorkingHours)) {
130 this.workingHours = new WorkingHours();
131 this.workingHours
132 .loadFromXml(reader, reader.getLocalName());
133
134 break;
135 }
136 }
137 } while (!reader.isEndElement(XmlNamespace.Messages,
138 XmlElementNames.FreeBusyView));
139 }
140
141 /**
142 * Gets a collection of calendar events for the attendee.
143 *
144 * @return the calendar events
145 */
146 public Collection<CalendarEvent> getCalendarEvents() {
147 return this.calendarEvents;
148 }
149
150 /**
151 * Gets a collection of merged free/busy status for the attendee.
152 *
153 * @return the merged free busy status
154 */
155 public Collection<LegacyFreeBusyStatus> getMergedFreeBusyStatus() {
156 return mergedFreeBusyStatus;
157 }
158
159 /**
160 * Gets the free/busy view type that wes retrieved for the attendee.
161 *
162 * @return the view type
163 */
164 public FreeBusyViewType getViewType() {
165 return viewType;
166 }
167
168 /**
169 * Gets the working hours of the attendee.
170 *
171 * @return the working hours
172 */
173 public WorkingHours getWorkingHours() {
174 return workingHours;
175 }
176
177 }