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.definition;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
027    import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
028    import microsoft.exchange.webservices.data.core.PropertyBag;
029    import microsoft.exchange.webservices.data.core.XmlElementNames;
030    import microsoft.exchange.webservices.data.core.enumeration.service.EffectiveRights;
031    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
032    import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags;
033    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
034    
035    import java.util.EnumSet;
036    
037    /**
038     * Represents effective rights property definition.
039     */
040    public final class EffectiveRightsPropertyDefinition extends PropertyDefinition {
041    
042      /**
043       * Initializes a new instance of the EffectiveRightsPropertyDefinition.
044       *
045       * @param xmlElementName the xml element name
046       * @param uri            the uri
047       * @param flags          the flags
048       * @param version        the version
049       */
050      public EffectiveRightsPropertyDefinition(String xmlElementName, String uri,
051          EnumSet<PropertyDefinitionFlags> flags, ExchangeVersion version) {
052        super(xmlElementName, uri, flags, version);
053    
054      }
055    
056      /**
057       * Loads from XML.
058       *
059       * @param reader      the reader
060       * @param propertyBag the property bag
061       * @throws Exception the exception
062       */
063      public void loadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag) throws Exception {
064        EnumSet<EffectiveRights> value = EnumSet.noneOf(EffectiveRights.class);
065        value.add(EffectiveRights.None);
066    
067        reader.ensureCurrentNodeIsStartElement(XmlNamespace.Types, this
068            .getXmlElement());
069    
070        if (!reader.isEmptyElement()) {
071          do {
072            reader.read();
073    
074            if (reader.isStartElement()) {
075    
076              if (reader.getLocalName().equals(
077                  XmlElementNames.CreateAssociated)) {
078    
079                if (reader.readElementValue(Boolean.class)) {
080                  value.add(EffectiveRights.CreateAssociated);
081                }
082              } else if (reader.getLocalName().equals(
083                  XmlElementNames.CreateContents)) {
084    
085                if (reader.readElementValue(Boolean.class)) {
086                  value.add(EffectiveRights.CreateContents);
087                }
088              } else if (reader.getLocalName().equals(
089                  XmlElementNames.CreateHierarchy)) {
090    
091                if (reader.readElementValue(Boolean.class)) {
092                  value.add(EffectiveRights.CreateHierarchy);
093                }
094              } else if (reader.getLocalName().equals(
095                  XmlElementNames.Delete)) {
096    
097                if (reader.readElementValue(Boolean.class)) {
098                  value.add(EffectiveRights.Delete);
099                }
100              } else if (reader.getLocalName().equals(
101                  XmlElementNames.Modify)) {
102    
103                if (reader.readElementValue(Boolean.class)) {
104                  value.add(EffectiveRights.Modify);
105                }
106              } else if (reader.getLocalName().equals(XmlElementNames.Read)) {
107                if (reader.readElementValue(Boolean.class)) {
108                  value.add(EffectiveRights.Read);
109                } else if (reader.getLocalName().equals(XmlElementNames.ViewPrivateItems)) {
110                  if (reader.readElementValue(Boolean.class)) {
111                    value.add(EffectiveRights.ViewPrivateItems);
112                  }
113                }
114    
115              }
116            }
117    
118          } while (!reader.isEndElement(XmlNamespace.Types, this
119              .getXmlElement()));
120        }
121        propertyBag.setObjectFromPropertyDefinition(this, value);
122      }
123    
124      /**
125       * Writes to XML.
126       *
127       * @param writer            the writer
128       * @param propertyBag       the property bag
129       * @param isUpdateOperation the is update operation
130       */
131      public void writePropertyValueToXml(EwsServiceXmlWriter writer, PropertyBag propertyBag,
132          boolean isUpdateOperation) {
133        // EffectiveRights is a read-only property, no need to implement this.
134      }
135    
136      /**
137       * Gets the property type.
138       */
139      @Override
140      public Class<EffectiveRights> getType() {
141        return EffectiveRights.class;
142      }
143    }