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

Violette Roche-Montane
06.06.2014 ab72b6a49233c5513e069a61761e5b1746c7a14a
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
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
/*
 * 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 legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * 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 legal-notices/CDDLv1_0.txt.
 * 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
 *
 *
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 */
package org.forgerock.opendj.config;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Set;
import java.util.Vector;
 
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.config.DefinitionDecodingException.Reason;
 
/**
 * Defines the structure of an abstract managed object. Abstract managed objects
 * cannot be instantiated.
 * <p>
 * Applications can query a managed object definition in order to determine the
 * overall configuration model of an application.
 *
 * @param <C>
 *            The type of client managed object configuration that this
 *            definition represents.
 * @param <S>
 *            The type of server managed object configuration that this
 *            definition represents.
 */
public abstract class AbstractManagedObjectDefinition<C extends ConfigurationClient, S extends Configuration> {
 
    // The name of the definition.
    private final String name;
 
    // The parent managed object definition if applicable.
    private final AbstractManagedObjectDefinition<? super C, ? super S> parent;
 
    // The set of constraints associated with this managed object
    // definition.
    private final Collection<Constraint> constraints;
 
    // The set of property definitions applicable to this managed object
    // definition.
    private final Map<String, PropertyDefinition<?>> propertyDefinitions;
 
    // The set of relation definitions applicable to this managed object
    // definition.
    private final Map<String, RelationDefinition<?, ?>> relationDefinitions;
 
    // The set of relation definitions directly referencing this managed
    // object definition.
    private final Set<RelationDefinition<C, S>> reverseRelationDefinitions;
 
    // The set of all property definitions associated with this managed
    // object definition including inherited property definitions.
    private final Map<String, PropertyDefinition<?>> allPropertyDefinitions;
 
    // The set of all relation definitions associated with this managed
    // object definition including inherited relation definitions.
    private final Map<String, RelationDefinition<?, ?>> allRelationDefinitions;
 
    // The set of aggregation property definitions applicable to this
    // managed object definition.
    private final Map<String, AggregationPropertyDefinition<?, ?>> aggregationPropertyDefinitions;
 
    // The set of aggregation property definitions directly referencing this
    // managed object definition.
    private final Vector<AggregationPropertyDefinition<?, ?>> reverseAggregationPropertyDefinitions;
 
    // The set of all aggregation property definitions associated with this
    // managed object definition including inherited relation definitions.
    private final Map<String, AggregationPropertyDefinition<?, ?>> allAggregationPropertyDefinitions;
 
    // The set of tags associated with this managed object.
    private final Set<Tag> allTags;
 
    // Options applicable to this definition.
    private final Set<ManagedObjectOption> options;
 
    // The set of managed object definitions which inherit from this definition.
    private final Map<String, AbstractManagedObjectDefinition<? extends C, ? extends S>> children;
 
    /**
     * Create a new abstract managed object definition.
     *
     * @param name
     *            The name of the definition.
     * @param parent
     *            The parent definition, or <code>null</code> if there is no
     *            parent (only the {@link TopCfgDefn} should have a
     *            <code>null</code> parent, unless the definition is being used
     *            for testing).
     */
    protected AbstractManagedObjectDefinition(String name,
        AbstractManagedObjectDefinition<? super C, ? super S> parent) {
        this.name = name;
        this.parent = parent;
        this.constraints = new LinkedList<Constraint>();
        this.propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
        this.relationDefinitions = new HashMap<String, RelationDefinition<?, ?>>();
        this.reverseRelationDefinitions = new HashSet<RelationDefinition<C, S>>();
        this.allPropertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
        this.allRelationDefinitions = new HashMap<String, RelationDefinition<?, ?>>();
        this.aggregationPropertyDefinitions = new HashMap<String, AggregationPropertyDefinition<?, ?>>();
        this.reverseAggregationPropertyDefinitions = new Vector<AggregationPropertyDefinition<?, ?>>();
        this.allAggregationPropertyDefinitions = new HashMap<String, AggregationPropertyDefinition<?, ?>>();
        this.allTags = new HashSet<Tag>();
        this.options = EnumSet.noneOf(ManagedObjectOption.class);
 
        this.children = new HashMap<String, AbstractManagedObjectDefinition<? extends C, ? extends S>>();
 
        // If we have a parent definition then inherit its features.
        if (parent != null) {
            registerInParent();
 
            for (PropertyDefinition<?> pd : parent.getAllPropertyDefinitions()) {
                allPropertyDefinitions.put(pd.getName(), pd);
            }
 
            for (RelationDefinition<?, ?> rd : parent.getAllRelationDefinitions()) {
                allRelationDefinitions.put(rd.getName(), rd);
            }
 
            for (AggregationPropertyDefinition<?, ?> apd : parent.getAllAggregationPropertyDefinitions()) {
 
                allAggregationPropertyDefinitions.put(apd.getName(), apd);
            }
 
            // Tag inheritance is performed during preprocessing.
        }
    }
 
