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