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.service.folder;
025
026 import microsoft.exchange.webservices.data.attribute.ServiceObjectDefinition;
027 import microsoft.exchange.webservices.data.core.ExchangeService;
028 import microsoft.exchange.webservices.data.core.PropertySet;
029 import microsoft.exchange.webservices.data.core.XmlElementNames;
030 import microsoft.exchange.webservices.data.core.service.schema.SearchFolderSchema;
031 import microsoft.exchange.webservices.data.core.service.schema.ServiceObjectSchema;
032 import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
033 import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName;
034 import microsoft.exchange.webservices.data.property.complex.FolderId;
035 import microsoft.exchange.webservices.data.property.complex.SearchFolderParameters;
036
037 /**
038 * Represents a search folder.
039 */
040 @ServiceObjectDefinition(xmlElementName = XmlElementNames.SearchFolder, returnedByServer = true)
041 public class SearchFolder extends Folder {
042
043 /**
044 * Binds to an existing search folder and loads the specified set of
045 * property. Calling this method results in a call to EWS.
046 *
047 * @param service the service
048 * @param id the id
049 * @param propertySet the property set
050 * @return A SearchFolder instance representing the search folder
051 * corresponding to the specified Id.
052 * @throws Exception the exception
053 */
054 public static SearchFolder bind(ExchangeService service, FolderId id,
055 PropertySet propertySet) throws Exception {
056 return service.bindToFolder(SearchFolder.class, id, propertySet);
057 }
058
059 /**
060 * Binds to an existing search folder and loads its first class property.
061 * Calling this method results in a call to EWS.
062 *
063 * @param service the service
064 * @param id the id
065 * @return A SearchFolder instance representing the search folder
066 * corresponding to the specified Id.
067 * @throws Exception the exception
068 */
069 public static SearchFolder bind(ExchangeService service, FolderId id)
070 throws Exception {
071 return SearchFolder.bind(service, id, PropertySet
072 .getFirstClassProperties());
073 }
074
075 /**
076 * Binds to an existing search folder and loads the specified set of
077 * property. Calling this method results in a call to EWS.
078 *
079 * @param service the service
080 * @param name the name
081 * @param propertySet the property set
082 * @return A SearchFolder instance representing the search folder with the
083 * specified name.
084 * @throws Exception the exception
085 */
086 public static SearchFolder bind(ExchangeService service,
087 WellKnownFolderName name, PropertySet propertySet)
088 throws Exception {
089 return SearchFolder.bind(service, new FolderId(name), propertySet);
090 }
091
092 /**
093 * Binds to an existing search folder and loads the specified set of
094 * property. Calling this method results in a call to EWS.
095 *
096 * @param service the service
097 * @param name the name
098 * @return A SearchFolder instance representing the search folder with the
099 * specified name.
100 * @throws Exception the exception
101 */
102 public static SearchFolder bind(ExchangeService service,
103 WellKnownFolderName name) throws Exception {
104 return SearchFolder.bind(service, new FolderId(name), PropertySet
105 .getFirstClassProperties());
106 }
107
108 /**
109 * Initializes an unsaved local instance of the class. To bind to an
110 * existing search folder, use SearchFolder.Bind() instead.
111 *
112 * @param service the service
113 * @throws Exception the exception
114 */
115 public SearchFolder(ExchangeService service) throws Exception {
116 super(service);
117 }
118
119 /**
120 * Internal method to return the schema associated with this type of object.
121 *
122 * @return The schema associated with this type of object.
123 */
124 @Override public ServiceObjectSchema getSchema() {
125 return SearchFolderSchema.Instance;
126 }
127
128 /**
129 * Validates this instance.
130 *
131 * @throws Exception the exception
132 */
133 @Override public void validate() throws Exception {
134 super.validate();
135 if (this.getSearchParameters() != null) {
136 this.getSearchParameters().validate();
137 }
138 }
139
140 /**
141 * Gets the minimum required server version.
142 *
143 * @return Earliest Exchange version in which this service object type is
144 * supported.
145 */
146 @Override public ExchangeVersion getMinimumRequiredServerVersion() {
147 return ExchangeVersion.Exchange2007_SP1;
148 }
149
150 /**
151 * Gets the search parameters associated with the search folder.
152 *
153 * @return the search parameters
154 * @throws Exception the exception
155 */
156 public SearchFolderParameters getSearchParameters() throws Exception {
157 return getPropertyBag().getObjectFromPropertyDefinition(
158 SearchFolderSchema.SearchParameters);
159 }
160
161 }