mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
30.41.2007 180b7d839228b6d3a48cd84dbe60daaca2f8e35f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2007 Sun Microsystems, Inc.
 */
package org.opends.server.tools.dsconfig;
 
 
 
import static org.opends.server.messages.MessageHandler.*;
import static org.opends.server.messages.ToolMessages.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
 
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
 
import org.opends.server.admin.AbsoluteInheritedDefaultBehaviorProvider;
import org.opends.server.admin.AbstractManagedObjectDefinition;
import org.opends.server.admin.AdministratorAction;
import org.opends.server.admin.AliasDefaultBehaviorProvider;
import org.opends.server.admin.DefaultBehaviorProviderVisitor;
import org.opends.server.admin.DefinedDefaultBehaviorProvider;
import org.opends.server.admin.EnumPropertyDefinition;
import org.opends.server.admin.PropertyDefinition;
import org.opends.server.admin.PropertyDefinitionUsageBuilder;
import org.opends.server.admin.PropertyDefinitionVisitor;
import org.opends.server.admin.PropertyOption;
import org.opends.server.admin.RelativeInheritedDefaultBehaviorProvider;
import org.opends.server.admin.StringPropertyDefinition;
import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
import org.opends.server.admin.UnknownPropertyDefinitionException;
import org.opends.server.tools.ClientException;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.StringArgument;
import org.opends.server.util.args.SubCommand;
import org.opends.server.util.args.SubCommandArgumentParser;
import org.opends.server.util.table.TableBuilder;
import org.opends.server.util.table.TablePrinter;
import org.opends.server.util.table.TextTablePrinter;
 
 
 
/**
 * A sub-command handler which is used to display help about managed
 * objects and their properties.
 * <p>
 * This sub-command implements the help-properties sub-command.
 */
final class HelpSubCommandHandler extends SubCommandHandler {
 
  /**
   * This class is used to print the default behavior of a property.
   */
  private static class DefaultBehaviorPrinter {
 
    /**
     * The default behavior printer visitor implementation.
     *
     * @param <T>
     *          The property type.
     */
    private static class DefaultVisitor<T> implements
        DefaultBehaviorProviderVisitor<T, String, PropertyDefinition<T>> {
 
      /**
       * {@inheritDoc}
       */
      public String visitAbsoluteInherited(
          AbsoluteInheritedDefaultBehaviorProvider<T> d,
          PropertyDefinition<T> p) {
        return getMessage(MSGID_DSCFG_HELP_FIELD_INHERITED_ABS, d
            .getPropertyName(), d.getManagedObjectPath()
            .getRelationDefinition().getUserFriendlyName());
      }
 
 
 
      /**
       * {@inheritDoc}
       */
      public String visitAlias(AliasDefaultBehaviorProvider<T> d,
          PropertyDefinition<T> p) {
        return d.getSynopsis();
      }
 
 
 
      /**
       * {@inheritDoc}
       */
      public String visitDefined(DefinedDefaultBehaviorProvider<T> d,
          PropertyDefinition<T> p) {
        StringBuilder builder = new StringBuilder();
        PropertyValuePrinter printer = new PropertyValuePrinter(null, null,
            false);
        boolean isFirst = true;
        for (String s : d.getDefaultValues()) {
          if (!isFirst) {
            builder.append(", ");
          }
 
          T value = p.decodeValue(s);
          builder.append(printer.print(p, value));
        }
 
        return builder.toString();
      }
 
 
 
      /**
       * {@inheritDoc}
       */
      public String visitRelativeInherited(
          RelativeInheritedDefaultBehaviorProvider<T> d,
          PropertyDefinition<T> p) {
        if (d.getRelativeOffset() == 0) {
          return getMessage(MSGID_DSCFG_HELP_FIELD_INHERITED_THIS, d
              .getPropertyName(), d.getManagedObjectDefinition()
              .getUserFriendlyName());
        } else {
          return getMessage(MSGID_DSCFG_HELP_FIELD_INHERITED_PARENT, d
              .getPropertyName(), d.getManagedObjectDefinition()
              .getUserFriendlyName());
        }
      }
 
 
 
      /**
       * {@inheritDoc}
       */
      public String visitUndefined(UndefinedDefaultBehaviorProvider<T> d,
          PropertyDefinition<T> p) {
        return getMessage(MSGID_DSCFG_HELP_FIELD_UNDEFINED);
      }
 
    }
 
 
 
