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