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