    /**
     * Get all the child managed object definitions which inherit from this
     * managed object definition.
     *
     * @return Returns an unmodifiable collection containing all the subordinate
     *         managed object definitions which inherit from this managed object
     *         definition.
     */
    public final Collection<AbstractManagedObjectDefinition<? extends C, ? extends S>> getAllChildren() {
        List<AbstractManagedObjectDefinition<? extends C, ? extends S>> list =
            new ArrayList<AbstractManagedObjectDefinition<? extends C, ? extends S>>(children.values());
 
        for (AbstractManagedObjectDefinition<? extends C, ? extends S> child : children.values()) {
            list.addAll(child.getAllChildren());
        }
 
        return Collections.unmodifiableCollection(list);
    }
 
    /**
     * Get all the constraints associated with this type of managed object. The
     * returned collection will contain inherited constraints.
     *
     * @return Returns a collection containing all the constraints associated
     *         with this type of managed object. The caller is free to modify
     *         the collection if required.
     */
    public final Collection<Constraint> getAllConstraints() {
        // This method does not used a cached set of constraints because
        // constraints may be updated after child definitions have been
        // defined.
        List<Constraint> allConstraints = new LinkedList<Constraint>();
 
        if (parent != null) {
            allConstraints.addAll(parent.getAllConstraints());
        }
        allConstraints.addAll(constraints);
 
        return allConstraints;
    }
 
    /**
     * Get all the property definitions associated with this type of managed
     * object. The returned collection will contain inherited property
     * definitions.
     *
     * @return Returns an unmodifiable collection containing all the property
     *         definitions associated with this type of managed object.
     */
    public final Collection<PropertyDefinition<?>> getAllPropertyDefinitions() {
        return Collections.unmodifiableCollection(allPropertyDefinitions.values());
    }
 
    /**
     * Get all the relation definitions associated with this type of managed
     * object. The returned collection will contain inherited relation
     * definitions.
     *
     * @return Returns an unmodifiable collection containing all the relation
     *         definitions associated with this type of managed object.
     */
    public final Collection<RelationDefinition<?, ?>> getAllRelationDefinitions() {
        return Collections.unmodifiableCollection(allRelationDefinitions.values());
    }
 
    /**
     * Get all the relation definitions which refer to this managed object
     * definition. The returned collection will contain relation definitions
     * which refer to parents of this managed object definition.
     *
     * @return Returns a collection containing all the relation definitions
     *         which refer to this managed object definition. The caller is free
     *         to modify the collection if required.
     */
    public final Collection<RelationDefinition<? super C, ? super S>> getAllReverseRelationDefinitions() {
        // This method does not used a cached set of relations because
        // relations may be updated after child definitions have been
        // defined.
        List<RelationDefinition<? super C, ? super S>> rdlist =
            new LinkedList<RelationDefinition<? super C, ? super S>>();
 
        if (parent != null) {
            rdlist.addAll(parent.getAllReverseRelationDefinitions());
        }
        rdlist.addAll(reverseRelationDefinitions);
 
        return rdlist;
    }
 
    /**
     * Get all the aggregation property definitions associated with this type of
     * managed object. The returned collection will contain inherited
     * aggregation property definitions.
     *
     * @return Returns an unmodifiable collection containing all the aggregation
     *         property definitions associated with this type of managed object.
     */
    public final Collection<AggregationPropertyDefinition<?, ?>> getAllAggregationPropertyDefinitions() {
        return Collections.unmodifiableCollection(allAggregationPropertyDefinitions.values());
    }
 
