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.EwsUtilities;
027import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
028import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags;
029import microsoft.exchange.webservices.data.core.enumeration.property.TaskDelegationState;
030
031import java.util.EnumSet;
032
033/**
034 * Represents a task delegation property definition.
035 */
036public final class TaskDelegationStatePropertyDefinition extends
037    GenericPropertyDefinition<TaskDelegationState> {
038  /**
039   * The No match.
040   */
041  private static final String NoMatch = "NoMatch";
042
043  /**
044   * The Own new.
045   */
046  private static final String OwnNew = "OwnNew";
047
048  /**
049   * The Owned.
050   */
051  private static final String Owned = "Owned";
052
053  /**
054   * The Accepted.
055   */
056  private static final String Accepted = "Accepted";
057
058  /**
059   * Initializes a new instance of the "TaskDelegationStatePropertyDefinition"
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 TaskDelegationStatePropertyDefinition(String xmlElementName, String uri,
068      EnumSet<PropertyDefinitionFlags> flags, ExchangeVersion version) {
069    super(TaskDelegationState.class, xmlElementName, uri, flags, version);
070  }
071
072  /**
073   * The Enum Status.
074   */
075  public enum Status {
076
077    /**
078     * The No match.
079     */
080    NoMatch,
081    /**
082     * The Own new.
083     */
084    OwnNew,
085    /**
086     * The Owned.
087     */
088    Owned,
089    /**
090     * The Accepted.
091     */
092    Accepted;
093  }
094
095  /**
096   * Parses the specified value.
097   *
098   * @param value The value.
099   * @return Typed value.
100   */
101  @Override
102  protected TaskDelegationState parse(String value) {
103    switch (Status.valueOf(value)) {
104      case NoMatch:
105        return TaskDelegationState.NoDelegation;
106      case OwnNew:
107        return TaskDelegationState.Unknown;
108      case Owned:
109        return TaskDelegationState.Accepted;
110      case Accepted:
111        return TaskDelegationState.Declined;
112      default:
113        EwsUtilities.ewsAssert(false, "TaskDelegationStatePropertyDefinition.Parse",
114                               String.format("TaskDelegationStatePropertyDefinition." +
115                                             "Parse():" +
116                                             " value %s cannot be handled.", value));
117
118        return null; // To keep the compiler happy
119    }
120  }
121
122  /**
123   * Convert instance to string.
124   *
125   * @param value The value.
126   * @return String representation of property value.
127   */
128  @Override
129  protected String toString(TaskDelegationState value) {
130    if (value.equals(TaskDelegationState.NoDelegation)) {
131      return NoMatch;
132    } else if (value.equals(TaskDelegationState.Unknown)) {
133      return OwnNew;
134    } else if (value.equals(TaskDelegationState.Accepted)) {
135      return Owned;
136    }
137    if (value.equals(TaskDelegationState.Declined)) {
138      return Accepted;
139    } else {
140      EwsUtilities.ewsAssert(false, "TaskDelegationStatePropertyDefinition.ToString",
141                             "Invalid TaskDelegationState value.");
142      return null; // To keep the compiler happy
143    }
144
145  }
146
147}