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.misc.ExchangeVersion;
031    import microsoft.exchange.webservices.data.core.enumeration.service.ResponseActions;
032    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
033    
034    import java.util.EnumSet;
035    
036    /**
037     * Represents response object property defintion.
038     */
039    public class ResponseObjectsPropertyDefinition extends PropertyDefinition {
040    
041      /**
042       * Initializes a new instance of the ResponseObjectsPropertyDefinition
043       * class.
044       *
045       * @param xmlElementName the xml element name
046       * @param uri            the uri
047       * @param version        the version
048       */
049      public ResponseObjectsPropertyDefinition(String xmlElementName, String uri, ExchangeVersion version) {
050        super(xmlElementName, uri, version);
051    
052      }
053    
054      /**
055       * Loads from XML.
056       *
057       * @param reader      the reader
058       * @param propertyBag the property bag
059       * @throws Exception the exception
060       */
061      public final void loadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag) throws Exception {
062        EnumSet<ResponseActions> value = EnumSet.noneOf(ResponseActions.class);
063        value.add(ResponseActions.None);
064    
065        reader.ensureCurrentNodeIsStartElement(XmlNamespace.Types, this
066            .getXmlElement());
067    
068        if (!reader.isEmptyElement()) {
069          do {
070            reader.read();
071    
072            if (reader.isStartElement()) {
073    
074              if (reader.getLocalName()
075                  .equals(XmlElementNames.AcceptItem)) {
076    
077                value.add(ResponseActions.Accept);
078              } else if (reader.getLocalName().equals(
079                  XmlElementNames.TentativelyAcceptItem)) {
080    
081                value.add(ResponseActions.TentativelyAccept);
082              } else if (reader.getLocalName().equals(
083                  XmlElementNames.DeclineItem)) {
084    
085                value.add(ResponseActions.Decline);
086              } else if (reader.getLocalName().equals(
087                  XmlElementNames.ReplyToItem)) {
088    
089                value.add(ResponseActions.Reply);
090              } else if (reader.getLocalName().equals(
091                  XmlElementNames.ForwardItem)) {
092    
093                value.add(ResponseActions.Forward);
094              } else if (reader.getLocalName().equals(
095                  XmlElementNames.ReplyAllToItem)) {
096    
097                value.add(ResponseActions.ReplyAll);
098              } else if (reader.getLocalName().equals(
099                  XmlElementNames.CancelCalendarItem)) {
100    
101                value.add(ResponseActions.Cancel);
102              } else if (reader.getLocalName().equals(
103                  XmlElementNames.RemoveItem)) {
104    
105                value.add(ResponseActions.RemoveFromCalendar);
106              } else if (reader.getLocalName().equals(
107                  XmlElementNames.SuppressReadReceipt)) {
108    
109                value.add(ResponseActions.SuppressReadReceipt);
110              } else if (reader.getLocalName().equals(
111                  XmlElementNames.PostReplyItem)) {
112    
113                value.add(ResponseActions.PostReply);
114              }
115            }
116    
117          } while (!reader.isEndElement(XmlNamespace.Types, this
118              .getXmlElement()));
119        } else {
120          reader.read();
121        }
122    
123        propertyBag.setObjectFromPropertyDefinition(this, value);
124      }
125    
126      /**
127       * Writes to XML.
128       *
129       * @param writer            the writer
130       * @param propertyBag       the property bag
131       * @param isUpdateOperation the is update operation
132       */
133      public void writePropertyValueToXml(EwsServiceXmlWriter writer, PropertyBag propertyBag,
134          boolean isUpdateOperation) {
135        // ResponseObjects is a read-only property, no need to implement this.
136      }
137    
138      /**
139       * Gets a value indicating whether this property
140       * definition is for a nullable type (ref, int?, bool?...).
141       */
142      @Override public boolean isNullable() {
143        return false;
144      }
145    
146      /**
147       * Gets the property type.
148       */
149      @Override
150      public Class<ResponseActions> getType() {
151        return ResponseActions.class;
152      }
153    }