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.forgerock.opendj.server.config.meta; 017 018 019 020import org.forgerock.opendj.config.AdministratorAction; 021import org.forgerock.opendj.config.BooleanPropertyDefinition; 022import org.forgerock.opendj.config.client.ConcurrentModificationException; 023import org.forgerock.opendj.config.client.ManagedObject; 024import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 025import org.forgerock.opendj.config.client.OperationRejectedException; 026import org.forgerock.opendj.config.DefaultBehaviorProvider; 027import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 028import org.forgerock.opendj.config.IntegerPropertyDefinition; 029import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 030import org.forgerock.opendj.config.ManagedObjectDefinition; 031import org.forgerock.opendj.config.PropertyException; 032import org.forgerock.opendj.config.PropertyOption; 033import org.forgerock.opendj.config.PropertyProvider; 034import org.forgerock.opendj.config.server.ConfigurationChangeListener; 035import org.forgerock.opendj.config.server.ServerManagedObject; 036import org.forgerock.opendj.config.StringPropertyDefinition; 037import org.forgerock.opendj.config.Tag; 038import org.forgerock.opendj.config.TopCfgDefn; 039import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 040import org.forgerock.opendj.ldap.DN; 041import org.forgerock.opendj.ldap.LdapException; 042import org.forgerock.opendj.server.config.client.DebugTargetCfgClient; 043import org.forgerock.opendj.server.config.server.DebugTargetCfg; 044 045 046 047/** 048 * An interface for querying the Debug Target managed object 049 * definition meta information. 050 * <p> 051 * Debug Targets define the types of messages logged by the debug 052 * logPublisher. 053 */ 054public final class DebugTargetCfgDefn extends ManagedObjectDefinition<DebugTargetCfgClient, DebugTargetCfg> { 055 056 /** The singleton configuration definition instance. */ 057 private static final DebugTargetCfgDefn INSTANCE = new DebugTargetCfgDefn(); 058 059 060 061 /** The "debug-exceptions-only" property definition. */ 062 private static final BooleanPropertyDefinition PD_DEBUG_EXCEPTIONS_ONLY; 063 064 065 066 /** The "debug-scope" property definition. */ 067 private static final StringPropertyDefinition PD_DEBUG_SCOPE; 068 069 070 071 /** The "enabled" property definition. */ 072 private static final BooleanPropertyDefinition PD_ENABLED; 073 074 075 076 /** The "include-throwable-cause" property definition. */ 077 private static final BooleanPropertyDefinition PD_INCLUDE_THROWABLE_CAUSE; 078 079 080 081 /** The "omit-method-entry-arguments" property definition. */ 082 private static final BooleanPropertyDefinition PD_OMIT_METHOD_ENTRY_ARGUMENTS; 083 084 085 086 /** The "omit-method-return-value" property definition. */ 087 private static final BooleanPropertyDefinition PD_OMIT_METHOD_RETURN_VALUE; 088 089 090 091 /** The "throwable-stack-frames" property definition. */ 092 private static final IntegerPropertyDefinition PD_THROWABLE_STACK_FRAMES; 093 094 095 096 /** Build the "debug-exceptions-only" property definition. */ 097 static { 098 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "debug-exceptions-only"); 099 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "debug-exceptions-only")); 100 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 101 builder.setDefaultBehaviorProvider(provider); 102 PD_DEBUG_EXCEPTIONS_ONLY = builder.getInstance(); 103 INSTANCE.registerPropertyDefinition(PD_DEBUG_EXCEPTIONS_ONLY); 104 } 105 106 107 108 /** Build the "debug-scope" property definition. */ 109 static { 110 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "debug-scope"); 111 builder.setOption(PropertyOption.READ_ONLY); 112 builder.setOption(PropertyOption.MANDATORY); 113 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "debug-scope")); 114 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 115 builder.setPattern("^([A-Za-z][A-Za-z0-9_]*\\.)*[A-Za-z][A-Za-z0-9_]*(#[A-Za-z][A-Za-z0-9_]*)?$", "STRING"); 116 PD_DEBUG_SCOPE = builder.getInstance(); 117 INSTANCE.registerPropertyDefinition(PD_DEBUG_SCOPE); 118 } 119 120 121 122 /** Build the "enabled" property definition. */ 123 static { 124 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 125 builder.setOption(PropertyOption.MANDATORY); 126 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 127 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 128 PD_ENABLED = builder.getInstance(); 129 INSTANCE.registerPropertyDefinition(PD_ENABLED); 130 } 131 132 133 134 /** Build the "include-throwable-cause" property definition. */ 135 static { 136 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "include-throwable-cause"); 137 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "include-throwable-cause")); 138 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 139 builder.setDefaultBehaviorProvider(provider); 140 PD_INCLUDE_THROWABLE_CAUSE = builder.getInstance(); 141 INSTANCE.registerPropertyDefinition(PD_INCLUDE_THROWABLE_CAUSE); 142 } 143 144 145 146 /** Build the "omit-method-entry-arguments" property definition. */ 147 static { 148 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "omit-method-entry-arguments"); 149 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "omit-method-entry-arguments")); 150 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 151 builder.setDefaultBehaviorProvider(provider); 152 PD_OMIT_METHOD_ENTRY_ARGUMENTS = builder.getInstance(); 153 INSTANCE.registerPropertyDefinition(PD_OMIT_METHOD_ENTRY_ARGUMENTS); 154 } 155 156 157 158 /** Build the "omit-method-return-value" property definition. */ 159 static { 160 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "omit-method-return-value"); 161 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "omit-method-return-value")); 162 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 163 builder.setDefaultBehaviorProvider(provider); 164 PD_OMIT_METHOD_RETURN_VALUE = builder.getInstance(); 165 INSTANCE.registerPropertyDefinition(PD_OMIT_METHOD_RETURN_VALUE); 166 } 167 168 169 170 /** Build the "throwable-stack-frames" property definition. */ 171 static { 172 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "throwable-stack-frames"); 173 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "throwable-stack-frames")); 174 DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("0"); 175 builder.setDefaultBehaviorProvider(provider); 176 builder.setLowerLimit(0); 177 PD_THROWABLE_STACK_FRAMES = builder.getInstance(); 178 INSTANCE.registerPropertyDefinition(PD_THROWABLE_STACK_FRAMES); 179 } 180 181 182 183 // Register the tags associated with this managed object definition. 184 static { 185 INSTANCE.registerTag(Tag.valueOf("logging")); 186 } 187 188 189 190 /** 191 * Get the Debug Target configuration definition singleton. 192 * 193 * @return Returns the Debug Target configuration definition 194 * singleton. 195 */ 196 public static DebugTargetCfgDefn getInstance() { 197 return INSTANCE; 198 } 199 200 201 202 /** 203 * Private constructor. 204 */ 205 private DebugTargetCfgDefn() { 206 super("debug-target", TopCfgDefn.getInstance()); 207 } 208 209 210 211 /** {@inheritDoc} */ 212 public DebugTargetCfgClient createClientConfiguration( 213 ManagedObject<? extends DebugTargetCfgClient> impl) { 214 return new DebugTargetCfgClientImpl(impl); 215 } 216 217 218 219 /** {@inheritDoc} */ 220 public DebugTargetCfg createServerConfiguration( 221 ServerManagedObject<? extends DebugTargetCfg> impl) { 222 return new DebugTargetCfgServerImpl(impl); 223 } 224 225 226 227 /** {@inheritDoc} */ 228 public Class<DebugTargetCfg> getServerConfigurationClass() { 229 return DebugTargetCfg.class; 230 } 231 232 233 234 /** 235 * Get the "debug-exceptions-only" property definition. 236 * <p> 237 * Indicates whether only logs with exception should be logged. 238 * 239 * @return Returns the "debug-exceptions-only" property definition. 240 */ 241 public BooleanPropertyDefinition getDebugExceptionsOnlyPropertyDefinition() { 242 return PD_DEBUG_EXCEPTIONS_ONLY; 243 } 244 245 246 247 /** 248 * Get the "debug-scope" property definition. 249 * <p> 250 * Specifies the fully-qualified OpenDJ Java package, class, or 251 * method affected by the settings in this target definition. Use the 252 * number character (#) to separate the class name and the method 253 * name (that is, org.opends.server.core.DirectoryServer#startUp). 254 * 255 * @return Returns the "debug-scope" property definition. 256 */ 257 public StringPropertyDefinition getDebugScopePropertyDefinition() { 258 return PD_DEBUG_SCOPE; 259 } 260 261 262 263 /** 264 * Get the "enabled" property definition. 265 * <p> 266 * Indicates whether the Debug Target is enabled. 267 * 268 * @return Returns the "enabled" property definition. 269 */ 270 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 271 return PD_ENABLED; 272 } 273 274 275 276 /** 277 * Get the "include-throwable-cause" property definition. 278 * <p> 279 * Specifies the property to indicate whether to include the cause 280 * of exceptions in exception thrown and caught messages. 281 * 282 * @return Returns the "include-throwable-cause" property definition. 283 */ 284 public BooleanPropertyDefinition getIncludeThrowableCausePropertyDefinition() { 285 return PD_INCLUDE_THROWABLE_CAUSE; 286 } 287 288 289 290 /** 291 * Get the "omit-method-entry-arguments" property definition. 292 * <p> 293 * Specifies the property to indicate whether to include method 294 * arguments in debug messages. 295 * 296 * @return Returns the "omit-method-entry-arguments" property definition. 297 */ 298 public BooleanPropertyDefinition getOmitMethodEntryArgumentsPropertyDefinition() { 299 return PD_OMIT_METHOD_ENTRY_ARGUMENTS; 300 } 301 302 303 304 /** 305 * Get the "omit-method-return-value" property definition. 306 * <p> 307 * Specifies the property to indicate whether to include the return 308 * value in debug messages. 309 * 310 * @return Returns the "omit-method-return-value" property definition. 311 */ 312 public BooleanPropertyDefinition getOmitMethodReturnValuePropertyDefinition() { 313 return PD_OMIT_METHOD_RETURN_VALUE; 314 } 315 316 317 318 /** 319 * Get the "throwable-stack-frames" property definition. 320 * <p> 321 * Specifies the property to indicate the number of stack frames to 322 * include in the stack trace for method entry and exception thrown 323 * messages. 324 * 325 * @return Returns the "throwable-stack-frames" property definition. 326 */ 327 public IntegerPropertyDefinition getThrowableStackFramesPropertyDefinition() { 328 return PD_THROWABLE_STACK_FRAMES; 329 } 330 331 332 333 /** 334 * Managed object client implementation. 335 */ 336 private static class DebugTargetCfgClientImpl implements 337 DebugTargetCfgClient { 338 339 /** Private implementation. */ 340 private ManagedObject<? extends DebugTargetCfgClient> impl; 341 342 343 344 /** Private constructor. */ 345 private DebugTargetCfgClientImpl( 346 ManagedObject<? extends DebugTargetCfgClient> impl) { 347 this.impl = impl; 348 } 349 350 351 352 /** {@inheritDoc} */ 353 public boolean isDebugExceptionsOnly() { 354 return impl.getPropertyValue(INSTANCE.getDebugExceptionsOnlyPropertyDefinition()); 355 } 356 357 358 359 /** {@inheritDoc} */ 360 public void setDebugExceptionsOnly(Boolean value) { 361 impl.setPropertyValue(INSTANCE.getDebugExceptionsOnlyPropertyDefinition(), value); 362 } 363 364 365 366 /** {@inheritDoc} */ 367 public String getDebugScope() { 368 return impl.getPropertyValue(INSTANCE.getDebugScopePropertyDefinition()); 369 } 370 371 372 373 /** {@inheritDoc} */ 374 public void setDebugScope(String value) throws PropertyException { 375 impl.setPropertyValue(INSTANCE.getDebugScopePropertyDefinition(), value); 376 } 377 378 379 380 /** {@inheritDoc} */ 381 public Boolean isEnabled() { 382 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 383 } 384 385 386 387 /** {@inheritDoc} */ 388 public void setEnabled(boolean value) { 389 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 390 } 391 392 393 394 /** {@inheritDoc} */ 395 public boolean isIncludeThrowableCause() { 396 return impl.getPropertyValue(INSTANCE.getIncludeThrowableCausePropertyDefinition()); 397 } 398 399 400 401 /** {@inheritDoc} */ 402 public void setIncludeThrowableCause(Boolean value) { 403 impl.setPropertyValue(INSTANCE.getIncludeThrowableCausePropertyDefinition(), value); 404 } 405 406 407 408 /** {@inheritDoc} */ 409 public boolean isOmitMethodEntryArguments() { 410 return impl.getPropertyValue(INSTANCE.getOmitMethodEntryArgumentsPropertyDefinition()); 411 } 412 413 414 415 /** {@inheritDoc} */ 416 public void setOmitMethodEntryArguments(Boolean value) { 417 impl.setPropertyValue(INSTANCE.getOmitMethodEntryArgumentsPropertyDefinition(), value); 418 } 419 420 421 422 /** {@inheritDoc} */ 423 public boolean isOmitMethodReturnValue() { 424 return impl.getPropertyValue(INSTANCE.getOmitMethodReturnValuePropertyDefinition()); 425 } 426 427 428 429 /** {@inheritDoc} */ 430 public void setOmitMethodReturnValue(Boolean value) { 431 impl.setPropertyValue(INSTANCE.getOmitMethodReturnValuePropertyDefinition(), value); 432 } 433 434 435 436 /** {@inheritDoc} */ 437 public int getThrowableStackFrames() { 438 return impl.getPropertyValue(INSTANCE.getThrowableStackFramesPropertyDefinition()); 439 } 440 441 442 443 /** {@inheritDoc} */ 444 public void setThrowableStackFrames(Integer value) { 445 impl.setPropertyValue(INSTANCE.getThrowableStackFramesPropertyDefinition(), value); 446 } 447 448 449 450 /** {@inheritDoc} */ 451 public ManagedObjectDefinition<? extends DebugTargetCfgClient, ? extends DebugTargetCfg> definition() { 452 return INSTANCE; 453 } 454 455 456 457 /** {@inheritDoc} */ 458 public PropertyProvider properties() { 459 return impl; 460 } 461 462 463 464 /** {@inheritDoc} */ 465 public void commit() throws ManagedObjectAlreadyExistsException, 466 MissingMandatoryPropertiesException, ConcurrentModificationException, 467 OperationRejectedException, LdapException { 468 impl.commit(); 469 } 470 471 472 473 /** {@inheritDoc} */ 474 public String toString() { 475 return impl.toString(); 476 } 477 } 478 479 480 481 /** 482 * Managed object server implementation. 483 */ 484 private static class DebugTargetCfgServerImpl implements 485 DebugTargetCfg { 486 487 /** Private implementation. */ 488 private ServerManagedObject<? extends DebugTargetCfg> impl; 489 490 /** The value of the "debug-exceptions-only" property. */ 491 private final boolean pDebugExceptionsOnly; 492 493 /** The value of the "debug-scope" property. */ 494 private final String pDebugScope; 495 496 /** The value of the "enabled" property. */ 497 private final boolean pEnabled; 498 499 /** The value of the "include-throwable-cause" property. */ 500 private final boolean pIncludeThrowableCause; 501 502 /** The value of the "omit-method-entry-arguments" property. */ 503 private final boolean pOmitMethodEntryArguments; 504 505 /** The value of the "omit-method-return-value" property. */ 506 private final boolean pOmitMethodReturnValue; 507 508 /** The value of the "throwable-stack-frames" property. */ 509 private final int pThrowableStackFrames; 510 511 512 513 /** Private constructor. */ 514 private DebugTargetCfgServerImpl(ServerManagedObject<? extends DebugTargetCfg> impl) { 515 this.impl = impl; 516 this.pDebugExceptionsOnly = impl.getPropertyValue(INSTANCE.getDebugExceptionsOnlyPropertyDefinition()); 517 this.pDebugScope = impl.getPropertyValue(INSTANCE.getDebugScopePropertyDefinition()); 518 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 519 this.pIncludeThrowableCause = impl.getPropertyValue(INSTANCE.getIncludeThrowableCausePropertyDefinition()); 520 this.pOmitMethodEntryArguments = impl.getPropertyValue(INSTANCE.getOmitMethodEntryArgumentsPropertyDefinition()); 521 this.pOmitMethodReturnValue = impl.getPropertyValue(INSTANCE.getOmitMethodReturnValuePropertyDefinition()); 522 this.pThrowableStackFrames = impl.getPropertyValue(INSTANCE.getThrowableStackFramesPropertyDefinition()); 523 } 524 525 526 527 /** {@inheritDoc} */ 528 public void addChangeListener( 529 ConfigurationChangeListener<DebugTargetCfg> listener) { 530 impl.registerChangeListener(listener); 531 } 532 533 534 535 /** {@inheritDoc} */ 536 public void removeChangeListener( 537 ConfigurationChangeListener<DebugTargetCfg> listener) { 538 impl.deregisterChangeListener(listener); 539 } 540 541 542 543 /** {@inheritDoc} */ 544 public boolean isDebugExceptionsOnly() { 545 return pDebugExceptionsOnly; 546 } 547 548 549 550 /** {@inheritDoc} */ 551 public String getDebugScope() { 552 return pDebugScope; 553 } 554 555 556 557 /** {@inheritDoc} */ 558 public boolean isEnabled() { 559 return pEnabled; 560 } 561 562 563 564 /** {@inheritDoc} */ 565 public boolean isIncludeThrowableCause() { 566 return pIncludeThrowableCause; 567 } 568 569 570 571 /** {@inheritDoc} */ 572 public boolean isOmitMethodEntryArguments() { 573 return pOmitMethodEntryArguments; 574 } 575 576 577 578 /** {@inheritDoc} */ 579 public boolean isOmitMethodReturnValue() { 580 return pOmitMethodReturnValue; 581 } 582 583 584 585 /** {@inheritDoc} */ 586 public int getThrowableStackFrames() { 587 return pThrowableStackFrames; 588 } 589 590 591 592 /** {@inheritDoc} */ 593 public Class<? extends DebugTargetCfg> configurationClass() { 594 return DebugTargetCfg.class; 595 } 596 597 598 599 /** {@inheritDoc} */ 600 public DN dn() { 601 return impl.getDN(); 602 } 603 604 605 606 /** {@inheritDoc} */ 607 public String toString() { 608 return impl.toString(); 609 } 610 } 611}