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 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.admin; 028 import org.opends.messages.Message; 029 030 031 032 import java.util.Locale; 033 import 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 */ 047 public 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 /** 102 * {@inheritDoc} 103 */ 104 @Override 105 public String toString() { 106 return name; 107 } 108 109 } 110 111 // The managed object definition associated with this administrator 112 // action. 113 private final AbstractManagedObjectDefinition<?, ?> definition; 114 115 // The name of the property definition associated with this 116 // administrator action. 117 private final String propertyName; 118 119 // The type of administration action. 120 private final Type type; 121 122 123 124 /** 125 * Create a new administrator action. 126 * 127 * @param type 128 * The type of this administration action. 129 * @param d 130 * The managed object definition associated with this 131 * administrator action. 132 * @param propertyName 133 * The name of the property definition associated with this 134 * administrator action. 135 */ 136 public AdministratorAction(Type type, 137 AbstractManagedObjectDefinition<?, ?> d, String propertyName) { 138 this.type = type; 139 this.definition = d; 140 this.propertyName = propertyName; 141 } 142 143 144 145 /** 146 * Gets the synopsis of this administrator action in the default 147 * locale. 148 * 149 * @return Returns the synopsis of this administrator action in the 150 * default locale, or <code>null</code> if there is no 151 * synopsis defined. 152 */ 153 public final Message getSynopsis() { 154 return getSynopsis(Locale.getDefault()); 155 } 156 157 158 159 /** 160 * Gets the synopsis of this administrator action in the specified 161 * locale. 162 * 163 * @param locale 164 * The locale. 165 * @return Returns the synopsis of this administrator action in the 166 * specified locale, or <code>null</code> if there is no 167 * synopsis defined. 168 */ 169 public final Message getSynopsis(Locale locale) { 170 ManagedObjectDefinitionI18NResource resource = 171 ManagedObjectDefinitionI18NResource.getInstance(); 172 String property = "property." + propertyName 173 + ".requires-admin-action.synopsis"; 174 try { 175 return resource.getMessage(definition, property, locale); 176 } catch (MissingResourceException e) { 177 return null; 178 } 179 } 180 181 182 183 /** 184 * Gets the type of this administrator action. 185 * 186 * @return Returns the type of this administrator action. 187 */ 188 public final Type getType() { 189 return type; 190 } 191 }