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 024package microsoft.exchange.webservices.data.property.definition; 025 026import microsoft.exchange.webservices.data.core.EwsServiceXmlReader; 027import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter; 028import microsoft.exchange.webservices.data.core.PropertyBag; 029import microsoft.exchange.webservices.data.core.service.schema.ServiceObjectSchema; 030import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion; 031import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags; 032 033import java.util.ArrayList; 034import java.util.EnumSet; 035import java.util.List; 036 037/** 038 * Represents the definition of a folder or item property. 039 */ 040public abstract class PropertyDefinition extends 041 ServiceObjectPropertyDefinition { 042 043 /** 044 * The xml element name. 045 */ 046 private String xmlElementName; 047 048 /** 049 * The flags. 050 */ 051 private EnumSet<PropertyDefinitionFlags> flags; 052 053 /** 054 * The name. 055 */ 056 private String name; 057 058 /** 059 * The version. 060 */ 061 private ExchangeVersion version; 062 063 /** 064 * Initializes a new instance. 065 * 066 * @param xmlElementName Name of the XML element. 067 * @param uri The URI. 068 * @param version The version. 069 */ 070 protected PropertyDefinition(String xmlElementName, String uri, 071 ExchangeVersion version) { 072 super(uri); 073 this.xmlElementName = xmlElementName; 074 this.flags = EnumSet.of(PropertyDefinitionFlags.None); 075 this.version = version; 076 } 077 078 /** 079 * Initializes a new instance. 080 * 081 * @param xmlElementName Name of the XML element. 082 * @param flags The flags. 083 * @param version The version. 084 */ 085 protected PropertyDefinition(String xmlElementName, 086 EnumSet<PropertyDefinitionFlags> flags, ExchangeVersion version) { 087 super(); 088 this.xmlElementName = xmlElementName; 089 this.flags = flags; 090 this.version = version; 091 } 092 093 /** 094 * Initializes a new instance. 095 * 096 * @param xmlElementName Name of the XML element. 097 * @param uri The URI. 098 * @param flags The flags. 099 * @param version The version. 100 */ 101 protected PropertyDefinition(String xmlElementName, String uri, 102 EnumSet<PropertyDefinitionFlags> flags, ExchangeVersion version) { 103 this(xmlElementName, uri, version); 104 this.flags = flags; 105 } 106 107 /** 108 * Determines whether the specified flag is set. 109 * 110 * @param flag The flag. 111 * @return true if the specified flag is set; otherwise, false. 112 */ 113 public boolean hasFlag(PropertyDefinitionFlags flag) { 114 return this.hasFlag(flag, null); 115 } 116 117 /** 118 * Determines whether the specified flag is set. 119 * 120 * @param flag The flag. 121 * @return true if the specified flag is set; otherwise, false. 122 */ 123 public boolean hasFlag(PropertyDefinitionFlags flag, ExchangeVersion version) { 124 return this.flags.contains(flag); 125 } 126 127 /** 128 * Registers associated internal property. 129 * 130 * @param properties The list in which to add the associated property. 131 */ 132 protected void registerAssociatedInternalProperties( 133 List<PropertyDefinition> properties) { 134 } 135 136 /** 137 * Gets a list of associated internal property. 138 * 139 * @return A list of PropertyDefinition objects. This is a hack. It is here 140 * (currently) solely to help the API register the MeetingTimeZone 141 * property definition that is internal. 142 */ 143 public List<PropertyDefinition> getAssociatedInternalProperties() { 144 List<PropertyDefinition> properties = new 145 ArrayList<PropertyDefinition>(); 146 this.registerAssociatedInternalProperties(properties); 147 return properties; 148 } 149 150 /** 151 * Gets the minimum Exchange version that supports this property. 152 * 153 * @return The version. 154 */ 155 public ExchangeVersion getVersion() { 156 return version; 157 } 158 159 /** 160 * Gets a value indicating whether this property definition is for a 161 * nullable type. 162 * 163 * @return always true 164 */ 165 public boolean isNullable() { 166 return true; 167 } 168 169 /** 170 * Loads from XML. 171 * 172 * @param reader The reader. 173 * @param propertyBag The property bag. 174 * @throws Exception the exception 175 */ 176 public abstract void loadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag) 177 throws Exception; 178 179 /** 180 * Writes the property value to XML. 181 * 182 * @param writer the writer 183 * @param propertyBag the property bag 184 * @param isUpdateOperation indicates whether the context is an update operation 185 * @throws Exception the exception 186 */ 187 public abstract void writePropertyValueToXml(EwsServiceXmlWriter writer, PropertyBag propertyBag, 188 boolean isUpdateOperation) throws Exception; 189 190 /** 191 * Gets the name of the XML element. 192 * 193 * @return The name of the XML element. 194 */ 195 public String getXmlElement() { 196 return this.xmlElementName; 197 } 198 199 /** 200 * Gets the name of the property. 201 * 202 * @return Name of the property. 203 */ 204 public String getName() { 205 206 if (null == this.name || this.name.isEmpty()) { 207 ServiceObjectSchema.initializeSchemaPropertyNames(); 208 } 209 return name; 210 } 211 212 /** 213 * Sets the name of the property. 214 * 215 * @param name name of the property 216 */ 217 public void setName(String name) { 218 this.name = name; 219 } 220 221 /** 222 * Gets the property definition's printable name. 223 * 224 * @return The property definition's printable name. 225 */ 226 @Override public String getPrintableName() { 227 return this.getName(); 228 } 229}