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.opends.server.admin.std.meta; 027 028 029 030import org.opends.server.admin.AdministratorAction; 031import org.opends.server.admin.BooleanPropertyDefinition; 032import org.opends.server.admin.ClassPropertyDefinition; 033import org.opends.server.admin.client.AuthorizationException; 034import org.opends.server.admin.client.CommunicationException; 035import org.opends.server.admin.client.ConcurrentModificationException; 036import org.opends.server.admin.client.ManagedObject; 037import org.opends.server.admin.client.MissingMandatoryPropertiesException; 038import org.opends.server.admin.client.OperationRejectedException; 039import org.opends.server.admin.ManagedObjectAlreadyExistsException; 040import org.opends.server.admin.ManagedObjectDefinition; 041import org.opends.server.admin.PropertyOption; 042import org.opends.server.admin.PropertyProvider; 043import org.opends.server.admin.server.ConfigurationChangeListener; 044import org.opends.server.admin.server.ServerManagedObject; 045import org.opends.server.admin.std.client.AccountStatusNotificationHandlerCfgClient; 046import org.opends.server.admin.std.server.AccountStatusNotificationHandlerCfg; 047import org.opends.server.admin.Tag; 048import org.opends.server.admin.TopCfgDefn; 049import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 050import org.opends.server.types.DN; 051 052 053 054/** 055 * An interface for querying the Account Status Notification Handler 056 * managed object definition meta information. 057 * <p> 058 * Account Status Notification Handlers are invoked to provide 059 * notification to users in some form (for example, by an email 060 * message) when the status of a user's account has changed in some 061 * way. The Account Status Notification Handler can be used to notify 062 * the user and/or administrators of the change. 063 */ 064public final class AccountStatusNotificationHandlerCfgDefn extends ManagedObjectDefinition<AccountStatusNotificationHandlerCfgClient, AccountStatusNotificationHandlerCfg> { 065 066 // The singleton configuration definition instance. 067 private static final AccountStatusNotificationHandlerCfgDefn INSTANCE = new AccountStatusNotificationHandlerCfgDefn(); 068 069 070 071 // The "enabled" property definition. 072 private static final BooleanPropertyDefinition PD_ENABLED; 073 074 075 076 // The "java-class" property definition. 077 private static final ClassPropertyDefinition PD_JAVA_CLASS; 078 079 080 081 // Build the "enabled" property definition. 082 static { 083 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 084 builder.setOption(PropertyOption.MANDATORY); 085 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 086 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 087 PD_ENABLED = builder.getInstance(); 088 INSTANCE.registerPropertyDefinition(PD_ENABLED); 089 } 090 091 092 093 // Build the "java-class" property definition. 094 static { 095 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 096 builder.setOption(PropertyOption.MANDATORY); 097 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 098 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 099 builder.addInstanceOf("org.opends.server.api.AccountStatusNotificationHandler"); 100 PD_JAVA_CLASS = builder.getInstance(); 101 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 102 } 103 104 105 106 // Register the tags associated with this managed object definition. 107 static { 108 INSTANCE.registerTag(Tag.valueOf("user-management")); 109 } 110 111 112 113 /** 114 * Get the Account Status Notification Handler configuration 115 * definition singleton. 116 * 117 * @return Returns the Account Status Notification Handler 118 * configuration definition singleton. 119 */ 120 public static AccountStatusNotificationHandlerCfgDefn getInstance() { 121 return INSTANCE; 122 } 123 124 125 126 /** 127 * Private constructor. 128 */ 129 private AccountStatusNotificationHandlerCfgDefn() { 130 super("account-status-notification-handler", TopCfgDefn.getInstance()); 131 } 132 133 134 135 /** 136 * {@inheritDoc} 137 */ 138 public AccountStatusNotificationHandlerCfgClient createClientConfiguration( 139 ManagedObject<? extends AccountStatusNotificationHandlerCfgClient> impl) { 140 return new AccountStatusNotificationHandlerCfgClientImpl(impl); 141 } 142 143 144 145 /** 146 * {@inheritDoc} 147 */ 148 public AccountStatusNotificationHandlerCfg createServerConfiguration( 149 ServerManagedObject<? extends AccountStatusNotificationHandlerCfg> impl) { 150 return new AccountStatusNotificationHandlerCfgServerImpl(impl); 151 } 152 153 154 155 /** 156 * {@inheritDoc} 157 */ 158 public Class<AccountStatusNotificationHandlerCfg> getServerConfigurationClass() { 159 return AccountStatusNotificationHandlerCfg.class; 160 } 161 162 163 164 /** 165 * Get the "enabled" property definition. 166 * <p> 167 * Indicates whether the Account Status Notification Handler is 168 * enabled. Only enabled handlers are invoked whenever a related 169 * event occurs in the server. 170 * 171 * @return Returns the "enabled" property definition. 172 */ 173 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 174 return PD_ENABLED; 175 } 176 177 178 179 /** 180 * Get the "java-class" property definition. 181 * <p> 182 * Specifies the fully-qualified name of the Java class that 183 * provides the Account Status Notification Handler implementation. 184 * 185 * @return Returns the "java-class" property definition. 186 */ 187 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 188 return PD_JAVA_CLASS; 189 } 190 191 192 193 /** 194 * Managed object client implementation. 195 */ 196 private static class AccountStatusNotificationHandlerCfgClientImpl implements 197 AccountStatusNotificationHandlerCfgClient { 198 199 // Private implementation. 200 private ManagedObject<? extends AccountStatusNotificationHandlerCfgClient> impl; 201 202 203 204 // Private constructor. 205 private AccountStatusNotificationHandlerCfgClientImpl( 206 ManagedObject<? extends AccountStatusNotificationHandlerCfgClient> impl) { 207 this.impl = impl; 208 } 209 210 211 212 /** 213 * {@inheritDoc} 214 */ 215 public Boolean isEnabled() { 216 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 217 } 218 219 220 221 /** 222 * {@inheritDoc} 223 */ 224 public void setEnabled(boolean value) { 225 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 226 } 227 228 229 230 /** 231 * {@inheritDoc} 232 */ 233 public String getJavaClass() { 234 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 235 } 236 237 238 239 /** 240 * {@inheritDoc} 241 */ 242 public void setJavaClass(String value) { 243 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 244 } 245 246 247 248 /** 249 * {@inheritDoc} 250 */ 251 public ManagedObjectDefinition<? extends AccountStatusNotificationHandlerCfgClient, ? extends AccountStatusNotificationHandlerCfg> definition() { 252 return INSTANCE; 253 } 254 255 256 257 /** 258 * {@inheritDoc} 259 */ 260 public PropertyProvider properties() { 261 return impl; 262 } 263 264 265 266 /** 267 * {@inheritDoc} 268 */ 269 public void commit() throws ManagedObjectAlreadyExistsException, 270 MissingMandatoryPropertiesException, ConcurrentModificationException, 271 OperationRejectedException, AuthorizationException, 272 CommunicationException { 273 impl.commit(); 274 } 275 276 277 278 /** {@inheritDoc} */ 279 public String toString() { 280 return impl.toString(); 281 } 282 } 283 284 285 286 /** 287 * Managed object server implementation. 288 */ 289 private static class AccountStatusNotificationHandlerCfgServerImpl implements 290 AccountStatusNotificationHandlerCfg { 291 292 // Private implementation. 293 private ServerManagedObject<? extends AccountStatusNotificationHandlerCfg> impl; 294 295 // The value of the "enabled" property. 296 private final boolean pEnabled; 297 298 // The value of the "java-class" property. 299 private final String pJavaClass; 300 301 302 303 // Private constructor. 304 private AccountStatusNotificationHandlerCfgServerImpl(ServerManagedObject<? extends AccountStatusNotificationHandlerCfg> impl) { 305 this.impl = impl; 306 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 307 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 308 } 309 310 311 312 /** 313 * {@inheritDoc} 314 */ 315 public void addChangeListener( 316 ConfigurationChangeListener<AccountStatusNotificationHandlerCfg> listener) { 317 impl.registerChangeListener(listener); 318 } 319 320 321 322 /** 323 * {@inheritDoc} 324 */ 325 public void removeChangeListener( 326 ConfigurationChangeListener<AccountStatusNotificationHandlerCfg> listener) { 327 impl.deregisterChangeListener(listener); 328 } 329 330 331 332 /** 333 * {@inheritDoc} 334 */ 335 public boolean isEnabled() { 336 return pEnabled; 337 } 338 339 340 341 /** 342 * {@inheritDoc} 343 */ 344 public String getJavaClass() { 345 return pJavaClass; 346 } 347 348 349 350 /** 351 * {@inheritDoc} 352 */ 353 public Class<? extends AccountStatusNotificationHandlerCfg> configurationClass() { 354 return AccountStatusNotificationHandlerCfg.class; 355 } 356 357 358 359 /** 360 * {@inheritDoc} 361 */ 362 public DN dn() { 363 return impl.getDN(); 364 } 365 366 367 368 /** {@inheritDoc} */ 369 public String toString() { 370 return impl.toString(); 371 } 372 } 373}