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.property.complex.availability; 025 026import microsoft.exchange.webservices.data.core.EwsServiceXmlReader; 027import microsoft.exchange.webservices.data.core.XmlElementNames; 028import microsoft.exchange.webservices.data.core.enumeration.availability.SuggestionQuality; 029import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace; 030import microsoft.exchange.webservices.data.property.complex.ComplexProperty; 031 032import java.text.SimpleDateFormat; 033import java.util.ArrayList; 034import java.util.Collection; 035import java.util.Date; 036 037/** 038 * Represents a suggestion for a specific date. 039 */ 040public final class Suggestion extends ComplexProperty { 041 042 /** 043 * The date. 044 */ 045 private Date date; 046 047 /** 048 * The quality. 049 */ 050 private SuggestionQuality quality; 051 052 /** 053 * The time suggestions. 054 */ 055 private Collection<TimeSuggestion> timeSuggestions = 056 new ArrayList<TimeSuggestion>(); 057 058 /** 059 * Initializes a new instance of the Suggestion class. 060 */ 061 public Suggestion() { 062 super(); 063 } 064 065 /** 066 * Tries to read element from XML. 067 * 068 * @param reader the reader 069 * @return True if appropriate element was read. 070 * @throws Exception the exception 071 */ 072 @Override 073 public boolean tryReadElementFromXml(EwsServiceXmlReader reader) throws Exception { 074 if (reader.getLocalName().equals(XmlElementNames.Date)) { 075 SimpleDateFormat sdfin = new SimpleDateFormat( 076 "yyyy-MM-dd'T'HH:mm:ss"); 077 this.date = sdfin.parse(reader.readElementValue()); 078 return true; 079 } else if (reader.getLocalName().equals(XmlElementNames.DayQuality)) { 080 this.quality = reader.readElementValue(SuggestionQuality.class); 081 return true; 082 } else if (reader.getLocalName() 083 .equals(XmlElementNames.SuggestionArray)) { 084 if (!reader.isEmptyElement()) { 085 do { 086 reader.read(); 087 088 if (reader.isStartElement(XmlNamespace.Types, 089 XmlElementNames.Suggestion)) { 090 TimeSuggestion timeSuggestion = new TimeSuggestion(); 091 092 timeSuggestion.loadFromXml(reader, reader 093 .getLocalName()); 094 095 this.timeSuggestions.add(timeSuggestion); 096 } 097 } while (!reader.isEndElement(XmlNamespace.Types, 098 XmlElementNames.SuggestionArray)); 099 } 100 101 return true; 102 } else { 103 return false; 104 } 105 106 } 107 108 /** 109 * Gets the date and time of the suggestion. 110 * 111 * @return the date 112 */ 113 public Date getDate() { 114 return date; 115 } 116 117 /** 118 * Gets the quality of the suggestion. 119 * 120 * @return the quality 121 */ 122 public SuggestionQuality getQuality() { 123 return quality; 124 } 125 126 /** 127 * Gets a collection of suggested times within the suggested day. 128 * 129 * @return the time suggestions 130 */ 131 public Collection<TimeSuggestion> getTimeSuggestions() { 132 return timeSuggestions; 133 } 134 135}