preprocessor.xsl revision 1008
0N/A<!-- CDDL HEADER START 0N/A ! The contents of this file are subject to the terms of the 0N/A ! Common Development and Distribution License, Version 1.0 only 0N/A ! (the "License"). You may not use this file except in compliance 0N/A ! You can obtain a copy of the license at 0N/A ! See the License for the specific language governing permissions 0N/A ! and limitations under the License. 0N/A ! When distributing Covered Code, include this CDDL HEADER in each 0N/A ! file and include the License file at 0N/A ! add the following below this CDDL HEADER, with the fields enclosed 0N/A ! by brackets "[]" replaced with your own identifying information: 1472N/A ! Portions Copyright [yyyy] [name of copyright owner] 0N/A ! Portions Copyright 2007 Sun Microsystems, Inc. 0N/A <
xsl:
output method="xml" indent="yes" />
0N/A Global parameter: the absolute path of the base directory where 0N/A XML managed object definitions can be found. 0N/A <
xsl:
param name="base-dir" select="'.'" />
0N/A Get an absolute URI from a package, object name, and suffix. 0N/A <
xsl:
template name="get-uri">
0N/A <
xsl:
param name="package" select="/.." />
0N/A <
xsl:
param name="name" select="/.." />
0N/A <
xsl:
param name="suffix" select="'.xml'" />
0N/A Convert the package name to a relative path. 0N/A <
xsl:
variable name="rpath" select="translate($package, '.', '/')" />
0N/A Convert the managed object name to a file name. 0N/A <
xsl:
variable name="java-name">
0N/A <
xsl:
call-
template name="name-to-java">
0N/A <
xsl:
with-
param name="value" select="$name" />
0N/A </
xsl:
call-
template>
0N/A Get the absolute path. 0N/A select="concat($base-dir, '/', $rpath, '/', $java-name, $suffix)" />
0N/A Get the URI of the named package definition. 0N/A <
xsl:
template name="get-package-uri">
1879N/A <
xsl:
param name="package" select="/.." />
1879N/A <
xsl:
call-
template name="get-uri">
<
xsl:
with-
param name="package" select="$package" />
<
xsl:
with-
param name="name" select="'package'" />
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')" />
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.'" />
select="adm:root-managed-object | adm:managed-object" 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">
select="'Managed object definition does not specify managed object name.'" />
<
xsl:
if test="not(@package)">
<
xsl:
message terminate="yes">
select="'Managed object definition does not specify managed object package.'" />
<
xsl:
variable name="parent-name" select="@extends" />
<
xsl:
variable name="parent-package">
The parent package defaults to this managed object's package. <
xsl:
when test="@parent-package">
<
xsl:
value-
of select="@parent-package" />
<
xsl:
value-
of select="@package" />
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:
if test="not(document($uri)/adm:managed-object)">
<
xsl:
message terminate="yes">
select="concat('No managed object definition found in ', $uri, '.')" />
test="not(document($uri)/adm:managed-object[@name=$parent-name and @package=$parent-package])">
<
xsl:
message terminate="yes">
select="concat('Managed object definition found in ', $uri, ' but it did not define a managed object ', $parent-name, ' in package ', $parent-package, '.')" />
<
xsl:
apply-
templates select="document($uri)/adm:managed-object" <
xsl:
variable name="hierarchy" select="exsl:node-set($_hierarchy)" />
Now pre-process this managed object. Shallow copy this element and its attributes. <
xsl:
copy-
of select="@*" />
Pre-process this managed object's elements. select="adm:TODO|adm:synopsis|adm:description|adm:profile" <
xsl:
with-
param name="moname" select="@name" />
<
xsl:
with-
param name="mopackage" select="@package" />
<
xsl:
with-
param name="hierarchy" select="$hierarchy" />
Add a pre-processor element defining this managed object's uppermost <
xsl:
if test="$parent-name">
<
xsl:
element name="adm:profile">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="'preprocessor'" />
<
xsl:
element name="admpp:parent-managed-object">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="$parent-name" />
<
xsl:
attribute name="package">
<
xsl:
value-
of select="$parent-package" />
Copy all inherited relations. 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" />
Copy all inherited properties. Copy all local properties. <
xsl:
apply-
templates select="adm:property|adm:property-reference" <
xsl:
with-
param name="moname" select="@name" />
<
xsl:
with-
param name="mopackage" select="@package" />
<
xsl:
with-
param name="hierarchy" select="$hierarchy" />
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. 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" 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" />
test="/adm:property[@name=$name][2] | /adm:property-reference[@name=$name]">
<
xsl:
message terminate="yes">
select="concat('Property definition ', @name, ' is already defined in this managed object')" />
Make sure that this property does not override an existing property. <
xsl:
message terminate="yes">
select="concat('Property definition ', @name, ' is already defined in a parent managed object')" />
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" />
Now append the preprocessor profile. <
xsl:
element name="adm:profile">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="'preprocessor'" />
<
xsl:
element name="admpp:managed-object">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="$moname" />
<
xsl:
attribute name="package">
<
xsl:
value-
of select="$mopackage" />
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" />
test="/adm:property[@name=$name] | /adm:property-reference[@name=$name][2]">
<
xsl:
message terminate="yes">
select="concat('Property definition ', @name, ' is already defined in this managed object')" />
Make sure that this property does not override an existing property. <
xsl:
message terminate="yes">
select="concat('Property reference ', @name, ' is already defined in a parent managed object')" />
Determine the package containing the reference property definition. <
xsl:
variable name="package">
<
xsl:
when test="@package">
<
xsl:
value-
of select="@package" />
<
xsl:
value-
of select="$mopackage" />
Get the referenced package. <
xsl:
variable name="uri">
<
xsl:
call-
template name="get-package-uri">
<
xsl:
with-
param name="package" select="$package" />
<
xsl:
if test="not(document($uri)/adm:package)">
<
xsl:
message terminate="yes">
select="concat('No package definition found in ', $uri, '.')" />
<
xsl:
if test="not(document($uri)/adm:package[@name=$package])">
<
xsl:
message terminate="yes">
select="concat('Package definition found in ', $uri, ' but it did not define package ', $package, '.')" />
test="not(document($uri)/adm:package[@name=$package]/adm:property[@name=$name])">
<
xsl:
message terminate="yes">
select="concat('Referenced property definition "', $name, '" not found in package definition "', $package, 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:
with-
param name="mopackage" select="$mopackage" />
<
xsl:
with-
param name="moname" select="$moname" />
<
xsl:
with-
param name="hierarchy" select="$hierarchy" />
<
xsl:
when test="adm:requires-admin-action">
<
xsl:
apply-
templates select="adm:requires-admin-action" <
xsl:
with-
param name="mopackage" select="$mopackage" />
<
xsl:
with-
param name="moname" select="$moname" />
<
xsl:
with-
param name="hierarchy" select="$hierarchy" />
<
xsl:
with-
param name="mopackage" select="$mopackage" />
<
xsl:
with-
param name="moname" select="$moname" />
<
xsl:
with-
param name="hierarchy" select="$hierarchy" />
<
xsl:
when test="adm:default-behavior">
<
xsl:
apply-
templates select="adm:default-behavior" <
xsl:
with-
param name="mopackage" select="$mopackage" />
<
xsl:
with-
param name="moname" select="$moname" />
<
xsl:
with-
param name="hierarchy" select="$hierarchy" />
<
xsl:
apply-
templates select="$property/adm:default-behavior" <
xsl:
with-
param name="mopackage" select="$mopackage" />
<
xsl:
with-
param name="moname" select="$moname" />
<
xsl:
with-
param name="hierarchy" select="$hierarchy" />
<
xsl:
with-
param name="mopackage" select="$mopackage" />
<
xsl:
with-
param name="moname" select="$moname" />
<
xsl:
with-
param name="hierarchy" select="$hierarchy" />
Now append the preprocessor profile. <
xsl:
element name="adm:profile">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="'preprocessor'" />
<
xsl:
element name="admpp:managed-object">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="$moname" />
<
xsl:
attribute name="package">
<
xsl:
value-
of select="$mopackage" />
<
xsl:
element name="admpp:package">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="$package" />
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:
message terminate="yes">
select="concat('Relation ', $name, ' is already defined in a parent managed object.')" />
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">
select="concat('Relation ', $name, ' is already defined in this managed object.')" />
Now get the referenced managed object. <
xsl:
variable name="mname">
<
xsl:
when test="not(@managed-object-name)">
<
xsl:
value-
of select="$name" />
<
xsl:
value-
of select="@managed-object-name" />
<
xsl:
variable name="mpackage">
<
xsl:
when test="not(@managed-object-package)">
<
xsl:
value-
of select="$mopackage" />
<
xsl:
value-
of select="@managed-object-package" />
<
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:
variable name="managed-object" select="document($uri)/adm:managed-object[@name=$mname]" />
<
xsl:
if test="not($managed-object)">
<
xsl:
message terminate="yes">
select="concat('Managed object definition "', $mname, '" not found in ', $uri, '.')" />
<
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" />
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:
copy-
of select="adm:TODO" />
Copy synopsis element from referenced managed object if it is undefined. <
xsl:
when test="adm:synopsis">
<
xsl:
apply-
templates select="adm:synopsis" <
xsl:
with-
param name="managed-object" select="$managed-object" />
<
xsl:
with-
param name="managed-object" select="$managed-object" />
Copy description element from referenced managed object if it is undefined. <
xsl:
when test="adm:description">
<
xsl:
apply-
templates select="adm:description" <
xsl:
with-
param name="managed-object" select="$managed-object" />
<
xsl:
with-
param name="managed-object" select="$managed-object" />
Merge remaining elements. select="*[not(self::adm:TODO|self::adm:synopsis|self::adm:description)]" <
xsl:
with-
param name="managed-object" select="$managed-object" />
Now append the preprocessor profile. <
xsl:
element name="adm:profile">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="'preprocessor'" />
<
xsl:
element name="admpp:managed-object">
<
xsl:
attribute name="name">
<
xsl:
value-
of select="$moname" />
<
xsl:
attribute name="package">
<
xsl:
value-
of select="$mopackage" />
Default template for merging relations. <
xsl:
template match="*|comment()" mode="merge-relation">
<
xsl:
param name="managed-object" select="/.." />
<
xsl:
copy-
of select="@*" />
<
xsl:
apply-
templates mode="merge-relation">
<
xsl:
with-
param name="managed-object" select="$managed-object" />
Merge a one-to-many relation. <
xsl:
template match="adm:one-to-many" mode="merge-relation">
<
xsl:
param name="managed-object" select="/.." />
<
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:
apply-
templates mode="merge-relation">
<
xsl:
with-
param name="managed-object" select="$managed-object" />
Process a rich-description element in a relation. <
xsl:
template match="adm:synopsis|adm:description" <
xsl:
param name="managed-object" select="/.." />
<
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:
with-
param name="ufpn">
<
xsl:
call-
template name="name-to-ufn">
<
xsl:
with-
param name="value" select="$managed-object/@plural-name" />
Process a rich-description element. match="adm:synopsis|adm:description|adm:unit-description" <
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" />
Process a user-friendly-name element. <
xsl:
template match="adm:user-friendly-name" <
xsl:
param name="ufn" select="/.." />
<
xsl:
value-
of select="$ufn" />
Process a user-friendly-plural-name element. <
xsl:
template match="adm:user-friendly-plural-name" <
xsl:
param name="ufpn" select="/.." />
<
xsl:
value-
of select="$ufpn" />
Process a product-name element. <
xsl:
template match="adm:product-name" mode="rich-description">
<
xsl:
value-
of select="$product-name" />
Default template for rich descriptions. <
xsl:
template match="*|comment()" mode="rich-description">
<
xsl:
param name="ufn" select="/.." />
<
xsl:
param name="ufpn" select="/.." />
<
xsl:
copy-
of select="@*" />
<
xsl:
apply-
templates mode="rich-description">
<
xsl:
with-
param name="ufn" select="$ufn" />
<
xsl:
with-
param name="ufpn" select="$ufpn" />
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-
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" />
Useful variables relating to the current managed object. FIXME: should get this from the root configuration but for some reason we get a circular dependency error when constructing <
xsl:
variable name="product-name" select="'OpenDS Directory Server'" />
<
xsl:
variable name="this-name">
<
xsl:
when test="/adm:managed-object">
<
xsl:
value-
of select="/adm:managed-object/@name" />
Must be the root configuration. <
xsl:
value-
of select="'root'" />
<
xsl:
variable name="this-plural-name">
<
xsl:
when test="/adm:managed-object">
<
xsl:
value-
of select="/adm:managed-object/@plural-name" />
Must be the root configuration - the plural form should never be required as this is a singleton. We'll define it for <
xsl:
value-
of select="'roots'" />
<
xsl:
variable name="this-ufn">
<
xsl:
call-
template name="name-to-ufn">
<
xsl:
with-
param name="value" select="$this-name" />
<
xsl:
variable name="this-ufpn">
<
xsl:
call-
template name="name-to-ufn">
<
xsl:
with-
param name="value" select="$this-plural-name" />
<
xsl:
variable name="_this">
<
xsl:
call-
template name="pre-process-managed-object" />
<
xsl:
variable name="_this_tmp" select="exsl:node-set($_this)" />
<
xsl:
variable name="this" <
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:
when test="not($this-is-root)">
<
xsl:
value-
of select="$this/@package" />
<
xsl:
variable name="this-java-class">
<
xsl:
call-
template name="name-to-java">
<
xsl:
with-
param name="value" select="$this-name" />
<
xsl:
variable name="this-short-name">
<
xsl:
variable name="top-name" select="$this/adm:profile[@name='preprocessor']/admpp:parent-managed-object[last()]/@name" />
<
xsl:
when test="$this-is-root">
<
xsl:
value-
of select="''" />
<
xsl:
when test="not($top-name)">
<
xsl:
value-
of select="''" />
<
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)" />
select="substring($this-name, $diff + 1, $top-length)" />
<
xsl:
if test="$middle != '-' or $end != $top-name">
<
xsl:
message terminate="yes">
select="concat('The managed object ', $this-name, ' should end with ', $top-name)" />
<
xsl:
value-
of select="$start" />
<
xsl:
variable name="this-short-java-class">
<
xsl:
call-
template name="name-to-java">
<
xsl:
with-
param name="value" select="$this-short-name" />
Useful variables relating to the parent managed object. <
xsl:
variable name="parent-name" select="$this/@extends" />
<
xsl:
variable name="parent-package">
<
xsl:
when test="$this/@parent-package">
<
xsl:
value-
of select="$this/@parent-package" />
<
xsl:
value-
of select="$this-package" />
<
xsl:
variable name="parent-java-class">
<
xsl:
call-
template name="name-to-java">
<
xsl:
with-
param name="value" select="$parent-name" />
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:
copy-
of select="$this" />