    /**
     * Get all the aggregation property definitions which refer to this managed
     * object definition. The returned collection will contain aggregation
     * property definitions which refer to parents of this managed object
     * definition.
     *
     * @return Returns a collection containing all the aggregation property
     *         definitions which refer to this managed object definition. The
     *         caller is free to modify the collection if required.
     */
    public final Collection<AggregationPropertyDefinition<?, ?>> getAllReverseAggregationPropertyDefinitions() {
        // This method does not used a cached set of aggregation properties
        // because
        // aggregation properties may be updated after child definitions have
        // been
        // defined.
        List<AggregationPropertyDefinition<?, ?>> apdlist = new LinkedList<AggregationPropertyDefinition<?, ?>>();
 
        if (parent != null) {
            apdlist.addAll(parent.getAllReverseAggregationPropertyDefinitions());
        }
        apdlist.addAll(reverseAggregationPropertyDefinitions);
 
        return apdlist;
    }
 
    /**
     * Get all the tags associated with this type of managed object. The
     * returned collection will contain inherited tags.
     *
     * @return Returns an unmodifiable collection containing all the tags
     *         associated with this type of managed object.
     */
    public final Collection<Tag> getAllTags() {
        return Collections.unmodifiableCollection(allTags);
    }
 
    /**
     * Get the named child managed object definition which inherits from this
     * managed object definition. This method will recursively search down
     * through the inheritance hierarchy.
     *
     * @param name
     *            The name of the managed object definition sub-type.
     * @return Returns the named child managed object definition which inherits
     *         from this managed object definition.
     * @throws IllegalArgumentException
     *             If the specified managed object definition name was null or
     *             empty or if the requested subordinate managed object
     *             definition was not found.
     */
    public final AbstractManagedObjectDefinition<? extends C, ? extends S> getChild(String name) {
        if ((name == null) || (name.length() == 0)) {
            throw new IllegalArgumentException("null or empty managed object name");
        }
 
        AbstractManagedObjectDefinition<? extends C, ? extends S> d = children.get(name);
 
        if (d == null) {
            // Recursively search.
            for (AbstractManagedObjectDefinition<? extends C, ? extends S> child : children.values()) {
                try {
                    d = child.getChild(name);
                    break;
                } catch (IllegalArgumentException e) {
                    // Try the next child.
                }
            }
        }
 
        if (d == null) {
            throw new IllegalArgumentException("child managed object definition \"" + name + "\" not found");
        }
 
        return d;
    }
 
    /**
     * Get the child managed object definitions which inherit directly from this
     * managed object definition.
     *
     * @return Returns an unmodifiable collection containing the subordinate
     *         managed object definitions which inherit directly from this
     *         managed object definition.
     */
    public final Collection<AbstractManagedObjectDefinition<? extends C, ? extends S>> getChildren() {
        return Collections.unmodifiableCollection(children.values());
    }
 
    /**
     * Get the constraints defined by this managed object definition. The
     * returned collection will not contain inherited constraints.
     *
     * @return Returns an unmodifiable collection containing the constraints
     *         defined by this managed object definition.
     */
    public final Collection<Constraint> getConstraints() {
        return Collections.unmodifiableCollection(constraints);
    }
 
    /**
     * Gets the optional description of this managed object definition in the
     * default locale.
     *
     * @return Returns the description of this managed object definition in the
     *         default locale, or <code>null</code> if there is no description.
     * @throws UnsupportedOperationException
     *             If this managed object definition is the {@link TopCfgDefn}.
     */
    public final LocalizableMessage getDescription() {
        return getDescription(Locale.getDefault());
    }
 
    /**
     * Gets the optional description of this managed object definition in the
     * specified locale.
     *
     * @param locale
     *            The locale.
     * @return Returns the description of this managed object definition in the
     *         specified locale, or <code>null</code> if there is no
     *         description.
     * @throws UnsupportedOperationException
     *             If this managed object definition is the {@link TopCfgDefn}.
     */
    public final LocalizableMessage getDescription(Locale locale) {
        try {
            return ManagedObjectDefinitionI18NResource.getInstance().getMessage(this, "description", locale);
        } catch (MissingResourceException e) {
            return null;
        }
    }
 
    /**
     * Get the name of the definition.
     *
     * @return Returns the name of the definition.
     */
    public final String getName() {
        return name;
    }
 
    /**
     * Get the parent managed object definition, if applicable.
     *
     * @return Returns the parent of this managed object definition, or
     *         <code>null</code> if this definition is the {@link TopCfgDefn}.
     */
    public final AbstractManagedObjectDefinition<? super C, ? super S> getParent() {
        return parent;
    }
 