    /**
     * Create a new default behavior printer.
     */
    public DefaultBehaviorPrinter() {
      // No implementation required.
    }
 
 
 
    /**
     * Get a user-friendly description of a property's default
     * behavior.
     *
     * @param <T>
     *          The type of the property definition.
     * @param pd
     *          The property definition.
     * @return Returns the user-friendly description of a property's
     *         default behavior.
     */
    public <T> String print(PropertyDefinition<T> pd) {
      DefaultVisitor<T> v = new DefaultVisitor<T>();
      return pd.getDefaultBehaviorProvider().accept(v, pd);
    }
  }
 
 
 
  /**
   * This class is used to print detailed syntax information about a
   * property.
   */
  private static class SyntaxPrinter {
 
    /**
     * The syntax printer visitor implementation.
     */
    private static class Visitor extends
        PropertyDefinitionVisitor<Void, PrintStream> {
 
      // Private constructor.
      private Visitor() {
        // No implementation required.
      }
 
 
 
      /**
       * {@inheritDoc}
       */
      @Override
      public <E extends Enum<E>> Void visitEnum(EnumPropertyDefinition<E> d,
          PrintStream p) {
        displayUsage(p, getMessage(MSGID_DSCFG_HELP_FIELD_ENUM));
        p.println();
 
        TableBuilder builder = new TableBuilder();
        boolean isFirst = true;
        for (E value : EnumSet.<E> allOf(d.getEnumClass())) {
          if (!isFirst) {
            builder.startRow();
          }
 
          builder.startRow();
          builder.appendCell();
          builder.appendCell();
          builder.appendCell(value.toString());
          builder.appendCell(HEADING_SEPARATOR);
          builder.appendCell(d.getValueSynopsis(value));
 
          isFirst = false;
        }
 
        TextTablePrinter factory = new TextTablePrinter(p);
        factory.setDisplayHeadings(false);
        factory.setColumnWidth(0, HEADING_WIDTH);
        factory.setColumnWidth(1, HEADING_SEPARATOR.length());
        factory.setColumnWidth(4, 0);
        factory.setPadding(0);
 
        builder.print(factory);
 
        return null;
      }
 
 
 
      /**
       * {@inheritDoc}
       */
      @Override
      public Void visitString(StringPropertyDefinition d, PrintStream p) {
        PropertyDefinitionUsageBuilder usageBuilder =
          new PropertyDefinitionUsageBuilder(true);
 
        TableBuilder builder = new TableBuilder();
        builder.startRow();
        builder.appendCell(getMessage(MSGID_DSCFG_HELP_HEADING_SYNTAX));
        builder.appendCell(HEADING_SEPARATOR);
        builder.appendCell(usageBuilder.getUsage(d));
 
        if (d.getPattern() != null) {
          builder.startRow();
          builder.startRow();
          builder.appendCell();
          builder.appendCell();
          builder.appendCell(d.getPatternSynopsis());
        }
 
        TextTablePrinter factory = new TextTablePrinter(p);
        factory.setDisplayHeadings(false);
        factory.setColumnWidth(0, HEADING_WIDTH);
        factory.setColumnWidth(2, 0);
        factory.setPadding(0);
 
        builder.print(factory);
 
        return null;
      }
 
 
 
      /**
       * {@inheritDoc}
       */
      @Override
      public Void visitUnknown(PropertyDefinition<?> d, PrintStream p)
          throws UnknownPropertyDefinitionException {
        PropertyDefinitionUsageBuilder usageBuilder =
          new PropertyDefinitionUsageBuilder(true);
        displayUsage(p, usageBuilder.getUsage(d));
 
        return null;
      }
 
 
 
      // Common usage.
      private void displayUsage(PrintStream p, String usage) {
        TableBuilder builder = new TableBuilder();
        builder.startRow();
        builder.appendCell(getMessage(MSGID_DSCFG_HELP_HEADING_SYNTAX));
        builder.appendCell(HEADING_SEPARATOR);
        builder.appendCell(usage);
 
        TextTablePrinter factory = new TextTablePrinter(p);
        factory.setDisplayHeadings(false);
        factory.setColumnWidth(0, HEADING_WIDTH);
        factory.setColumnWidth(2, 0);
        factory.setPadding(0);
 
        builder.print(factory);
      }
    }
 
