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.core.EwsServiceXmlReader;
027 import microsoft.exchange.webservices.data.core.XmlElementNames;
028 import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
029 import microsoft.exchange.webservices.data.core.exception.misc.ArgumentOutOfRangeException;
030
031 import java.util.ArrayList;
032 import java.util.Iterator;
033
034 /**
035 * Represents a collection of rules.
036 */
037 public final class RuleCollection extends ComplexProperty implements Iterable<Rule> {
038
039 /**
040 * The OutlookRuleBlobExists flag.
041 */
042 private boolean outlookRuleBlobExists;
043
044 /**
045 * The rules in the rule collection.
046 */
047 private ArrayList<Rule> rules;
048
049 /**
050 * Initializes a new instance of the RuleCollection class.
051 */
052 public RuleCollection() {
053 super();
054 this.rules = new ArrayList<Rule>();
055 }
056
057 /**
058 * Gets a value indicating whether an Outlook rule blob exists in the user's
059 * mailbox. To update rules with EWS when the Outlook rule blob exists, call
060 * SetInboxRules passing true as the
061 * value of the removeOutlookBlob parameter.
062 */
063 public boolean getOutlookRuleBlobExists() {
064 return this.outlookRuleBlobExists;
065 }
066
067 public void setOutlookRuleBlobExists(boolean value) {
068 this.outlookRuleBlobExists = value;
069 }
070
071 /**
072 * Gets the number of rules in this collection.
073 */
074 public int getCount() {
075 return this.rules.size();
076 }
077
078 /**
079 * Gets the rule at the specified index in the collection.
080 *
081 * @param index The index of the rule to get.
082 * @return The rule at the specified index.
083 * @throws ArgumentOutOfRangeException
084 */
085 public Rule getRule(int index) throws ArgumentOutOfRangeException {
086 if (index < 0 || index >= this.rules.size()) {
087 throw new ArgumentOutOfRangeException("Index");
088 }
089
090 return this.rules.get(index);
091
092 }
093
094
095 /**
096 * Tries to read element from XML.
097 *
098 * @param reader The reader.
099 * @return True if element was read.
100 * @throws Exception
101 */
102 @Override
103 public boolean tryReadElementFromXml(EwsServiceXmlReader reader)
104 throws Exception {
105 if (reader.isStartElement(XmlNamespace.Types, XmlElementNames.Rule)) {
106 Rule rule = new Rule();
107 rule.loadFromXml(reader, XmlElementNames.Rule);
108 this.rules.add(rule);
109 return true;
110 } else {
111 return false;
112 }
113 }
114
115 /**
116 * Get an enumerator for the collection
117 */
118 @Override
119 public Iterator<Rule> iterator() {
120 return this.rules.iterator();
121 }
122
123 }