    /**
     * Get the specified property definition associated with this type of
     * managed object. The search will include any inherited property
     * definitions.
     *
     * @param name
     *            The name of the property definition to be retrieved.
     * @return Returns the specified property definition associated with this
     *         type of managed object.
     * @throws IllegalArgumentException
     *             If the specified property name was null or empty or if the
     *             requested property definition was not found.
     */
    public final PropertyDefinition<?> getPropertyDefinition(String name) {
        if ((name == null) || (name.length() == 0)) {
            throw new IllegalArgumentException("null or empty property name");
        }
 
        PropertyDefinition<?> d = allPropertyDefinitions.get(name);
        if (d == null) {
            throw new IllegalArgumentException("property definition \"" + name + "\" not found");
        }
 
        return d;
    }
 
    /**
     * Get the property definitions defined by this managed object definition.
     * The returned collection will not contain inherited property definitions.
     *
     * @return Returns an unmodifiable collection containing the property
     *         definitions defined by this managed object definition.
     */
    public final Collection<PropertyDefinition<?>> getPropertyDefinitions() {
        return Collections.unmodifiableCollection(propertyDefinitions.values());
    }
 
    /**
     * Get the specified relation definition associated with this type of
     * managed object.The search will include any inherited relation
     * definitions.
     *
     * @param name
     *            The name of the relation definition to be retrieved.
     * @return Returns the specified relation definition associated with this
     *         type of managed object.
     * @throws IllegalArgumentException
     *             If the specified relation name was null or empty or if the
     *             requested relation definition was not found.
     */
    public final RelationDefinition<?, ?> getRelationDefinition(String name) {
        if ((name == null) || (name.length() == 0)) {
            throw new IllegalArgumentException("null or empty relation name");
        }
 
        RelationDefinition<?, ?> d = allRelationDefinitions.get(name);
        if (d == null) {
            throw new IllegalArgumentException("relation definition \"" + name + "\" not found");
        }
 
        return d;
    }
 
    /**
     * Get the relation definitions defined by this managed object definition.
     * The returned collection will not contain inherited relation definitions.
     *
     * @return Returns an unmodifiable collection containing the relation
     *         definitions defined by this managed object definition.
     */
    public final Collection<RelationDefinition<?, ?>> getRelationDefinitions() {
        return Collections.unmodifiableCollection(relationDefinitions.values());
    }
 
    /**
     * Get the relation definitions which refer directly to this managed object
     * definition. The returned collection will not contain relation definitions
     * which refer to parents of this managed object definition.
     *
     * @return Returns an unmodifiable collection containing the relation
     *         definitions which refer directly to this managed object
     *         definition.
     */
    public final Collection<RelationDefinition<C, S>> getReverseRelationDefinitions() {
        return Collections.unmodifiableCollection(reverseRelationDefinitions);
    }
 
    /**
     * Get the specified aggregation property definition associated with this
     * type of managed object.The search will include any inherited aggregation
     * property definitions.
     *
     * @param name
     *            The name of the aggregation property definition to be
     *            retrieved.
     * @return Returns the specified aggregation property definition associated
     *         with this type of managed object.
     * @throws IllegalArgumentException
     *             If the specified aggregation property name was null or empty
     *             or if the requested aggregation property definition was not
     *             found.
     */
    public final AggregationPropertyDefinition<?, ?> getAggregationPropertyDefinition(String name) {
        if ((name == null) || (name.length() == 0)) {
            throw new IllegalArgumentException("null or empty aggregation property name");
        }
 
        AggregationPropertyDefinition<?, ?> d = allAggregationPropertyDefinitions.get(name);
        if (d == null) {
            throw new IllegalArgumentException("aggregation property definition \"" + name + "\" not found");
        }
 
        return d;
    }
 
    /**
     * Get the aggregation property definitions defined by this managed object
     * definition. The returned collection will not contain inherited
     * aggregation property definitions.
     *
     * @return Returns an unmodifiable collection containing the aggregation
     *         property definitions defined by this managed object definition.
     */
    public final Collection<AggregationPropertyDefinition<?, ?>> getAggregationPropertyDefinitions() {
        return Collections.unmodifiableCollection(aggregationPropertyDefinitions.values());
    }
 
