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 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.admin.std.meta; 028 029 030 031 import java.util.Collection; 032 import java.util.SortedSet; 033 import org.opends.server.admin.AdministratorAction; 034 import org.opends.server.admin.AliasDefaultBehaviorProvider; 035 import org.opends.server.admin.BooleanPropertyDefinition; 036 import org.opends.server.admin.ClassPropertyDefinition; 037 import org.opends.server.admin.client.AuthorizationException; 038 import org.opends.server.admin.client.CommunicationException; 039 import org.opends.server.admin.client.ConcurrentModificationException; 040 import org.opends.server.admin.client.ManagedObject; 041 import org.opends.server.admin.client.MissingMandatoryPropertiesException; 042 import org.opends.server.admin.client.OperationRejectedException; 043 import org.opends.server.admin.ManagedObjectAlreadyExistsException; 044 import org.opends.server.admin.ManagedObjectDefinition; 045 import org.opends.server.admin.PropertyOption; 046 import org.opends.server.admin.PropertyProvider; 047 import org.opends.server.admin.server.ConfigurationChangeListener; 048 import org.opends.server.admin.server.ServerManagedObject; 049 import org.opends.server.admin.std.client.AlertHandlerCfgClient; 050 import org.opends.server.admin.std.server.AlertHandlerCfg; 051 import org.opends.server.admin.StringPropertyDefinition; 052 import org.opends.server.admin.Tag; 053 import org.opends.server.admin.TopCfgDefn; 054 import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 055 import org.opends.server.types.DN; 056 057 058 059 /** 060 * An interface for querying the Alert Handler managed object 061 * definition meta information. 062 * <p> 063 * Alert Handlers are used to notify administrators of significant 064 * problems or notable events that occur in the Directory Server. 065 */ 066 public 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 388 389 /** 390 * Managed object server implementation. 391 */ 392 private static class AlertHandlerCfgServerImpl implements 393 AlertHandlerCfg { 394 395 // Private implementation. 396 private ServerManagedObject<? extends AlertHandlerCfg> impl; 397 398 // The value of the "disabled-alert-type" property. 399 private final SortedSet<String> pDisabledAlertType; 400 401 // The value of the "enabled" property. 402 private final boolean pEnabled; 403 404 // The value of the "enabled-alert-type" property. 405 private final SortedSet<String> pEnabledAlertType; 406 407 // The value of the "java-class" property. 408 private final String pJavaClass; 409 410 411 412 // Private constructor. 413 private AlertHandlerCfgServerImpl(ServerManagedObject<? extends AlertHandlerCfg> impl) { 414 this.impl = impl; 415 this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition()); 416 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 417 this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition()); 418 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 419 } 420 421 422 423 /** 424 * {@inheritDoc} 425 */ 426 public void addChangeListener( 427 ConfigurationChangeListener<AlertHandlerCfg> listener) { 428 impl.registerChangeListener(listener); 429 } 430 431 432 433 /** 434 * {@inheritDoc} 435 */ 436 public void removeChangeListener( 437 ConfigurationChangeListener<AlertHandlerCfg> listener) { 438 impl.deregisterChangeListener(listener); 439 } 440 441 442 443 /** 444 * {@inheritDoc} 445 */ 446 public SortedSet<String> getDisabledAlertType() { 447 return pDisabledAlertType; 448 } 449 450 451 452 /** 453 * {@inheritDoc} 454 */ 455 public boolean isEnabled() { 456 return pEnabled; 457 } 458 459 460 461 /** 462 * {@inheritDoc} 463 */ 464 public SortedSet<String> getEnabledAlertType() { 465 return pEnabledAlertType; 466 } 467 468 469 470 /** 471 * {@inheritDoc} 472 */ 473 public String getJavaClass() { 474 return pJavaClass; 475 } 476 477 478 479 /** 480 * {@inheritDoc} 481 */ 482 public Class<? extends AlertHandlerCfg> configurationClass() { 483 return AlertHandlerCfg.class; 484 } 485 486 487 488 /** 489 * {@inheritDoc} 490 */ 491 public DN dn() { 492 return impl.getDN(); 493 } 494 495 } 496 }