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