    /**
     * Get the aggregation property definitions which refer directly to this
     * managed object definition. The returned collection will not contain
     * aggregation property definitions which refer to parents of this managed
     * object definition.
     *
     * @return Returns an unmodifiable collection containing the aggregation
     *         property definitions which refer directly to this managed object
     *         definition.
     */
    public final Collection<AggregationPropertyDefinition<?, ?>> getReverseAggregationPropertyDefinitions() {
        return Collections.unmodifiableCollection(reverseAggregationPropertyDefinitions);
    }
 
    /**
     * Gets the synopsis of this managed object definition in the default
     * locale.
     *
     * @return Returns the synopsis of this managed object definition in the
     *         default locale.
     * @throws UnsupportedOperationException
     *             If this managed object definition is the {@link TopCfgDefn}.
     */
    public final LocalizableMessage getSynopsis() {
        return getSynopsis(Locale.getDefault());
    }
 
    /**
     * Gets the synopsis of this managed object definition in the specified
     * locale.
     *
     * @param locale
     *            The locale.
     * @return Returns the synopsis of this managed object definition in the
     *         specified locale.
     * @throws UnsupportedOperationException
     *             If this managed object definition is the {@link TopCfgDefn}.
     */
    public final LocalizableMessage getSynopsis(Locale locale) {
        return ManagedObjectDefinitionI18NResource.getInstance().getMessage(this, "synopsis", locale);
    }
 
    /**
     * Gets the user friendly name of this managed object definition in the
     * default locale.
     *
     * @return Returns the user friendly name of this managed object definition
     *         in the default locale.
     * @throws UnsupportedOperationException
     *             If this managed object definition is the {@link TopCfgDefn}.
     */
    public final LocalizableMessage getUserFriendlyName() {
        return getUserFriendlyName(Locale.getDefault());
    }
 
    /**
     * Gets the user friendly name of this managed object definition in the
     * specified locale.
     *
     * @param locale
     *            The locale.
     * @return Returns the user friendly name of this managed object definition
     *         in the specified locale.
     * @throws UnsupportedOperationException
     *             If this managed object definition is the {@link TopCfgDefn}.
     */
    public final LocalizableMessage getUserFriendlyName(Locale locale) {
        return LocalizableMessage.raw(ManagedObjectDefinitionI18NResource.getInstance().getMessage(this,
            "user-friendly-name", locale));
    }
 
    /**
     * Gets the user friendly plural name of this managed object definition in
     * the default locale.
     *
     * @return Returns the user friendly plural name of this managed object
     *         definition in the default locale.
     * @throws UnsupportedOperationException
     *             If this managed object definition is the {@link TopCfgDefn}.
     */
    public final LocalizableMessage getUserFriendlyPluralName() {
        return getUserFriendlyPluralName(Locale.getDefault());
    }
 
    /**
     * Gets the user friendly plural name of this managed object definition in
     * the specified locale.
     *
     * @param locale
     *            The locale.
     * @return Returns the user friendly plural name of this managed object
     *         definition in the specified locale.
     * @throws UnsupportedOperationException
     *             If this managed object definition is the {@link TopCfgDefn}.
     */
    public final LocalizableMessage getUserFriendlyPluralName(Locale locale) {
        return ManagedObjectDefinitionI18NResource.getInstance()
            .getMessage(this, "user-friendly-plural-name", locale);
    }
 
    /**
     * Determine whether there are any child managed object definitions which
     * inherit from this managed object definition.
     *
     * @return Returns <code>true</code> if this type of managed object has any
     *         child managed object definitions, <code>false</code> otherwise.
     */
    public final boolean hasChildren() {
        return !children.isEmpty();
    }
 
    /**
     * Determines whether or not this managed object definition has the
     * specified option.
     *
     * @param option
     *            The option to test.
     * @return Returns <code>true</code> if the option is set, or
     *         <code>false</code> otherwise.
     */
    public final boolean hasOption(ManagedObjectOption option) {
        return options.contains(option);
    }
 
    /**
     * Determines whether or not this managed object definition has the
     * specified tag.
     *
     * @param t
     *            The tag definition.
     * @return Returns <code>true</code> if this managed object definition has
     *         the specified tag.
     */
    public final boolean hasTag(Tag t) {
        return allTags.contains(t);
    }
 
