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 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.admin;
028import org.forgerock.i18n.LocalizableMessage;
029
030
031
032import java.util.Locale;
033import java.util.MissingResourceException;
034
035
036
037/**
038 * Defines an optional action which administators must perform after
039 * they have modified a property. By default modifications to
040 * properties are assumed to take effect immediately and require no
041 * additional administrative action. Developers should be aware that,
042 * where feasible, they should implement components such that property
043 * modifications require no additional administrative action. This is
044 * required in order to minimize server downtime during administration
045 * and provide a more user-friendly experience.
046 */
047public final class AdministratorAction {
048
049  /**
050   * Specifies the type of administrator action which must be
051   * performed in order for pending changes to take effect.
052   */
053  public static enum Type {
054    /**
055     * Used when modifications to a property require a component
056     * restart in order to take effect (usually by disabling and
057     * re-enabling the component). May have a description describing
058     * any additional administrator action that is required when the
059     * component is restarted.
060     */
061    COMPONENT_RESTART("component-restart"),
062
063    /**
064     * Used when modifications to a property take effect immediately,
065     * and no additional administrator action is required. May have a
066     * description describing how changes to the modified property
067     * will take effect.
068     */
069    NONE("none"),
070
071    /**
072     * Used when modifications to a property require an additional
073     * administrative action in order to take effect. This should be
074     * used when neither a server restart nor a component restart are
075     * applicable. Always has a description which describes the
076     * additional administrator action which is required when the
077     * property is modified.
078     */
079    OTHER("other"),
080
081    /**
082     * Used when modifications to a property require a server restart
083     * in order to take effect. May have a description describing any
084     * additional administrator action that is required when the
085     * component is restarted.
086     */
087    SERVER_RESTART("server-restart");
088
089    /** The user-friendly name of the type. */
090    private final String name;
091
092
093
094    /** Private constructor. */
095    private Type(String name) {
096      this.name = name;
097    }
098
099
100
101    /** {@inheritDoc} */
102    @Override
103    public String toString() {
104      return name;
105    }
106
107  }
108
109  /**
110   * The managed object definition associated with this administrator
111   * action.
112   */
113  private final AbstractManagedObjectDefinition<?, ?> definition;
114
115  /**
116   * The name of the property definition associated with this
117   * administrator action.
118   */
119  private final String propertyName;
120
121  /** The type of administration action. */
122  private final Type type;
123
124
125
126  /**
127   * Create a new administrator action.
128   *
129   * @param type
130   *          The type of this administration action.
131   * @param d
132   *          The managed object definition associated with this
133   *          administrator action.
134   * @param propertyName
135   *          The name of the property definition associated with this
136   *          administrator action.
137   */
138  public AdministratorAction(Type type,
139      AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
140    this.type = type;
141    this.definition = d;
142    this.propertyName = propertyName;
143  }
144
145
146
147  /**
148   * Gets the synopsis of this administrator action in the default
149   * locale.
150   *
151   * @return Returns the synopsis of this administrator action in the
152   *         default locale, or <code>null</code> if there is no
153   *         synopsis defined.
154   */
155  public final LocalizableMessage getSynopsis() {
156    return getSynopsis(Locale.getDefault());
157  }
158
159
160
161  /**
162   * Gets the synopsis of this administrator action in the specified
163   * locale.
164   *
165   * @param locale
166   *          The locale.
167   * @return Returns the synopsis of this administrator action in the
168   *         specified locale, or <code>null</code> if there is no
169   *         synopsis defined.
170   */
171  public final LocalizableMessage getSynopsis(Locale locale) {
172    ManagedObjectDefinitionI18NResource resource =
173      ManagedObjectDefinitionI18NResource.getInstance();
174    String property = "property." + propertyName
175        + ".requires-admin-action.synopsis";
176    try {
177      return resource.getMessage(definition, property, locale);
178    } catch (MissingResourceException e) {
179      return null;
180    }
181  }
182
183
184
185  /**
186   * Gets the type of this administrator action.
187   *
188   * @return Returns the type of this administrator action.
189   */
190  public final Type getType() {
191    return type;
192  }
193}