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

matthew_swift
23.26.2007 feb5d90ec016c99712f19c5485cf7633cd38f111
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
<!-- 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.
  ! -->
<xsl:stylesheet version="1.0" xmlns:adm="http://www.opends.org/admin"
  xmlns:admpp="http://www.opends.org/admin-preprocessor"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common">
  <xsl:import href="java-utilities.xsl" />
  <xsl:output method="xml" indent="yes" />
  <!--
    Global parameter: the absolute path of the base directory where
    XML managed object definitions can be found.
  -->
  <xsl:param name="base-dir" select="'.'" />
  <!-- 
    Get an absolute URI from a package, object name, and suffix.
  -->
  <xsl:template name="get-uri">
    <xsl:param name="package" select="/.." />
    <xsl:param name="name" select="/.." />
    <xsl:param name="suffix" select="'.xml'" />
    <!--
      Convert the package name to a relative path.
    -->
    <xsl:variable name="rpath" select="translate($package, '.', '/')" />
    <!-- 
      Convert the managed object name to a file name.
    -->
    <xsl:variable name="java-name">
      <xsl:call-template name="name-to-java">
        <xsl:with-param name="value" select="$name" />
      </xsl:call-template>
    </xsl:variable>
    <!--
      Get the absolute path.
    -->
    <xsl:value-of
      select="concat($base-dir, '/', $rpath, '/', $java-name, $suffix)" />
  </xsl:template>
  <!--
    Get the URI of the named package definition.
  -->
  <xsl:template name="get-package-uri">
    <xsl:param name="package" select="/.." />
    <xsl:call-template name="get-uri">
      <xsl:with-param name="package" select="$package" />
      <xsl:with-param name="name" select="'package'" />
    </xsl:call-template>
  </xsl:template>
  <!--
    Get the URI of the named managed object definition.
  -->
  <xsl:template name="get-managed-object-uri">
    <xsl:param name="package" select="/.." />
    <xsl:param name="name" select="/.." />
    <xsl:call-template name="get-uri">
      <xsl:with-param name="package" select="$package" />
      <xsl:with-param name="name"
        select="concat($name, '-configuration')" />
    </xsl:call-template>
  </xsl:template>
  <!--
    Pre-process the current managed object element.
  -->
  <xsl:template name="pre-process-managed-object">
    <xsl:if test="not(adm:root-managed-object | adm:managed-object)">
      <xsl:message terminate="yes">
        <xsl:value-of select="'No managed object definition found.'" />
      </xsl:message>
    </xsl:if>
    <xsl:apply-templates
      select="adm:root-managed-object | adm:managed-object"
      mode="pre-process" />
  </xsl:template>
  <!--
    Pre-process a managed object definition: pull in the managed object's
    inherited property definitions and relations.
  -->
  <xsl:template match="adm:managed-object" mode="pre-process">
    <xsl:if test="not(@name)">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="'Managed object definition does not specify managed object name.'" />
      </xsl:message>
    </xsl:if>
    <xsl:if test="not(@package)">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="'Managed object definition does not specify managed object package.'" />
      </xsl:message>
    </xsl:if>
    <xsl:variable name="parent-name" select="@extends" />
    <xsl:variable name="parent-package">
      <!--
        The parent package defaults to this managed object's package.
      -->
      <xsl:choose>
        <xsl:when test="@parent-package">
          <xsl:value-of select="@parent-package" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@package" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!--
      Get this managed object's hierarchy if there is one.
    -->
    <xsl:variable name="_hierarchy">
      <xsl:if test="$parent-name">
        <xsl:variable name="uri">
          <xsl:call-template name="get-managed-object-uri">
            <xsl:with-param name="package" select="$parent-package" />
            <xsl:with-param name="name" select="$parent-name" />
          </xsl:call-template>
        </xsl:variable>
        <xsl:if test="not(document($uri)/adm:managed-object)">
          <xsl:message terminate="yes">
            <xsl:value-of
              select="concat('No managed object definition found in ', $uri, '.')" />
          </xsl:message>
        </xsl:if>
        <xsl:if
          test="not(document($uri)/adm:managed-object[@name=$parent-name and @package=$parent-package])">
          <xsl:message terminate="yes">
            <xsl:value-of
              select="concat('Managed object definition found in ', $uri, ' but it did not define a managed object ', $parent-name, ' in package ', $parent-package, '.')" />
          </xsl:message>
        </xsl:if>
        <xsl:apply-templates select="document($uri)/adm:managed-object"
          mode="pre-process" />
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="hierarchy" select="exsl:node-set($_hierarchy)" />
    <!--
      Now pre-process this managed object.
    -->
    <xsl:copy>
      <!--
        Shallow copy this element and its attributes.
      -->
      <xsl:copy-of select="@*" />
      <!--
        Pre-process this managed object's elements.
      -->
      <xsl:apply-templates
        select="adm:TODO|adm:synopsis|adm:description|adm:profile"
        mode="pre-process">
        <xsl:with-param name="moname" select="@name" />
        <xsl:with-param name="mopackage" select="@package" />
        <xsl:with-param name="hierarchy" select="$hierarchy" />
      </xsl:apply-templates>
      <!-- 
        Add a pre-processor element defining this managed object's uppermost
        definition.
      -->
      <xsl:if test="$parent-name">
        <xsl:element name="adm:profile">
          <xsl:attribute name="name">
            <xsl:value-of select="'preprocessor'" />
          </xsl:attribute>
          <xsl:element name="admpp:parent-managed-object">
            <xsl:attribute name="name">
              <xsl:value-of select="$parent-name" />
            </xsl:attribute>
            <xsl:attribute name="package">
              <xsl:value-of select="$parent-package" />
            </xsl:attribute>
          </xsl:element>
          <xsl:copy-of
            select="$hierarchy/adm:managed-object/adm:profile[@name='preprocessor']/admpp:parent-managed-object" />
        </xsl:element>
      </xsl:if>
      <!--
        Copy all inherited relations.
      -->
      <xsl:copy-of select="$hierarchy/adm:managed-object/adm:relation" />
      <!--
        Copy all local relations.
      -->
      <xsl:apply-templates select="adm:relation" mode="pre-process">
        <xsl:with-param name="moname" select="@name" />
        <xsl:with-param name="mopackage" select="@package" />
        <xsl:with-param name="hierarchy" select="$hierarchy" />
      </xsl:apply-templates>
      <!--
        Copy all inherited properties.
      -->
      <xsl:copy-of select="$hierarchy/adm:managed-object/adm:property" />
      <!--
        Copy all local properties.
      -->
      <xsl:apply-templates select="adm:property|adm:property-reference"
        mode="pre-process">
        <xsl:with-param name="moname" select="@name" />
        <xsl:with-param name="mopackage" select="@package" />
        <xsl:with-param name="hierarchy" select="$hierarchy" />
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <!--
    Pre-process a managed object definition: pull in the managed object's
    inherited property definitions and relations.
  -->
  <xsl:template match="adm:root-managed-object" mode="pre-process">
    <!--
      Now pre-process this root managed object.
      By definition it has no hierarchy.
    -->
    <xsl:copy>
      <!--
        Shallow copy this element and its attributes.
      -->
      <xsl:copy-of select="@*" />
      <!--
        Pre-process this managed object's elements.
      -->
      <xsl:apply-templates mode="pre-process">
        <xsl:with-param name="moname" select="'root'" />
        <xsl:with-param name="mopackage"
          select="'org.opends.server.admin.std'" />
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <!--
    Pre-process a property definition by adding a "preprocessor" profile
    which contains information about where the property was defined.
  -->
  <xsl:template match="adm:property" mode="pre-process">
    <xsl:param name="mopackage" select="/.." />
    <xsl:param name="moname" select="/.." />
    <xsl:param name="hierarchy" select="/.." />
    <!--
      Make sure that this property does not have the same name as another
      property or reference in this managed object.
    -->
    <xsl:variable name="name" select="@name" />
    <xsl:if
      test="../adm:property[@name=$name][2] |
            ../adm:property-reference[@name=$name]">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Property definition ', @name, ' is already defined in this managed object')" />
      </xsl:message>
    </xsl:if>
    <!--
      Make sure that this property does not override an existing property.
    -->
    <xsl:if
      test="$hierarchy/adm:managed-object/adm:property[@name=$name]">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Property definition ', @name, ' is already defined in a parent managed object')" />
      </xsl:message>
    </xsl:if>
    <xsl:copy>
      <!--
        Shallow copy this element and its attributes.
      -->
      <xsl:copy-of select="@*" />
      <!--
        Apply templates to subordinate elements (e.g. descriptions).
      -->
      <xsl:apply-templates mode="pre-process">
        <xsl:with-param name="mopackage" select="$mopackage" />
        <xsl:with-param name="moname" select="$moname" />
        <xsl:with-param name="hierarchy" select="$hierarchy" />
      </xsl:apply-templates>
      <!--
        Now append the preprocessor profile.
      -->
      <xsl:element name="adm:profile">
        <xsl:attribute name="name">
          <xsl:value-of select="'preprocessor'" />
        </xsl:attribute>
        <xsl:element name="admpp:managed-object">
          <xsl:attribute name="name">
            <xsl:value-of select="$moname" />
          </xsl:attribute>
          <xsl:attribute name="package">
            <xsl:value-of select="$mopackage" />
          </xsl:attribute>
        </xsl:element>
      </xsl:element>
    </xsl:copy>
  </xsl:template>
  <!--
    Pre-process a property reference pulling in the referenced property
    definition and by adding a "preprocessor" profile which contains
    information about where the property was defined.
  -->
  <xsl:template match="adm:property-reference" mode="pre-process">
    <xsl:param name="mopackage" select="/.." />
    <xsl:param name="moname" select="/.." />
    <xsl:param name="hierarchy" />
    <!--
      Make sure that this property reference does not have the same name as another
      property or reference in this managed object.
    -->
    <xsl:variable name="name" select="@name" />
    <xsl:if
      test="../adm:property[@name=$name] |
            ../adm:property-reference[@name=$name][2]">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Property definition ', @name, ' is already defined in this managed object')" />
      </xsl:message>
    </xsl:if>
    <!--
      Make sure that this property does not override an existing property.
    -->
    <xsl:if
      test="$hierarchy/adm:managed-object/adm:property[@name=$name]">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Property reference ', @name, ' is already defined in a parent managed object')" />
      </xsl:message>
    </xsl:if>
    <!--
      Determine the package containing the reference property definition.
    -->
    <xsl:variable name="package">
      <xsl:choose>
        <xsl:when test="@package">
          <xsl:value-of select="@package" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$mopackage" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!--
      Get the referenced package.
    -->
    <xsl:variable name="uri">
      <xsl:call-template name="get-package-uri">
        <xsl:with-param name="package" select="$package" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:if test="not(document($uri)/adm:package)">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('No package definition found in ', $uri, '.')" />
      </xsl:message>
    </xsl:if>
    <xsl:if test="not(document($uri)/adm:package[@name=$package])">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Package definition found in ', $uri, ' but it did not define package ', $package, '.')" />
      </xsl:message>
    </xsl:if>
    <xsl:if
      test="not(document($uri)/adm:package[@name=$package]/adm:property[@name=$name])">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Referenced property definition &quot;', $name,
                           '&quot; not found in package definition &quot;', $package,
                           '&quot;.')" />
      </xsl:message>
    </xsl:if>
    <!--
      Copy the referenced property definition taking care to override
      the default behavior and admin action if required.
    -->
    <xsl:variable name="property"
      select="document($uri)/adm:package[@name=$package]/adm:property[@name=$name]" />
    <xsl:element name="adm:property">
      <xsl:copy-of select="$property/@*" />
      <xsl:apply-templates
        select="$property/adm:TODO | $property/adm:synopsis | $property/adm:description"
        mode="pre-process">
        <xsl:with-param name="mopackage" select="$mopackage" />
        <xsl:with-param name="moname" select="$moname" />
        <xsl:with-param name="hierarchy" select="$hierarchy" />
      </xsl:apply-templates>
      <xsl:choose>
        <xsl:when test="adm:requires-admin-action">
          <xsl:apply-templates select="adm:requires-admin-action"
            mode="pre-process">
            <xsl:with-param name="mopackage" select="$mopackage" />
            <xsl:with-param name="moname" select="$moname" />
            <xsl:with-param name="hierarchy" select="$hierarchy" />
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates
            select="$property/adm:requires-admin-action"
            mode="pre-process">
            <xsl:with-param name="mopackage" select="$mopackage" />
            <xsl:with-param name="moname" select="$moname" />
            <xsl:with-param name="hierarchy" select="$hierarchy" />
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="adm:default-behavior">
          <xsl:apply-templates select="adm:default-behavior"
            mode="pre-process">
            <xsl:with-param name="mopackage" select="$mopackage" />
            <xsl:with-param name="moname" select="$moname" />
            <xsl:with-param name="hierarchy" select="$hierarchy" />
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="$property/adm:default-behavior"
            mode="pre-process">
            <xsl:with-param name="mopackage" select="$mopackage" />
            <xsl:with-param name="moname" select="$moname" />
            <xsl:with-param name="hierarchy" select="$hierarchy" />
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates
        select="$property/adm:syntax | $property/adm:profile"
        mode="pre-process">
        <xsl:with-param name="mopackage" select="$mopackage" />
        <xsl:with-param name="moname" select="$moname" />
        <xsl:with-param name="hierarchy" select="$hierarchy" />
      </xsl:apply-templates>
      <!--
        Now append the preprocessor profile.
      -->
      <xsl:element name="adm:profile">
        <xsl:attribute name="name">
          <xsl:value-of select="'preprocessor'" />
        </xsl:attribute>
        <xsl:element name="admpp:managed-object">
          <xsl:attribute name="name">
            <xsl:value-of select="$moname" />
          </xsl:attribute>
          <xsl:attribute name="package">
            <xsl:value-of select="$mopackage" />
          </xsl:attribute>
        </xsl:element>
        <xsl:element name="admpp:package">
          <xsl:attribute name="name">
            <xsl:value-of select="$package" />
          </xsl:attribute>
        </xsl:element>
      </xsl:element>
    </xsl:element>
  </xsl:template>
  <!--
    Pre-process a relation, merging information from the referenced
    managed object where required, and by adding a "preprocessor" profile
    which contains information about where the relation was defined.
  -->
  <xsl:template match="adm:relation" mode="pre-process">
    <xsl:param name="mopackage" select="/.." />
    <xsl:param name="moname" select="/.." />
    <xsl:param name="hierarchy" select="/.." />
    <!--
      Determine the name of the relation.
    -->
    <xsl:variable name="name" select="@name" />
    <!--
      Make sure that this relation does not override an existing relation.
    -->
    <xsl:if
      test="$hierarchy/adm:managed-object/adm:relation[@name=$name]">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Relation ', $name, ' is already defined in a parent managed object.')" />
      </xsl:message>
    </xsl:if>
    <!--
      Make sure that this relation is not already defined in this managed object.
    -->
    <xsl:if test="../adm:relation[@name=$name][2]">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Relation ', $name, ' is already defined in this managed object.')" />
      </xsl:message>
    </xsl:if>
    <!-- 
      Now get the referenced managed object.
    -->
    <xsl:variable name="mname">
      <xsl:choose>
        <xsl:when test="not(@managed-object-name)">
          <xsl:value-of select="$name" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@managed-object-name" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="mpackage">
      <xsl:choose>
        <xsl:when test="not(@managed-object-package)">
          <xsl:value-of select="$mopackage" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@managed-object-package" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="uri">
      <xsl:call-template name="get-managed-object-uri">
        <xsl:with-param name="name" select="$mname" />
        <xsl:with-param name="package" select="$mpackage" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="managed-object"
      select="document($uri)/adm:managed-object[@name=$mname]" />
    <xsl:if test="not($managed-object)">
      <xsl:message terminate="yes">
        <xsl:value-of
          select="concat('Managed object definition &quot;', $mname, '&quot; not found in ', $uri, '.')" />
      </xsl:message>
    </xsl:if>
    <!--
      Now merge the relation.
    -->
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <!--
        Add missing attribute managed-object-name if it is not provided.
      -->
      <xsl:if test="not(@managed-object-name)">
        <xsl:attribute name="managed-object-name">
          <xsl:value-of select="$mname" />
        </xsl:attribute>
      </xsl:if>
      <!--
        Add missing attribute managed-object-package if it is not provided.
      -->
      <xsl:if test="not(@managed-object-package)">
        <xsl:attribute name="managed-object-package">
          <xsl:value-of select="$mpackage" />
        </xsl:attribute>
      </xsl:if>
      <!-- 
        Copy TODO element.
      -->
      <xsl:copy-of select="adm:TODO" />
      <!-- 
        Copy synopsis element from referenced managed object if it is undefined.
      -->
      <xsl:choose>
        <xsl:when test="adm:synopsis">
          <xsl:apply-templates select="adm:synopsis"
            mode="merge-relation">
            <xsl:with-param name="managed-object"
              select="$managed-object" />
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="$managed-object/adm:synopsis"
            mode="merge-relation">
            <xsl:with-param name="managed-object"
              select="$managed-object" />
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
      <!-- 
        Copy description element from referenced managed object if it is undefined.
      -->
      <xsl:choose>
        <xsl:when test="adm:description">
          <xsl:apply-templates select="adm:description"
            mode="merge-relation">
            <xsl:with-param name="managed-object"
              select="$managed-object" />
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="$managed-object/adm:description"
            mode="merge-relation">
            <xsl:with-param name="managed-object"
              select="$managed-object" />
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
      <!--
        Merge remaining elements.
      -->
      <xsl:apply-templates
        select="*[not(self::adm:TODO|self::adm:synopsis|self::adm:description)]"
        mode="merge-relation">
        <xsl:with-param name="managed-object" select="$managed-object" />
      </xsl:apply-templates>
      <!--
        Now append the preprocessor profile.
      -->
      <xsl:element name="adm:profile">
        <xsl:attribute name="name">
          <xsl:value-of select="'preprocessor'" />
        </xsl:attribute>
        <xsl:element name="admpp:managed-object">
          <xsl:attribute name="name">
            <xsl:value-of select="$moname" />
          </xsl:attribute>
          <xsl:attribute name="package">
            <xsl:value-of select="$mopackage" />
          </xsl:attribute>
        </xsl:element>
      </xsl:element>
    </xsl:copy>
  </xsl:template>
  <!--
    Default template for merging relations.
  -->
  <xsl:template match="*|comment()" mode="merge-relation">
    <xsl:param name="managed-object" select="/.." />
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates mode="merge-relation">
        <xsl:with-param name="managed-object" select="$managed-object" />
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <!--
    Merge a one-to-many relation.
  -->
  <xsl:template match="adm:one-to-many" mode="merge-relation">
    <xsl:param name="managed-object" select="/.." />
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <!--
        Add missing plural name attribute if not present.
      -->
      <xsl:if test="not(@plural-name)">
        <xsl:attribute name="plural-name">
          <xsl:value-of select="$managed-object/@plural-name" />
        </xsl:attribute>
      </xsl:if>
      <xsl:apply-templates mode="merge-relation">
        <xsl:with-param name="managed-object" select="$managed-object" />
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <!--
    Process a rich-description element in a relation.
  -->
  <xsl:template match="adm:synopsis|adm:description"
    mode="merge-relation">
    <xsl:param name="managed-object" select="/.." />
    <xsl:copy>
      <!--
        Shallow copy.
      -->
      <xsl:copy-of select="@*" />
      <xsl:apply-templates mode="rich-description">
        <xsl:with-param name="ufn">
          <xsl:call-template name="name-to-ufn">
            <xsl:with-param name="value" select="$managed-object/@name" />
          </xsl:call-template>
        </xsl:with-param>
        <xsl:with-param name="ufpn">
          <xsl:call-template name="name-to-ufn">
            <xsl:with-param name="value"
              select="$managed-object/@plural-name" />
          </xsl:call-template>
        </xsl:with-param>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <!--
    Process a rich-description element.
  -->
  <xsl:template
    match="adm:synopsis|adm:description|adm:unit-description"
    mode="pre-process">
    <xsl:copy>
      <!--
        Shallow copy.
      -->
      <xsl:copy-of select="@*" />
      <xsl:apply-templates mode="rich-description">
        <xsl:with-param name="ufn" select="$this-ufn" />
        <xsl:with-param name="ufpn" select="$this-ufpn" />
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <!--
    Process a user-friendly-name element.
  -->
  <xsl:template match="adm:user-friendly-name"
    mode="rich-description">
    <xsl:param name="ufn" select="/.." />
    <xsl:value-of select="$ufn" />
  </xsl:template>
  <!--
    Process a user-friendly-plural-name element.
  -->
  <xsl:template match="adm:user-friendly-plural-name"
    mode="rich-description">
    <xsl:param name="ufpn" select="/.." />
    <xsl:value-of select="$ufpn" />
  </xsl:template>
  <!--
    Process a product-name element.
  -->
  <xsl:template match="adm:product-name" mode="rich-description">
    <xsl:value-of select="$product-name" />
  </xsl:template>
  <!--
    Default template for rich descriptions.
  -->
  <xsl:template match="*|comment()" mode="rich-description">
    <xsl:param name="ufn" select="/.." />
    <xsl:param name="ufpn" select="/.." />
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates mode="rich-description">
        <xsl:with-param name="ufn" select="$ufn" />
        <xsl:with-param name="ufpn" select="$ufpn" />
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <!--
    Default template for pre-processing.
  -->
  <xsl:template match="*|comment()" mode="pre-process">
    <xsl:param name="mopackage" select="/.." />
    <xsl:param name="moname" select="/.." />
    <xsl:param name="hierarchy" />
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates mode="pre-process">
        <xsl:with-param name="mopackage" select="$mopackage" />
        <xsl:with-param name="moname" select="$moname" />
        <xsl:with-param name="hierarchy" select="$hierarchy" />
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <!--
    Useful variables relating to the current managed object.
  -->
  <!--
    Product name.
    
    FIXME: should get this from the root configuration but for some
    reason we get a circular dependency error when constructing
    the URI in JDK1.6.
  -->
  <xsl:variable name="product-name" select="'OpenDS Directory Server'" />
  <xsl:variable name="this-name">
    <xsl:choose>
      <xsl:when test="/adm:managed-object">
        <xsl:value-of select="/adm:managed-object/@name" />
      </xsl:when>
      <xsl:otherwise>
        <!--
          Must be the root configuration.  
        -->
        <xsl:value-of select="'root'" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="this-plural-name">
    <xsl:choose>
      <xsl:when test="/adm:managed-object">
        <xsl:value-of select="/adm:managed-object/@plural-name" />
      </xsl:when>
      <xsl:otherwise>
        <!--
          Must be the root configuration - the plural form should never
          be required as this is a singleton. We'll define it for
          consistency. 
        -->
        <xsl:value-of select="'roots'" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="this-ufn">
    <xsl:call-template name="name-to-ufn">
      <xsl:with-param name="value" select="$this-name" />
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="this-ufpn">
    <xsl:call-template name="name-to-ufn">
      <xsl:with-param name="value" select="$this-plural-name" />
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="_this">
    <xsl:call-template name="pre-process-managed-object" />
  </xsl:variable>
  <xsl:variable name="_this_tmp" select="exsl:node-set($_this)" />
  <xsl:variable name="this"
    select="$_this_tmp/adm:managed-object | $_this_tmp/adm:root-managed-object" />
  <xsl:variable name="this-is-abstract"
    select="boolean(string($this/@abstract) = 'true')" />
  <xsl:variable name="this-is-root"
    select="not(local-name($this) = 'managed-object')" />
  <xsl:variable name="this-package">
    <xsl:choose>
      <xsl:when test="not($this-is-root)">
        <xsl:value-of select="$this/@package" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="'org.opends.server.admin.std'" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="this-java-class">
    <xsl:call-template name="name-to-java">
      <xsl:with-param name="value" select="$this-name" />
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="this-short-name">
    <xsl:variable name="top-name"
      select="$this/adm:profile[@name='preprocessor']/admpp:parent-managed-object[last()]/@name" />
    <xsl:choose>
      <xsl:when test="$this-is-root">
        <xsl:value-of select="''" />
      </xsl:when>
      <xsl:when test="not($top-name)">
        <xsl:value-of select="''" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name="top-length"
          select="string-length($top-name)" />
        <xsl:variable name="this-length"
          select="string-length($this-name)" />
        <xsl:variable name="diff" select="$this-length - $top-length" />
        <xsl:variable name="start"
          select="substring($this-name, 1, $diff - 1)" />
        <xsl:variable name="middle"
          select="substring($this-name, $diff, 1)" />
        <xsl:variable name="end"
          select="substring($this-name, $diff + 1, $top-length)" />
        <xsl:if test="$middle != '-' or $end != $top-name">
          <xsl:message terminate="yes">
            <xsl:value-of
              select="concat('The managed object ', $this-name, ' should end with ', $top-name)" />
          </xsl:message>
        </xsl:if>
        <xsl:value-of select="$start" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="this-short-java-class">
    <xsl:call-template name="name-to-java">
      <xsl:with-param name="value" select="$this-short-name" />
    </xsl:call-template>
  </xsl:variable>
  <!-- 
    Useful variables relating to the parent managed object.
  -->
  <xsl:variable name="parent-name" select="$this/@extends" />
  <xsl:variable name="parent-package">
    <xsl:choose>
      <xsl:when test="$this/@parent-package">
        <xsl:value-of select="$this/@parent-package" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$this-package" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="parent-java-class">
    <xsl:call-template name="name-to-java">
      <xsl:with-param name="value" select="$parent-name" />
    </xsl:call-template>
  </xsl:variable>
  <!-- 
    Useful variables relating to managed object's relations.
  -->
  <xsl:variable name="this-local-relations"
    select="$this/adm:relation[adm:profile[@name='preprocessor']/admpp:managed-object[@name=$this-name and @package=$this-package]]" />
  <xsl:variable name="this-inherited-relations"
    select="$this/adm:relation[adm:profile[@name='preprocessor']/admpp:managed-object[not(@name=$this-name and @package=$this-package)]]" />
  <xsl:variable name="this-all-relations" select="$this/adm:relation" />
  <!-- 
    Useful variables relating to managed object's properties.
  -->
  <xsl:variable name="this-local-properties"
    select="$this/adm:property[adm:profile[@name='preprocessor']/admpp:managed-object[@name=$this-name and @package=$this-package]]" />
  <xsl:variable name="this-inherited-properties"
    select="$this/adm:property[adm:profile[@name='preprocessor']/admpp:managed-object[not(@name=$this-name and @package=$this-package)]]" />
  <xsl:variable name="this-all-properties" select="$this/adm:property" />
  <!--
    Default rule for testing.
  -->
  <xsl:template match="/">
    <xsl:copy-of select="$this" />
  </xsl:template>
</xsl:stylesheet>