    // The private implementation.
    private final Visitor pimpl;
 
 
 
    /**
     * Creates a new syntax printer which can be used to print
     * detailed syntax information about a property.
     */
    public SyntaxPrinter() {
      this.pimpl = new Visitor();
    }
 
 
 
    /**
     * Print detailed syntax information about a property definition.
     *
     * @param out
     *          The output stream.
     * @param pd
     *          The property definition.
     */
    public void print(PrintStream out, PropertyDefinition<?> pd) {
      pd.accept(pimpl, out);
    }
  }
 
  // Strings used in property help.
  private final static String HEADING_SEPARATOR = " : ";
 
  // Width of biggest heading (need to be careful of I18N).
  private final static int HEADING_WIDTH;
 
  /**
   * The value for the long option type.
   */
  private static final String OPTION_DSCFG_LONG_TYPE = "type";
 
 
 
  /**
   * The value for the short option type.
   */
  private static final Character OPTION_DSCFG_SHORT_TYPE = 't';
 
  static {
    int tmp = getMessage(MSGID_DSCFG_HELP_HEADING_SYNTAX).length();
    tmp = Math.max(tmp, getMessage(MSGID_DSCFG_HELP_HEADING_DEFAULT).length());
    tmp = Math.max(tmp, getMessage(MSGID_DSCFG_HELP_HEADING_MULTI_VALUED)
        .length());
    tmp = Math
        .max(tmp, getMessage(MSGID_DSCFG_HELP_HEADING_MANDATORY).length());
    tmp = Math
        .max(tmp, getMessage(MSGID_DSCFG_HELP_HEADING_READ_ONLY).length());
    HEADING_WIDTH = tmp;
  }
 
  /**
   * Creates a new help-properties sub-command.
   *
   * @param app
   *          The console application.
   * @param parser
   *          The sub-command argument parser.
   * @return Returns the new help-properties sub-command.
   * @throws ArgumentException
   *           If the sub-command could not be created successfully.
   */
  public static synchronized HelpSubCommandHandler create(
      ConsoleApplication app, SubCommandArgumentParser parser)
      throws ArgumentException {
    if (INSTANCE == null) {
      INSTANCE = new HelpSubCommandHandler(app, parser);
    }
    return INSTANCE;
  }
 
 
 
  /**
   * Gets the application-wide help sub-command handler.
   *
   * @return Returns the application-wide help sub-command handler.
   */
  public static synchronized HelpSubCommandHandler getInstance() {
    if (INSTANCE == null) {
      throw new RuntimeException("Help sub-command handler not initialized");
    } else {
      return INSTANCE;
    }
  }
 
 
 
  // The singleton instance.
  private static HelpSubCommandHandler INSTANCE = null;
 
  // The sub-command associated with this handler.
  private final SubCommand subCommand;
 
  // The argument which should be used to specify the type of managed
  // object to be retrieved.
  private final StringArgument typeArgument;
 
  // A table listing all the available types of managed object.
  private final Map<String, AbstractManagedObjectDefinition<?, ?>> types;
 
  // Private constructor.
  private HelpSubCommandHandler(ConsoleApplication app,
      SubCommandArgumentParser parser) throws ArgumentException {
    super(app);
 
    // Create the sub-command.
    String name = "list-properties";
    int descriptionID = MSGID_DSCFG_DESCRIPTION_SUBCMD_HELPPROP;
    this.subCommand = new SubCommand(parser, name, false, 0, 0, null,
        descriptionID);
 
    this.typeArgument = new StringArgument(OPTION_DSCFG_LONG_TYPE,
        OPTION_DSCFG_SHORT_TYPE, OPTION_DSCFG_LONG_TYPE, false, false, true,
        "{TYPE}", null, null, MSGID_DSCFG_DESCRIPTION_HELP_TYPE);
    this.subCommand.addArgument(this.typeArgument);
 
    // Register common arguments.
    registerAdvancedModeArgument(this.subCommand,
        MSGID_DSCFG_DESCRIPTION_ADVANCED_HELP);
    registerPropertyNameArgument(this.subCommand);
 
    this.types = new TreeMap<String, AbstractManagedObjectDefinition<?, ?>>();
  }
 
 
 