    /**
     * Determines whether or not this managed object definition is a sub-type of
     * the provided managed object definition. This managed object definition is
     * a sub-type of the provided managed object definition if they are both the
     * same or if the provided managed object definition can be obtained by
     * recursive invocations of the {@link #getParent()} method.
     *
     * @param d
     *            The managed object definition to be checked.
     * @return Returns <code>true</code> if this managed object definition is a
     *         sub-type of the provided managed object definition.
     */
    public final boolean isChildOf(AbstractManagedObjectDefinition<?, ?> d) {
        AbstractManagedObjectDefinition<?, ?> i;
        for (i = this; i != null; i = i.parent) {
            if (i == d) {
                return true;
            }
        }
        return false;
    }
 
    /**
     * Determines whether or not this managed object definition is a super-type
     * of the provided managed object definition. This managed object definition
     * is a super-type of the provided managed object definition if they are
     * both the same or if the provided managed object definition is a member of
     * the set of children returned from {@link #getAllChildren()}.
     *
     * @param d
     *            The managed object definition to be checked.
     * @return Returns <code>true</code> if this managed object definition is a
     *         super-type of the provided managed object definition.
     */
    public final boolean isParentOf(AbstractManagedObjectDefinition<?, ?> d) {
        return d.isChildOf(this);
    }
 
    /**
     * Determines whether or not this managed object definition is the
     * {@link TopCfgDefn}.
     *
     * @return Returns <code>true</code> if this managed object definition is
     *         the {@link TopCfgDefn}.
     */
    public final boolean isTop() {
        return (this instanceof TopCfgDefn);
    }
 
