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 java.util.Collection; 031import java.util.SortedSet; 032import org.forgerock.opendj.config.AdministratorAction; 033import org.forgerock.opendj.config.AliasDefaultBehaviorProvider; 034import org.forgerock.opendj.config.BooleanPropertyDefinition; 035import org.forgerock.opendj.config.ClassPropertyDefinition; 036import org.forgerock.opendj.config.client.ConcurrentModificationException; 037import org.forgerock.opendj.config.client.ManagedObject; 038import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 039import org.forgerock.opendj.config.client.OperationRejectedException; 040import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 041import org.forgerock.opendj.config.ManagedObjectDefinition; 042import org.forgerock.opendj.config.PropertyOption; 043import org.forgerock.opendj.config.PropertyProvider; 044import org.forgerock.opendj.config.server.ConfigurationChangeListener; 045import org.forgerock.opendj.config.server.ServerManagedObject; 046import org.forgerock.opendj.config.StringPropertyDefinition; 047import org.forgerock.opendj.config.Tag; 048import org.forgerock.opendj.config.TopCfgDefn; 049import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 050import org.forgerock.opendj.ldap.DN; 051import org.forgerock.opendj.ldap.LdapException; 052import org.forgerock.opendj.server.config.client.AlertHandlerCfgClient; 053import org.forgerock.opendj.server.config.server.AlertHandlerCfg; 054 055 056 057/** 058 * An interface for querying the Alert Handler managed object 059 * definition meta information. 060 * <p> 061 * Alert Handlers are used to notify administrators of significant 062 * problems or notable events that occur in the OpenDJ directory 063 * server. 064 */ 065public final class AlertHandlerCfgDefn extends ManagedObjectDefinition<AlertHandlerCfgClient, AlertHandlerCfg> { 066 067 // The singleton configuration definition instance. 068 private static final AlertHandlerCfgDefn INSTANCE = new AlertHandlerCfgDefn(); 069 070 071 072 // The "disabled-alert-type" property definition. 073 private static final StringPropertyDefinition PD_DISABLED_ALERT_TYPE; 074 075 076 077 // The "enabled" property definition. 078 private static final BooleanPropertyDefinition PD_ENABLED; 079 080 081 082 // The "enabled-alert-type" property definition. 083 private static final StringPropertyDefinition PD_ENABLED_ALERT_TYPE; 084 085 086 087 // The "java-class" property definition. 088 private static final ClassPropertyDefinition PD_JAVA_CLASS; 089 090 091 092 // Build the "disabled-alert-type" property definition. 093 static { 094 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "disabled-alert-type"); 095 builder.setOption(PropertyOption.MULTI_VALUED); 096 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "disabled-alert-type")); 097 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "disabled-alert-type")); 098 PD_DISABLED_ALERT_TYPE = builder.getInstance(); 099 INSTANCE.registerPropertyDefinition(PD_DISABLED_ALERT_TYPE); 100 } 101 102 103 104 // Build the "enabled" property definition. 105 static { 106 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 107 builder.setOption(PropertyOption.MANDATORY); 108 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 109 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 110 PD_ENABLED = builder.getInstance(); 111 INSTANCE.registerPropertyDefinition(PD_ENABLED); 112 } 113 114 115 116 // Build the "enabled-alert-type" property definition. 117 static { 118 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "enabled-alert-type"); 119 builder.setOption(PropertyOption.MULTI_VALUED); 120 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled-alert-type")); 121 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "enabled-alert-type")); 122 PD_ENABLED_ALERT_TYPE = builder.getInstance(); 123 INSTANCE.registerPropertyDefinition(PD_ENABLED_ALERT_TYPE); 124 } 125 126 127 128 // Build the "java-class" property definition. 129 static { 130 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 131 builder.setOption(PropertyOption.MANDATORY); 132 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 133 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 134 builder.addInstanceOf("org.opends.server.api.AlertHandler"); 135 PD_JAVA_CLASS = builder.getInstance(); 136 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 137 } 138 139 140 141 // Register the tags associated with this managed object definition. 142 static { 143 INSTANCE.registerTag(Tag.valueOf("core-server")); 144 } 145 146 147 148 /** 149 * Get the Alert Handler configuration definition singleton. 150 * 151 * @return Returns the Alert Handler configuration definition 152 * singleton. 153 */ 154 public static AlertHandlerCfgDefn getInstance() { 155 return INSTANCE; 156 } 157 158 159 160 /** 161 * Private constructor. 162 */ 163 private AlertHandlerCfgDefn() { 164 super("alert-handler", TopCfgDefn.getInstance()); 165 } 166 167 168 169 /** 170 * {@inheritDoc} 171 */ 172 public AlertHandlerCfgClient createClientConfiguration( 173 ManagedObject<? extends AlertHandlerCfgClient> impl) { 174 return new AlertHandlerCfgClientImpl(impl); 175 } 176 177 178 179 /** 180 * {@inheritDoc} 181 */ 182 public AlertHandlerCfg createServerConfiguration( 183 ServerManagedObject<? extends AlertHandlerCfg> impl) { 184 return new AlertHandlerCfgServerImpl(impl); 185 } 186 187 188 189 /** 190 * {@inheritDoc} 191 */ 192 public Class<AlertHandlerCfg> getServerConfigurationClass() { 193 return AlertHandlerCfg.class; 194 } 195 196 197 198 /** 199 * Get the "disabled-alert-type" property definition. 200 * <p> 201 * Specifies the names of the alert types that are disabled for this 202 * alert handler. 203 * <p> 204 * If there are any values for this attribute, then no alerts with 205 * any of the specified types are allowed. If there are no values for 206 * this attribute, then only alerts with a type included in the set 207 * of enabled alert types are allowed, or if there are no values for 208 * the enabled alert types option, then all alert types are allowed. 209 * 210 * @return Returns the "disabled-alert-type" property definition. 211 */ 212 public StringPropertyDefinition getDisabledAlertTypePropertyDefinition() { 213 return PD_DISABLED_ALERT_TYPE; 214 } 215 216 217 218 /** 219 * Get the "enabled" property definition. 220 * <p> 221 * Indicates whether the Alert Handler is enabled. 222 * 223 * @return Returns the "enabled" property definition. 224 */ 225 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 226 return PD_ENABLED; 227 } 228 229 230 231 /** 232 * Get the "enabled-alert-type" property definition. 233 * <p> 234 * Specifies the names of the alert types that are enabled for this 235 * alert handler. 236 * <p> 237 * If there are any values for this attribute, then only alerts with 238 * one of the specified types are allowed (unless they are also 239 * included in the disabled alert types). If there are no values for 240 * this attribute, then any alert with a type not included in the 241 * list of disabled alert types is allowed. 242 * 243 * @return Returns the "enabled-alert-type" property definition. 244 */ 245 public StringPropertyDefinition getEnabledAlertTypePropertyDefinition() { 246 return PD_ENABLED_ALERT_TYPE; 247 } 248 249 250 251 /** 252 * Get the "java-class" property definition. 253 * <p> 254 * Specifies the fully-qualified name of the Java class that 255 * provides the Alert Handler implementation. 256 * 257 * @return Returns the "java-class" property definition. 258 */ 259 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 260 return PD_JAVA_CLASS; 261 } 262 263 264 265 /** 266 * Managed object client implementation. 267 */ 268 private static class AlertHandlerCfgClientImpl implements 269 AlertHandlerCfgClient { 270 271 // Private implementation. 272 private ManagedObject<? extends AlertHandlerCfgClient> impl; 273 274 275 276 // Private constructor. 277 private AlertHandlerCfgClientImpl( 278 ManagedObject<? extends AlertHandlerCfgClient> impl) { 279 this.impl = impl; 280 } 281 282 283 284 /** 285 * {@inheritDoc} 286 */ 287 public SortedSet<String> getDisabledAlertType() { 288 return impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition()); 289 } 290 291 292 293 /** 294 * {@inheritDoc} 295 */ 296 public void setDisabledAlertType(Collection<String> values) { 297 impl.setPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition(), values); 298 } 299 300 301 302 /** 303 * {@inheritDoc} 304 */ 305 public Boolean isEnabled() { 306 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 307 } 308 309 310 311 /** 312 * {@inheritDoc} 313 */ 314 public void setEnabled(boolean value) { 315 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 316 } 317 318 319 320 /** 321 * {@inheritDoc} 322 */ 323 public SortedSet<String> getEnabledAlertType() { 324 return impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition()); 325 } 326 327 328 329 /** 330 * {@inheritDoc} 331 */ 332 public void setEnabledAlertType(Collection<String> values) { 333 impl.setPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition(), values); 334 } 335 336 337 338 /** 339 * {@inheritDoc} 340 */ 341 public String getJavaClass() { 342 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 343 } 344 345 346 347 /** 348 * {@inheritDoc} 349 */ 350 public void setJavaClass(String value) { 351 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 352 } 353 354 355 356 /** 357 * {@inheritDoc} 358 */ 359 public ManagedObjectDefinition<? extends AlertHandlerCfgClient, ? extends AlertHandlerCfg> definition() { 360 return INSTANCE; 361 } 362 363 364 365 /** 366 * {@inheritDoc} 367 */ 368 public PropertyProvider properties() { 369 return impl; 370 } 371 372 373 374 /** 375 * {@inheritDoc} 376 */ 377 public void commit() throws ManagedObjectAlreadyExistsException, 378 MissingMandatoryPropertiesException, ConcurrentModificationException, 379 OperationRejectedException, LdapException { 380 impl.commit(); 381 } 382 383 } 384 385 386 387 /** 388 * Managed object server implementation. 389 */ 390 private static class AlertHandlerCfgServerImpl implements 391 AlertHandlerCfg { 392 393 // Private implementation. 394 private ServerManagedObject<? extends AlertHandlerCfg> impl; 395 396 // The value of the "disabled-alert-type" property. 397 private final SortedSet<String> pDisabledAlertType; 398 399 // The value of the "enabled" property. 400 private final boolean pEnabled; 401 402 // The value of the "enabled-alert-type" property. 403 private final SortedSet<String> pEnabledAlertType; 404 405 // The value of the "java-class" property. 406 private final String pJavaClass; 407 408 409 410 // Private constructor. 411 private AlertHandlerCfgServerImpl(ServerManagedObject<? extends AlertHandlerCfg> impl) { 412 this.impl = impl; 413 this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition()); 414 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 415 this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition()); 416 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 417 } 418 419 420 421 /** 422 * {@inheritDoc} 423 */ 424 public void addChangeListener( 425 ConfigurationChangeListener<AlertHandlerCfg> listener) { 426 impl.registerChangeListener(listener); 427 } 428 429 430 431 /** 432 * {@inheritDoc} 433 */ 434 public void removeChangeListener( 435 ConfigurationChangeListener<AlertHandlerCfg> listener) { 436 impl.deregisterChangeListener(listener); 437 } 438 439 440 441 /** 442 * {@inheritDoc} 443 */ 444 public SortedSet<String> getDisabledAlertType() { 445 return pDisabledAlertType; 446 } 447 448 449 450 /** 451 * {@inheritDoc} 452 */ 453 public boolean isEnabled() { 454 return pEnabled; 455 } 456 457 458 459 /** 460 * {@inheritDoc} 461 */ 462 public SortedSet<String> getEnabledAlertType() { 463 return pEnabledAlertType; 464 } 465 466 467 468 /** 469 * {@inheritDoc} 470 */ 471 public String getJavaClass() { 472 return pJavaClass; 473 } 474 475 476 477 /** 478 * {@inheritDoc} 479 */ 480 public Class<? extends AlertHandlerCfg> configurationClass() { 481 return AlertHandlerCfg.class; 482 } 483 484 485 486 /** 487 * {@inheritDoc} 488 */ 489 public DN dn() { 490 return impl.getDN(); 491 } 492 493 } 494}