001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2015 ForgeRock AS.
016 */
017package org.opends.server.admin;
018import org.forgerock.i18n.LocalizableMessage;
019
020
021
022import java.util.Locale;
023import java.util.MissingResourceException;
024
025
026
027/**
028 * Defines an optional action which administators must perform after
029 * they have modified a property. By default modifications to
030 * properties are assumed to take effect immediately and require no
031 * additional administrative action. Developers should be aware that,
032 * where feasible, they should implement components such that property
033 * modifications require no additional administrative action. This is
034 * required in order to minimize server downtime during administration
035 * and provide a more user-friendly experience.
036 */
037public final class AdministratorAction {
038
039  /**
040   * Specifies the type of administrator action which must be
041   * performed in order for pending changes to take effect.
042   */
043  public static enum Type {
044    /**
045     * Used when modifications to a property require a component
046     * restart in order to take effect (usually by disabling and
047     * re-enabling the component). May have a description describing
048     * any additional administrator action that is required when the
049     * component is restarted.
050     */
051    COMPONENT_RESTART("component-restart"),
052
053    /**
054     * Used when modifications to a property take effect immediately,
055     * and no additional administrator action is required. May have a
056     * description describing how changes to the modified property
057     * will take effect.
058     */
059    NONE("none"),
060
061    /**
062     * Used when modifications to a property require an additional
063     * administrative action in order to take effect. This should be
064     * used when neither a server restart nor a component restart are
065     * applicable. Always has a description which describes the
066     * additional administrator action which is required when the
067     * property is modified.
068     */
069    OTHER("other"),
070
071    /**
072     * Used when modifications to a property require a server restart
073     * in order to take effect. May have a description describing any
074     * additional administrator action that is required when the
075     * component is restarted.
076     */
077    SERVER_RESTART("server-restart");
078
079    /** The user-friendly name of the type. */
080    private final String name;
081
082
083
084    /** Private constructor. */
085    private Type(String name) {
086      this.name = name;
087    }
088
089
090
091    /** {@inheritDoc} */
092    @Override
093    public String toString() {
094      return name;
095    }
096
097  }
098
099  /**
100   * The managed object definition associated with this administrator
101   * action.
102   */
103  private final AbstractManagedObjectDefinition<?, ?> definition;
104
105  /**
106   * The name of the property definition associated with this
107   * administrator action.
108   */
109  private final String propertyName;
110
111  /** The type of administration action. */
112  private final Type type;
113
114
115
116  /**
117   * Create a new administrator action.
118   *
119   * @param type
120   *          The type of this administration action.
121   * @param d
122   *          The managed object definition associated with this
123   *          administrator action.
124   * @param propertyName
125   *          The name of the property definition associated with this
126   *          administrator action.
127   */
128  public AdministratorAction(Type type,
129      AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
130    this.type = type;
131    this.definition = d;
132    this.propertyName = propertyName;
133  }
134
135
136
137  /**
138   * Gets the synopsis of this administrator action in the default
139   * locale.
140   *
141   * @return Returns the synopsis of this administrator action in the
142   *         default locale, or <code>null</code> if there is no
143   *         synopsis defined.
144   */
145  public final LocalizableMessage getSynopsis() {
146    return getSynopsis(Locale.getDefault());
147  }
148
149
150
151  /**
152   * Gets the synopsis of this administrator action in the specified
153   * locale.
154   *
155   * @param locale
156   *          The locale.
157   * @return Returns the synopsis of this administrator action in the
158   *         specified locale, or <code>null</code> if there is no
159   *         synopsis defined.
160   */
161  public final LocalizableMessage getSynopsis(Locale locale) {
162    ManagedObjectDefinitionI18NResource resource =
163      ManagedObjectDefinitionI18NResource.getInstance();
164    String property = "property." + propertyName
165        + ".requires-admin-action.synopsis";
166    try {
167      return resource.getMessage(definition, property, locale);
168    } catch (MissingResourceException e) {
169      return null;
170    }
171  }
172
173
174
175  /**
176   * Gets the type of this administrator action.
177   *
178   * @return Returns the type of this administrator action.
179   */
180  public final Type getType() {
181    return type;
182  }
183}