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  /** {@inheritDoc} */
222  public DebugTargetCfgClient createClientConfiguration(
223      ManagedObject<? extends DebugTargetCfgClient> impl) {
224    return new DebugTargetCfgClientImpl(impl);
225  }
226
227
228
229  /** {@inheritDoc} */
230  public DebugTargetCfg createServerConfiguration(
231      ServerManagedObject<? extends DebugTargetCfg> impl) {
232    return new DebugTargetCfgServerImpl(impl);
233  }
234
235
236
237  /** {@inheritDoc} */
238  public Class<DebugTargetCfg> getServerConfigurationClass() {
239    return DebugTargetCfg.class;
240  }
241
242
243
244  /**
245   * Get the "debug-exceptions-only" property definition.
246   * <p>
247   * Indicates whether only logs with exception should be logged.
248   *
249   * @return Returns the "debug-exceptions-only" property definition.
250   */
251  public BooleanPropertyDefinition getDebugExceptionsOnlyPropertyDefinition() {
252    return PD_DEBUG_EXCEPTIONS_ONLY;
253  }
254
255
256
257  /**
258   * Get the "debug-scope" property definition.
259   * <p>
260   * Specifies the fully-qualified OpenDJ Java package, class, or
261   * method affected by the settings in this target definition. Use the
262   * number character (#) to separate the class name and the method
263   * name (that is, org.opends.server.core.DirectoryServer#startUp).
264   *
265   * @return Returns the "debug-scope" property definition.
266   */
267  public StringPropertyDefinition getDebugScopePropertyDefinition() {
268    return PD_DEBUG_SCOPE;
269  }
270
271
272
273  /**
274   * Get the "enabled" property definition.
275   * <p>
276   * Indicates whether the Debug Target is enabled.
277   *
278   * @return Returns the "enabled" property definition.
279   */
280  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
281    return PD_ENABLED;
282  }
283
284
285
286  /**
287   * Get the "include-throwable-cause" property definition.
288   * <p>
289   * Specifies the property to indicate whether to include the cause
290   * of exceptions in exception thrown and caught messages.
291   *
292   * @return Returns the "include-throwable-cause" property definition.
293   */
294  public BooleanPropertyDefinition getIncludeThrowableCausePropertyDefinition() {
295    return PD_INCLUDE_THROWABLE_CAUSE;
296  }
297
298
299
300  /**
301   * Get the "omit-method-entry-arguments" property definition.
302   * <p>
303   * Specifies the property to indicate whether to include method
304   * arguments in debug messages.
305   *
306   * @return Returns the "omit-method-entry-arguments" property definition.
307   */
308  public BooleanPropertyDefinition getOmitMethodEntryArgumentsPropertyDefinition() {
309    return PD_OMIT_METHOD_ENTRY_ARGUMENTS;
310  }
311
312
313
314  /**
315   * Get the "omit-method-return-value" property definition.
316   * <p>
317   * Specifies the property to indicate whether to include the return
318   * value in debug messages.
319   *
320   * @return Returns the "omit-method-return-value" property definition.
321   */
322  public BooleanPropertyDefinition getOmitMethodReturnValuePropertyDefinition() {
323    return PD_OMIT_METHOD_RETURN_VALUE;
324  }
325
326
327
328  /**
329   * Get the "throwable-stack-frames" property definition.
330   * <p>
331   * Specifies the property to indicate the number of stack frames to
332   * include in the stack trace for method entry and exception thrown
333   * messages.
334   *
335   * @return Returns the "throwable-stack-frames" property definition.
336   */
337  public IntegerPropertyDefinition getThrowableStackFramesPropertyDefinition() {
338    return PD_THROWABLE_STACK_FRAMES;
339  }
340
341
342
343  /**
344   * Managed object client implementation.
345   */
346  private static class DebugTargetCfgClientImpl implements
347    DebugTargetCfgClient {
348
349    /** Private implementation. */
350    private ManagedObject<? extends DebugTargetCfgClient> impl;
351
352
353
354    /** Private constructor. */
355    private DebugTargetCfgClientImpl(
356        ManagedObject<? extends DebugTargetCfgClient> impl) {
357      this.impl = impl;
358    }
359
360
361
362    /** {@inheritDoc} */
363    public boolean isDebugExceptionsOnly() {
364      return impl.getPropertyValue(INSTANCE.getDebugExceptionsOnlyPropertyDefinition());
365    }
366
367
368
369    /** {@inheritDoc} */
370    public void setDebugExceptionsOnly(Boolean value) {
371      impl.setPropertyValue(INSTANCE.getDebugExceptionsOnlyPropertyDefinition(), value);
372    }
373
374
375
376    /** {@inheritDoc} */
377    public String getDebugScope() {
378      return impl.getPropertyValue(INSTANCE.getDebugScopePropertyDefinition());
379    }
380
381
382
383    /** {@inheritDoc} */
384    public void setDebugScope(String value) throws PropertyException {
385      impl.setPropertyValue(INSTANCE.getDebugScopePropertyDefinition(), value);
386    }
387
388
389
390    /** {@inheritDoc} */
391    public Boolean isEnabled() {
392      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
393    }
394
395
396
397    /** {@inheritDoc} */
398    public void setEnabled(boolean value) {
399      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
400    }
401
402
403
404    /** {@inheritDoc} */
405    public boolean isIncludeThrowableCause() {
406      return impl.getPropertyValue(INSTANCE.getIncludeThrowableCausePropertyDefinition());
407    }
408
409
410
411    /** {@inheritDoc} */
412    public void setIncludeThrowableCause(Boolean value) {
413      impl.setPropertyValue(INSTANCE.getIncludeThrowableCausePropertyDefinition(), value);
414    }
415
416
417
418    /** {@inheritDoc} */
419    public boolean isOmitMethodEntryArguments() {
420      return impl.getPropertyValue(INSTANCE.getOmitMethodEntryArgumentsPropertyDefinition());
421    }
422
423
424
425    /** {@inheritDoc} */
426    public void setOmitMethodEntryArguments(Boolean value) {
427      impl.setPropertyValue(INSTANCE.getOmitMethodEntryArgumentsPropertyDefinition(), value);
428    }
429
430
431
432    /** {@inheritDoc} */
433    public boolean isOmitMethodReturnValue() {
434      return impl.getPropertyValue(INSTANCE.getOmitMethodReturnValuePropertyDefinition());
435    }
436
437
438
439    /** {@inheritDoc} */
440    public void setOmitMethodReturnValue(Boolean value) {
441      impl.setPropertyValue(INSTANCE.getOmitMethodReturnValuePropertyDefinition(), value);
442    }
443
444
445
446    /** {@inheritDoc} */
447    public int getThrowableStackFrames() {
448      return impl.getPropertyValue(INSTANCE.getThrowableStackFramesPropertyDefinition());
449    }
450
451
452
453    /** {@inheritDoc} */
454    public void setThrowableStackFrames(Integer value) {
455      impl.setPropertyValue(INSTANCE.getThrowableStackFramesPropertyDefinition(), value);
456    }
457
458
459
460    /** {@inheritDoc} */
461    public ManagedObjectDefinition<? extends DebugTargetCfgClient, ? extends DebugTargetCfg> definition() {
462      return INSTANCE;
463    }
464
465
466
467    /** {@inheritDoc} */
468    public PropertyProvider properties() {
469      return impl;
470    }
471
472
473
474    /** {@inheritDoc} */
475    public void commit() throws ManagedObjectAlreadyExistsException,
476        MissingMandatoryPropertiesException, ConcurrentModificationException,
477        OperationRejectedException, LdapException {
478      impl.commit();
479    }
480
481
482
483    /** {@inheritDoc} */
484    public String toString() {
485      return impl.toString();
486    }
487  }
488
489
490
491  /**
492   * Managed object server implementation.
493   */
494  private static class DebugTargetCfgServerImpl implements
495    DebugTargetCfg {
496
497    /** Private implementation. */
498    private ServerManagedObject<? extends DebugTargetCfg> impl;
499
500    /** The value of the "debug-exceptions-only" property. */
501    private final boolean pDebugExceptionsOnly;
502
503    /** The value of the "debug-scope" property. */
504    private final String pDebugScope;
505
506    /** The value of the "enabled" property. */
507    private final boolean pEnabled;
508
509    /** The value of the "include-throwable-cause" property. */
510    private final boolean pIncludeThrowableCause;
511
512    /** The value of the "omit-method-entry-arguments" property. */
513    private final boolean pOmitMethodEntryArguments;
514
515    /** The value of the "omit-method-return-value" property. */
516    private final boolean pOmitMethodReturnValue;
517
518    /** The value of the "throwable-stack-frames" property. */
519    private final int pThrowableStackFrames;
520
521
522
523    /** Private constructor. */
524    private DebugTargetCfgServerImpl(ServerManagedObject<? extends DebugTargetCfg> impl) {
525      this.impl = impl;
526      this.pDebugExceptionsOnly = impl.getPropertyValue(INSTANCE.getDebugExceptionsOnlyPropertyDefinition());
527      this.pDebugScope = impl.getPropertyValue(INSTANCE.getDebugScopePropertyDefinition());
528      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
529      this.pIncludeThrowableCause = impl.getPropertyValue(INSTANCE.getIncludeThrowableCausePropertyDefinition());
530      this.pOmitMethodEntryArguments = impl.getPropertyValue(INSTANCE.getOmitMethodEntryArgumentsPropertyDefinition());
531      this.pOmitMethodReturnValue = impl.getPropertyValue(INSTANCE.getOmitMethodReturnValuePropertyDefinition());
532      this.pThrowableStackFrames = impl.getPropertyValue(INSTANCE.getThrowableStackFramesPropertyDefinition());
533    }
534
535
536
537    /** {@inheritDoc} */
538    public void addChangeListener(
539        ConfigurationChangeListener<DebugTargetCfg> listener) {
540      impl.registerChangeListener(listener);
541    }
542
543
544
545    /** {@inheritDoc} */
546    public void removeChangeListener(
547        ConfigurationChangeListener<DebugTargetCfg> listener) {
548      impl.deregisterChangeListener(listener);
549    }
550
551
552
553    /** {@inheritDoc} */
554    public boolean isDebugExceptionsOnly() {
555      return pDebugExceptionsOnly;
556    }
557
558
559
560    /** {@inheritDoc} */
561    public String getDebugScope() {
562      return pDebugScope;
563    }
564
565
566
567    /** {@inheritDoc} */
568    public boolean isEnabled() {
569      return pEnabled;
570    }
571
572
573
574    /** {@inheritDoc} */
575    public boolean isIncludeThrowableCause() {
576      return pIncludeThrowableCause;
577    }
578
579
580
581    /** {@inheritDoc} */
582    public boolean isOmitMethodEntryArguments() {
583      return pOmitMethodEntryArguments;
584    }
585
586
587
588    /** {@inheritDoc} */
589    public boolean isOmitMethodReturnValue() {
590      return pOmitMethodReturnValue;
591    }
592
593
594
595    /** {@inheritDoc} */
596    public int getThrowableStackFrames() {
597      return pThrowableStackFrames;
598    }
599
600
601
602    /** {@inheritDoc} */
603    public Class<? extends DebugTargetCfg> configurationClass() {
604      return DebugTargetCfg.class;
605    }
606
607
608
609    /** {@inheritDoc} */
610    public DN dn() {
611      return impl.getDN();
612    }
613
614
615
616    /** {@inheritDoc} */
617    public String toString() {
618      return impl.toString();
619    }
620  }
621}