  /**
   * Displays detailed help about a single property to the specified
   * output stream.
   *
   * @param d
   *          The managed object definition.
   * @param name
   *          The name of the property definition.
   * @param out
   *          The output stream.
   */
  public void displayVerboseSingleProperty(
      AbstractManagedObjectDefinition<?, ?> d, String name, PrintStream out) {
    PropertyDefinition<?> pd = d.getPropertyDefinition(name);
 
    // Display the title.
    out.println(getMessage(MSGID_DSCFG_HELP_HEADING_PROPERTY, name));
 
    // Display the property synopsis and description.
    out.println();
    out.println(wrapText(pd.getSynopsis(), MAX_LINE_WIDTH));
    if (pd.getDescription() != null) {
      out.println();
      out.println(wrapText(pd.getDescription(), MAX_LINE_WIDTH));
    }
 
    // Display the syntax.
    out.println();
    SyntaxPrinter syntaxPrinter = new SyntaxPrinter();
    syntaxPrinter.print(out, pd);
 
    // Display remaining information in a table.
    out.println();
    TableBuilder builder = new TableBuilder();
 
    // Display the default behavior.
    DefaultBehaviorPrinter defaultPrinter = new DefaultBehaviorPrinter();
 
    builder.startRow();
    builder.appendCell(getMessage(MSGID_DSCFG_HELP_HEADING_DEFAULT));
    builder.appendCell(HEADING_SEPARATOR);
    builder.appendCell(defaultPrinter.print(pd));
 
    // Display options.
    builder.startRow();
    builder.appendCell(getMessage(MSGID_DSCFG_HELP_HEADING_ADVANCED));
    builder.appendCell(HEADING_SEPARATOR);
    if (pd.hasOption(PropertyOption.ADVANCED)) {
      builder.appendCell(getMessage(MSGID_DSCFG_GENERAL_CONFIRM_YES));
    } else {
      builder.appendCell(getMessage(MSGID_DSCFG_GENERAL_CONFIRM_NO));
    }
 
    builder.startRow();
    builder.appendCell(getMessage(MSGID_DSCFG_HELP_HEADING_MULTI_VALUED));
    builder.appendCell(HEADING_SEPARATOR);
    if (pd.hasOption(PropertyOption.MULTI_VALUED)) {
      builder.appendCell(getMessage(MSGID_DSCFG_GENERAL_CONFIRM_YES));
    } else {
      builder.appendCell(getMessage(MSGID_DSCFG_GENERAL_CONFIRM_NO));
    }
 
    builder.startRow();
    builder.appendCell(getMessage(MSGID_DSCFG_HELP_HEADING_MANDATORY));
    builder.appendCell(HEADING_SEPARATOR);
    if (pd.hasOption(PropertyOption.MANDATORY)) {
      builder.appendCell(getMessage(MSGID_DSCFG_GENERAL_CONFIRM_YES));
    } else {
      builder.appendCell(getMessage(MSGID_DSCFG_GENERAL_CONFIRM_NO));
    }
 
    builder.startRow();
    builder.appendCell(getMessage(MSGID_DSCFG_HELP_HEADING_READ_ONLY));
    builder.appendCell(HEADING_SEPARATOR);
    if (pd.hasOption(PropertyOption.MONITORING)) {
      builder.appendCell(getMessage(MSGID_DSCFG_HELP_FIELD_MONITORING));
    } else if (pd.hasOption(PropertyOption.READ_ONLY)) {
      builder.appendCell(getMessage(MSGID_DSCFG_HELP_FIELD_READ_ONLY, d
          .getUserFriendlyName()));
    } else {
      builder.appendCell(getMessage(MSGID_DSCFG_GENERAL_CONFIRM_NO));
    }
 
    TextTablePrinter factory = new TextTablePrinter(out);
    factory.setDisplayHeadings(false);
    factory.setColumnWidth(0, HEADING_WIDTH);
    factory.setColumnWidth(2, 0);
    factory.setPadding(0);
    builder.print(factory);
 
    // Administrator action.
    AdministratorAction action = pd.getAdministratorAction();
    String synopsis = action.getSynopsis();
    if (synopsis == null) {
      switch (action.getType()) {
      case COMPONENT_RESTART:
        synopsis = getMessage(MSGID_DSCFG_HELP_FIELD_COMPONENT_RESTART, d
            .getUserFriendlyName());
        break;
      case SERVER_RESTART:
        synopsis = getMessage(MSGID_DSCFG_HELP_FIELD_SERVER_RESTART);
        break;
      default:
        // Do nothing.
        break;
      }
    }
 
    if (synopsis != null) {
      out.println();
      out.println(wrapText(synopsis, MAX_LINE_WIDTH));
    }
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  @Override
  public SubCommand getSubCommand() {
    return subCommand;
  }
 
 
 
  /**
   * Registers a managed object definition with this help properties
   * sub-command.
   *
   * @param d
   *          The managed object definition.
   */
  public void registerManagedObjectDefinition(
      AbstractManagedObjectDefinition<?, ?> d) {
    types.put(d.getName(), d);
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  @Override
  public int run()
      throws ArgumentException, ClientException {
    String typeName = typeArgument.getValue();
    Set<String> propertyNames = getPropertyNames();
 
    AbstractManagedObjectDefinition<?, ?> d = null;
    if (typeName != null) {
      // Requested help regarding a single managed object type.
      d = types.get(typeName);
      if (d == null) {
        throw ArgumentExceptionFactory.unknownType(typeName);
      }
    }
 
    // Validate property names if the type was specified.
    if (d != null) {
      for (String propertyName : propertyNames) {
        try {
          d.getPropertyDefinition(propertyName);
        } catch (IllegalArgumentException e) {
          throw ArgumentExceptionFactory.unknownProperty(d, propertyName);
        }
      }
    }
 
    // Determine the set of managed objects to be displayed.
    Collection<AbstractManagedObjectDefinition<?, ?>> defns;
    if (d == null) {
      defns = types.values();
    } else {
      defns = Collections.<AbstractManagedObjectDefinition<?, ?>> singleton(d);
    }
 
    if (!getConsoleApplication().isVerbose()) {
      displayNonVerbose(defns, propertyNames);
    } else {
      displayVerbose(defns, propertyNames);
    }
    return 0;
  }
 
 
 
  // Output property summary table.
  private void displayNonVerbose(
      Collection<AbstractManagedObjectDefinition<?, ?>> defns,
      Set<String> propertyNames) {
    PrintStream out = getConsoleApplication().getOutputStream();
    if (!getConsoleApplication().isScriptFriendly()) {
      out.println(getMessage(MSGID_DSCFG_HELP_DESCRIPTION_OPTION));
      out.println();
      out.print(" r -- ");
      out.println(getMessage(MSGID_DSCFG_HELP_DESCRIPTION_READ));
      out.print(" w -- ");
      out.println(getMessage(MSGID_DSCFG_HELP_DESCRIPTION_WRITE));
      out.print(" m -- ");
      out.println(getMessage(MSGID_DSCFG_HELP_DESCRIPTION_MANDATORY));
      out.print(" s -- ");
      out.println(getMessage(MSGID_DSCFG_HELP_DESCRIPTION_SINGLE_VALUED));
      out.print(" a -- ");
      out.println(getMessage(MSGID_DSCFG_HELP_DESCRIPTION_ADMIN_ACTION));
      out.println();
      out.println();
    }
 
    // Headings.
    TableBuilder builder = new TableBuilder();
 
    builder.appendHeading(getMessage(MSGID_DSCFG_HEADING_MANAGED_OBJECT_NAME));
    builder.appendHeading(getMessage(MSGID_DSCFG_HEADING_PROPERTY_NAME));
    builder.appendHeading(getMessage(MSGID_DSCFG_HEADING_PROPERTY_OPTIONS));
    builder.appendHeading(getMessage(MSGID_DSCFG_HEADING_PROPERTY_SYNTAX));
 
    // Sort keys.
    builder.addSortKey(0);
    builder.addSortKey(1);
 
    // Generate the table content.
    for (AbstractManagedObjectDefinition<?, ?> mod : defns) {
      Collection<PropertyDefinition<?>> pds;
      if (getConsoleApplication().isScriptFriendly()) {
        pds = mod.getAllPropertyDefinitions();
      } else {
        pds = mod.getPropertyDefinitions();
      }
 
      for (PropertyDefinition<?> pd : pds) {
        if (pd.hasOption(PropertyOption.HIDDEN)) {
          continue;
        }
 
        if (!isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
          continue;
        }
 
        if (!propertyNames.isEmpty() && !propertyNames.contains(pd.getName())) {
          continue;
        }
 
        // Display the property.
        builder.startRow();
 
        // Display the managed object type if necessary.
        builder.appendCell(mod.getName());
 
        // Display the property name.
        builder.appendCell(pd.getName());
 
        // Display the options.
        builder.appendCell(getPropertyOptionSummary(pd));
 
        // Display the syntax.
        PropertyDefinitionUsageBuilder v =
          new PropertyDefinitionUsageBuilder(false);
        builder.appendCell(v.getUsage(pd));
      }
    }
 
    TablePrinter printer;
    if (getConsoleApplication().isScriptFriendly()) {
      printer = createScriptFriendlyTablePrinter(out);
    } else {
      printer = new TextTablePrinter(out);
    }
    builder.print(printer);
  }
 
 
 
  // Display detailed help on managed objects and their properties.
  private void displayVerbose(
      Collection<AbstractManagedObjectDefinition<?, ?>> defns,
      Set<String> propertyNames) {
    PrintStream out = getConsoleApplication().getOutputStream();
 
    // Construct line used to separate consecutive sections.
    char[] c1 = new char[MAX_LINE_WIDTH];
    Arrays.fill(c1, '=');
    char[] c2 = new char[MAX_LINE_WIDTH];
    Arrays.fill(c2, '-');
 
    // Display help for each managed object.
    boolean isFirstManagedObject = true;
    for (AbstractManagedObjectDefinition<?, ?> mod : defns) {
      // Display help for each property.
      Set<PropertyDefinition<?>> pds =
        new TreeSet<PropertyDefinition<?>>(mod.getAllPropertyDefinitions());
      boolean isFirstProperty = true;
      for (PropertyDefinition<?> pd : pds) {
        if (pd.hasOption(PropertyOption.HIDDEN)) {
          continue;
        }
 
        if (!isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
          continue;
        }
 
        if (!propertyNames.isEmpty() && !propertyNames.contains(pd.getName())) {
          continue;
        }
 
        if (isFirstProperty) {
          // User has requested properties relating to this managed
          // object definition, so display the summary of the managed
          // object.
          if (!isFirstManagedObject) {
            out.println();
            out.println(c1);
            out.println();
          } else {
            isFirstManagedObject = false;
          }
 
          // Display the title.
          out.println(wrapText(getMessage(MSGID_DSCFG_HELP_HEADING_COMPONENT,
              mod.getUserFriendlyName()), MAX_LINE_WIDTH));
 
          out.println();
          out.println(wrapText(mod.getSynopsis(), MAX_LINE_WIDTH));
          if (mod.getDescription() != null) {
            out.println();
            out.println(wrapText(mod.getDescription(), MAX_LINE_WIDTH));
          }
        }
 
        out.println();
        out.println(c2);
        out.println();
 
        displayVerboseSingleProperty(mod, pd.getName(), out);
        isFirstProperty = false;
      }
    }
  }
 
 
 
  // Compute the options field.
  private String getPropertyOptionSummary(PropertyDefinition<?> pd) {
    StringBuilder b = new StringBuilder();
 
    if (pd.hasOption(PropertyOption.MONITORING)
        || pd.hasOption(PropertyOption.READ_ONLY)) {
      b.append("r-");
    } else {
      b.append("rw");
    }
 
    if (pd.hasOption(PropertyOption.MANDATORY)) {
      b.append('m');
    } else {
      b.append('-');
    }
 
    if (pd.hasOption(PropertyOption.MULTI_VALUED)) {
      b.append('-');
    } else {
      b.append('s');
    }
 
    AdministratorAction action = pd.getAdministratorAction();
    if (action.getType() != AdministratorAction.Type.NONE) {
      b.append('a');
    } else {
      b.append('-');
    }
    return b.toString();
  }
}