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.EwsUtilities;
027 import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
028 import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags;
029
030 import java.io.Serializable;
031 import java.text.ParseException;
032 import java.util.EnumSet;
033
034 /**
035 * Represents generic property definition.
036 *
037 * @param <TPropertyValue> Property type.
038 */
039 public class GenericPropertyDefinition<TPropertyValue extends Serializable> extends
040 TypedPropertyDefinition<TPropertyValue> {
041
042 private Class<TPropertyValue> instance;
043
044 /**
045 * Initializes a new instance of the "GenericPropertyDefinition<T>"
046 * class.
047 *
048 * @param xmlElementName Name of the XML element.
049 * @param uri The URI.
050 * @param version The version.
051 */
052 public GenericPropertyDefinition(Class<TPropertyValue> cls, String xmlElementName, String uri,
053 ExchangeVersion version) {
054 super(xmlElementName, uri, version);
055 this.instance = cls;
056 }
057
058 /**
059 * Initializes a new instance of the "GenericPropertyDefinition<T>"
060 * class.
061 *
062 * @param xmlElementName Name of the XML element.
063 * @param uri The URI.
064 * @param flags The flags.
065 * @param version The version.
066 */
067 public GenericPropertyDefinition(Class<TPropertyValue> cls, String xmlElementName, String uri,
068 EnumSet<PropertyDefinitionFlags> flags, ExchangeVersion version) {
069 super(xmlElementName, uri, flags, version);
070 this.instance = cls;
071 }
072
073 /**
074 * Initializes a new instance of the GenericPropertyDefinition class.
075 *
076 * @param xmlElementName Name of the XML element.
077 * @param uri The URI.
078 * @param flags The flags.
079 * @param version The version.
080 * @param isNullable if set to true, property value is nullable.
081 */
082 protected GenericPropertyDefinition(
083 Class<TPropertyValue> cls,
084 String xmlElementName,
085 String uri,
086 EnumSet<PropertyDefinitionFlags> flags,
087 ExchangeVersion version,
088 boolean isNullable) {
089 super(xmlElementName, uri, flags, version, isNullable);
090 this.instance = cls;
091 }
092
093
094 /**
095 * Parses the specified value.
096 *
097 * @param value The value
098 * @return Double value from parsed value.
099 * @throws java.text.ParseException
100 * @throws IllegalAccessException
101 * @throws InstantiationException
102 */
103 @Override
104 protected TPropertyValue parse(String value) throws InstantiationException,
105 IllegalAccessException, ParseException {
106
107 return EwsUtilities.parse(instance, value);
108 }
109
110 /**
111 * Gets the property type.
112 */
113 @Override
114 public Class<TPropertyValue> getType() {
115 return instance;
116 }
117 }