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