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