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