001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014 ForgeRock AS
026 */
027package org.opends.server.backends.task;
028
029import org.forgerock.i18n.LocalizableMessage;
030import static org.opends.messages.TaskMessages.*;
031
032
033/**
034 * This enumeration defines the various ways that a task can behave if it is
035 * dependent upon another task and that earlier task is done running but did not
036 * complete successfully.
037 */
038public enum FailedDependencyAction
039{
040  /**
041   * The action that indicates that the dependent task should be processed
042   * anyway.
043   */
044  PROCESS(INFO_FAILED_DEPENDENCY_ACTION_PROCESS.get()),
045
046
047
048  /**
049   * The action that indicates that the dependent task should be canceled.
050   */
051  CANCEL(INFO_FAILED_DEPENDENCY_ACTION_CANCEL.get()),
052
053
054
055  /**
056   * The action that indicates that the dependent task should be disabled so
057   * that an administrator will have to re-enable it before it can start.
058   */
059  DISABLE(INFO_FAILED_DEPENDENCY_ACTION_DISABLE.get());
060
061
062  /**
063   * Returns the default action.
064   *
065   * @return the default action
066   */
067  public static FailedDependencyAction defaultValue() {
068    return CANCEL;
069  }
070
071  /**
072   * Retrieves the failed dependency action that corresponds to the provided
073   * string value.
074   *
075   * @param  s  The string value for which to retrieve the corresponding
076   *            failed dependency action.
077   *
078   * @return  The corresponding failed dependency action, or <CODE>null</CODE>
079   *          if none could be associated with the provided string.
080   */
081  public static FailedDependencyAction fromString(String s)
082  {
083    String lowerString = s.toLowerCase();
084    if (lowerString.equals("process") ||
085            lowerString.equals(INFO_FAILED_DEPENDENCY_ACTION_PROCESS.get().
086                    toString().toLowerCase()))
087    {
088      return PROCESS;
089    }
090    else if (lowerString.equals("cancel") ||
091            lowerString.equals(INFO_FAILED_DEPENDENCY_ACTION_CANCEL.get().
092                    toString().toLowerCase()))
093    {
094      return CANCEL;
095    }
096    else if (lowerString.equals("disable") ||
097            lowerString.equals(INFO_FAILED_DEPENDENCY_ACTION_DISABLE.get().
098                    toString().toLowerCase()))
099    {
100      return DISABLE;
101    }
102    else
103    {
104      return null;
105    }
106  }
107
108  private LocalizableMessage name;
109
110  /**
111   * Gets the display name of this action.
112   *
113   * @return LocalizableMessage representing the name of this action
114   */
115  public LocalizableMessage getDisplayName() {
116    return name;
117  }
118
119  private FailedDependencyAction(LocalizableMessage name) {
120    this.name = name;
121  }
122}
123