    /**
     * Finds a sub-type of this managed object definition which most closely
     * corresponds to the matching criteria of the provided definition resolver.
     *
     * @param r
     *            The definition resolver.
     * @return Returns the sub-type of this managed object definition which most
     *         closely corresponds to the matching criteria of the provided
     *         definition resolver.
     * @throws DefinitionDecodingException
     *             If no matching sub-type could be found or if the resolved
     *             definition was abstract.
     * @see DefinitionResolver
     */
    public final ManagedObjectDefinition<? extends C, ? extends S> resolveManagedObjectDefinition(DefinitionResolver r)
            throws DefinitionDecodingException {
        AbstractManagedObjectDefinition<? extends C, ? extends S> rd;
        rd = resolveManagedObjectDefinitionAux(this, r);
        if (rd == null) {
            // Unable to resolve the definition.
            throw new DefinitionDecodingException(this, Reason.WRONG_TYPE_INFORMATION);
        } else if (rd instanceof ManagedObjectDefinition) {
            return (ManagedObjectDefinition<? extends C, ? extends S>) rd;
        } else {
            // Resolved definition was abstract.
            throw new DefinitionDecodingException(this, Reason.ABSTRACT_TYPE_INFORMATION);
        }
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public final String toString() {
        StringBuilder builder = new StringBuilder();
        toString(builder);
        return builder.toString();
    }
 
    /**
     * Append a string representation of the managed object definition to the
     * provided string builder.
     *
     * @param builder
     *            The string builder where the string representation should be
     *            appended.
     */
    public final void toString(StringBuilder builder) {
        builder.append(getName());
    }
 
    /**
     * Initializes all of the components associated with this managed object
     * definition.
     *
     * @throws Exception
     *             If this managed object definition could not be initialized.
     */
    protected final void initialize() throws Exception {
        for (PropertyDefinition<?> pd : getAllPropertyDefinitions()) {
            pd.initialize();
            pd.getDefaultBehaviorProvider().initialize();
        }
 
        for (RelationDefinition<?, ?> rd : getAllRelationDefinitions()) {
            rd.initialize();
        }
 
        for (AggregationPropertyDefinition<?, ?> apd : getAllAggregationPropertyDefinitions()) {
 
            apd.initialize();
            /*
             * Now register the aggregation property in the referenced managed
             * object definition for reverse lookups.
             */
            registerReverseAggregationPropertyDefinition(apd);
        }
 
        for (Constraint constraint : getAllConstraints()) {
            constraint.initialize();
        }
    }
 
    /**
     * Register a constraint with this managed object definition.
     * <p>
     * This method <b>must not</b> be called by applications.
     *
     * @param constraint
     *            The constraint to be registered.
     */
    protected final void registerConstraint(Constraint constraint) {
        constraints.add(constraint);
    }
 
    /**
     * Register a property definition with this managed object definition,
     * overriding any existing property definition with the same name.
     * <p>
     * This method <b>must not</b> be called by applications.
     *
     * @param d
     *            The property definition to be registered.
     */
    protected final void registerPropertyDefinition(PropertyDefinition<?> d) {
        String propName = d.getName();
 
        propertyDefinitions.put(propName, d);
        allPropertyDefinitions.put(propName, d);
 
        if (d instanceof AggregationPropertyDefinition<?, ?>) {
            AggregationPropertyDefinition<?, ?> apd = (AggregationPropertyDefinition<?, ?>) d;
            aggregationPropertyDefinitions.put(propName, apd);
            // The key must also contain the managed object name, since several
            // MOs
            // in an inheritance tree may aggregate the same aggregation
            // property name
            allAggregationPropertyDefinitions.put(apd.getManagedObjectDefinition().getName() + ":" + propName, apd);
        }
    }
 
    /**
     * Register a relation definition with this managed object definition,
     * overriding any existing relation definition with the same name.
     * <p>
     * This method <b>must not</b> be called by applications.
     *
     * @param d
     *            The relation definition to be registered.
     */
    protected final void registerRelationDefinition(RelationDefinition<?, ?> d) {
        // Register the relation in this managed object definition.
        String relName = d.getName();
 
        relationDefinitions.put(relName, d);
        allRelationDefinitions.put(relName, d);
 
        // Now register the relation in the referenced managed object
        // definition for reverse lookups.
        registerReverseRelationDefinition(d);
    }
 
    /**
     * Register an option with this managed object definition.
     * <p>
     * This method <b>must not</b> be called by applications.
     *
     * @param option
     *            The option to be registered.
     */
    protected final void registerOption(ManagedObjectOption option) {
        options.add(option);
    }
 
    /**
     * Register a tag with this managed object definition.
     * <p>
     * This method <b>must not</b> be called by applications.
     *
     * @param tag
     *            The tag to be registered.
     */
    protected final void registerTag(Tag tag) {
        allTags.add(tag);
    }
 
    /**
     * Deregister a constraint from the managed object definition.
     * <p>
     * This method <b>must not</b> be called by applications and is only
     * intended for internal testing.
     *
     * @param constraint
     *            The constraint to be deregistered.
     */
    final void deregisterConstraint(Constraint constraint) {
        if (!constraints.remove(constraint)) {
            throw new RuntimeException("Failed to deregister a constraint");
        }
    }
 
    /**
     * Deregister a relation definition from the managed object definition.
     * <p>
     * This method <b>must not</b> be called by applications and is only
     * intended for internal testing.
     *
     * @param d
     *            The relation definition to be deregistered.
     */
    final void deregisterRelationDefinition(RelationDefinition<?, ?> d) {
        // Deregister the relation from this managed object definition.
        String relName = d.getName();
        relationDefinitions.remove(relName);
        allRelationDefinitions.remove(relName);
 
        // Now deregister the relation from the referenced managed object
        // definition for reverse lookups.
        d.getChildDefinition().reverseRelationDefinitions.remove(d);
    }
 
    /**
     * Register this managed object definition in its parent.
     * <p>
     * This method <b>must not</b> be called by applications and is only
     * intended for internal testing.
     */
    final void registerInParent() {
        if (parent != null) {
            parent.children.put(name, this);
        }
    }
 
    // Register a relation definition in the referenced managed object
    // definition's reverse lookup table.
    private <C1 extends ConfigurationClient, S1 extends Configuration> void registerReverseRelationDefinition(
        RelationDefinition<C1, S1> rd) {
        rd.getChildDefinition().reverseRelationDefinitions.add(rd);
    }
 
    // Register a aggregation property definition in the referenced managed
    // object
    // definition's reverse lookup table.
    private void registerReverseAggregationPropertyDefinition(AggregationPropertyDefinition<?, ?> apd) {
 
        apd.getRelationDefinition().getChildDefinition().reverseAggregationPropertyDefinitions.add(apd);
    }
 
    // Recursively descend definition hierarchy to find the best match
    // definition.
    private AbstractManagedObjectDefinition<? extends C, ? extends S> resolveManagedObjectDefinitionAux(
        AbstractManagedObjectDefinition<? extends C, ? extends S> d, DefinitionResolver r) {
        if (!r.matches(d)) {
            return null;
        }
 
        for (AbstractManagedObjectDefinition<? extends C, ? extends S> child : d.getChildren()) {
            AbstractManagedObjectDefinition<? extends C, ? extends S> rd =
                resolveManagedObjectDefinitionAux(child, r);
            if (rd != null) {
                return rd;
            }
        }
 
        return d;
    }
}