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 /** {@inheritDoc} */ 170 public AlertHandlerCfgClient createClientConfiguration( 171 ManagedObject<? extends AlertHandlerCfgClient> impl) { 172 return new AlertHandlerCfgClientImpl(impl); 173 } 174 175 176 177 /** {@inheritDoc} */ 178 public AlertHandlerCfg createServerConfiguration( 179 ServerManagedObject<? extends AlertHandlerCfg> impl) { 180 return new AlertHandlerCfgServerImpl(impl); 181 } 182 183 184 185 /** {@inheritDoc} */ 186 public Class<AlertHandlerCfg> getServerConfigurationClass() { 187 return AlertHandlerCfg.class; 188 } 189 190 191 192 /** 193 * Get the "disabled-alert-type" property definition. 194 * <p> 195 * Specifies the names of the alert types that are disabled for this 196 * alert handler. 197 * <p> 198 * If there are any values for this attribute, then no alerts with 199 * any of the specified types are allowed. If there are no values for 200 * this attribute, then only alerts with a type included in the set 201 * of enabled alert types are allowed, or if there are no values for 202 * the enabled alert types option, then all alert types are allowed. 203 * 204 * @return Returns the "disabled-alert-type" property definition. 205 */ 206 public StringPropertyDefinition getDisabledAlertTypePropertyDefinition() { 207 return PD_DISABLED_ALERT_TYPE; 208 } 209 210 211 212 /** 213 * Get the "enabled" property definition. 214 * <p> 215 * Indicates whether the Alert Handler is enabled. 216 * 217 * @return Returns the "enabled" property definition. 218 */ 219 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 220 return PD_ENABLED; 221 } 222 223 224 225 /** 226 * Get the "enabled-alert-type" property definition. 227 * <p> 228 * Specifies the names of the alert types that are enabled for this 229 * alert handler. 230 * <p> 231 * If there are any values for this attribute, then only alerts with 232 * one of the specified types are allowed (unless they are also 233 * included in the disabled alert types). If there are no values for 234 * this attribute, then any alert with a type not included in the 235 * list of disabled alert types is allowed. 236 * 237 * @return Returns the "enabled-alert-type" property definition. 238 */ 239 public StringPropertyDefinition getEnabledAlertTypePropertyDefinition() { 240 return PD_ENABLED_ALERT_TYPE; 241 } 242 243 244 245 /** 246 * Get the "java-class" property definition. 247 * <p> 248 * Specifies the fully-qualified name of the Java class that 249 * provides the Alert Handler implementation. 250 * 251 * @return Returns the "java-class" property definition. 252 */ 253 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 254 return PD_JAVA_CLASS; 255 } 256 257 258 259 /** 260 * Managed object client implementation. 261 */ 262 private static class AlertHandlerCfgClientImpl implements 263 AlertHandlerCfgClient { 264 265 /** Private implementation. */ 266 private ManagedObject<? extends AlertHandlerCfgClient> impl; 267 268 269 270 /** Private constructor. */ 271 private AlertHandlerCfgClientImpl( 272 ManagedObject<? extends AlertHandlerCfgClient> impl) { 273 this.impl = impl; 274 } 275 276 277 278 /** {@inheritDoc} */ 279 public SortedSet<String> getDisabledAlertType() { 280 return impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition()); 281 } 282 283 284 285 /** {@inheritDoc} */ 286 public void setDisabledAlertType(Collection<String> values) { 287 impl.setPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition(), values); 288 } 289 290 291 292 /** {@inheritDoc} */ 293 public Boolean isEnabled() { 294 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 295 } 296 297 298 299 /** {@inheritDoc} */ 300 public void setEnabled(boolean value) { 301 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 302 } 303 304 305 306 /** {@inheritDoc} */ 307 public SortedSet<String> getEnabledAlertType() { 308 return impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition()); 309 } 310 311 312 313 /** {@inheritDoc} */ 314 public void setEnabledAlertType(Collection<String> values) { 315 impl.setPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition(), values); 316 } 317 318 319 320 /** {@inheritDoc} */ 321 public String getJavaClass() { 322 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 323 } 324 325 326 327 /** {@inheritDoc} */ 328 public void setJavaClass(String value) { 329 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 330 } 331 332 333 334 /** {@inheritDoc} */ 335 public ManagedObjectDefinition<? extends AlertHandlerCfgClient, ? extends AlertHandlerCfg> definition() { 336 return INSTANCE; 337 } 338 339 340 341 /** {@inheritDoc} */ 342 public PropertyProvider properties() { 343 return impl; 344 } 345 346 347 348 /** {@inheritDoc} */ 349 public void commit() throws ManagedObjectAlreadyExistsException, 350 MissingMandatoryPropertiesException, ConcurrentModificationException, 351 OperationRejectedException, LdapException { 352 impl.commit(); 353 } 354 355 356 357 /** {@inheritDoc} */ 358 public String toString() { 359 return impl.toString(); 360 } 361 } 362 363 364 365 /** 366 * Managed object server implementation. 367 */ 368 private static class AlertHandlerCfgServerImpl implements 369 AlertHandlerCfg { 370 371 /** Private implementation. */ 372 private ServerManagedObject<? extends AlertHandlerCfg> impl; 373 374 /** The value of the "disabled-alert-type" property. */ 375 private final SortedSet<String> pDisabledAlertType; 376 377 /** The value of the "enabled" property. */ 378 private final boolean pEnabled; 379 380 /** The value of the "enabled-alert-type" property. */ 381 private final SortedSet<String> pEnabledAlertType; 382 383 /** The value of the "java-class" property. */ 384 private final String pJavaClass; 385 386 387 388 /** Private constructor. */ 389 private AlertHandlerCfgServerImpl(ServerManagedObject<? extends AlertHandlerCfg> impl) { 390 this.impl = impl; 391 this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition()); 392 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 393 this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition()); 394 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 395 } 396 397 398 399 /** {@inheritDoc} */ 400 public void addChangeListener( 401 ConfigurationChangeListener<AlertHandlerCfg> listener) { 402 impl.registerChangeListener(listener); 403 } 404 405 406 407 /** {@inheritDoc} */ 408 public void removeChangeListener( 409 ConfigurationChangeListener<AlertHandlerCfg> listener) { 410 impl.deregisterChangeListener(listener); 411 } 412 413 414 415 /** {@inheritDoc} */ 416 public SortedSet<String> getDisabledAlertType() { 417 return pDisabledAlertType; 418 } 419 420 421 422 /** {@inheritDoc} */ 423 public boolean isEnabled() { 424 return pEnabled; 425 } 426 427 428 429 /** {@inheritDoc} */ 430 public SortedSet<String> getEnabledAlertType() { 431 return pEnabledAlertType; 432 } 433 434 435 436 /** {@inheritDoc} */ 437 public String getJavaClass() { 438 return pJavaClass; 439 } 440 441 442 443 /** {@inheritDoc} */ 444 public Class<? extends AlertHandlerCfg> configurationClass() { 445 return AlertHandlerCfg.class; 446 } 447 448 449 450 /** {@inheritDoc} */ 451 public DN dn() { 452 return impl.getDN(); 453 } 454 455 456 457 /** {@inheritDoc} */ 458 public String toString() { 459 return impl.toString(); 460 } 461 } 462}