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.attribute.EditorBrowsable;
027    import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
028    import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
029    import microsoft.exchange.webservices.data.core.XmlAttributeNames;
030    import microsoft.exchange.webservices.data.core.service.ServiceObject;
031    import microsoft.exchange.webservices.data.core.enumeration.attribute.EditorBrowsableState;
032    import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
033    
034    import javax.xml.stream.XMLStreamException;
035    
036    /**
037     * Represents an entry of a DictionaryProperty object.
038     * <p/>
039     * All descendants of DictionaryEntryProperty must implement a parameterless
040     * constructor. That constructor does not have to be public. That constructor
041     * does not have to be public.
042     *
043     * @param <TKey> the generic type
044     */
045    @EditorBrowsable(state = EditorBrowsableState.Never)
046    public abstract class DictionaryEntryProperty<TKey> extends ComplexProperty {
047    
048      /**
049       * The key.
050       */
051      private TKey key;
052      private Class<TKey> instance;
053    
054      /**
055       * Initializes a new instance of the "DictionaryEntryProperty&lt;TKey&gt;"
056       * class.
057       */
058      protected DictionaryEntryProperty(Class<TKey> cls) {
059        this.instance = cls;
060      }
061    
062      /**
063       * Initializes a new instance of the "DictionaryEntryProperty&lt;TKey&gt;"
064       * class.
065       *
066       * @param key The key.
067       */
068      protected DictionaryEntryProperty(Class<TKey> cls, TKey key) {
069        super();
070        this.key = key;
071        this.instance = cls;
072      }
073    
074      /**
075       * Gets the key.
076       *
077       * @return the key
078       */
079      protected TKey getKey() {
080        return key;
081      }
082    
083      /**
084       * Sets the key.
085       *
086       * @param value the value to set
087       */
088      protected void setKey(TKey value) {
089        this.key = value;
090      }
091    
092      /**
093       * Reads the attribute from XML.
094       *
095       * @param reader accepts EwsServiceXmlReader
096       * @throws Exception throws Exception
097       */
098      @Override
099      public void readAttributesFromXml(EwsServiceXmlReader reader)
100          throws Exception {
101        this.key = reader.readAttributeValue(instance,
102            XmlAttributeNames.Key);
103      }
104    
105      /**
106       * Writes the attribute to XML.
107       *
108       * @param writer accepts EwsServiceXmlWriter
109       * @throws ServiceXmlSerializationException throws ServiceXmlSerializationException
110       */
111      @Override
112      public void writeAttributesToXml(EwsServiceXmlWriter writer)
113          throws ServiceXmlSerializationException {
114        writer.writeAttributeValue(XmlAttributeNames.Key, this.getKey());
115      }
116    
117      /**
118       * Writes the set update to XML.
119       *
120       * @param writer                        the writer
121       * @param ewsObject                     the ews object
122       * @param ownerDictionaryXmlElementName name of the owner dictionary XML element
123       * @return true if update XML was written
124       * @throws XMLStreamException the XML stream exception
125       * @throws ServiceXmlSerializationException the service xml serialization exception
126       */
127      protected boolean writeSetUpdateToXml(EwsServiceXmlWriter writer,
128          ServiceObject ewsObject, String ownerDictionaryXmlElementName)
129          throws XMLStreamException, ServiceXmlSerializationException {
130        return false;
131      }
132    
133      /**
134       * Writes the delete update to XML.
135       *
136       * @param writer    the writer
137       * @param ewsObject the ews object
138       * @return true if update XML was written
139       * @throws XMLStreamException the XML stream exception
140       * @throws ServiceXmlSerializationException the service xml serialization exception
141       */
142      protected boolean writeDeleteUpdateToXml(EwsServiceXmlWriter writer,
143          ServiceObject ewsObject) throws XMLStreamException, ServiceXmlSerializationException {
144        return false;
145      }
146    
147    }