preprocessor.xsl revision 1884
<
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. <
xsl:
variable name="property-overrides" select="adm:property-override" />
Copy all local properties. select="adm:property|adm:property-reference|adm:property-override" <
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 tag and validate it and by adding a "preprocessor" profile which contains information about where the tag was defined. <
xsl:
template match="adm:tag" mode="pre-process">
<
xsl:
param name="mopackage" select="/.." />
<
xsl:
param name="moname" select="/.." />
<
xsl:
param name="hierarchy" />
Make sure that this tag is not duplicated. <
xsl:
variable name="name" select="@name" />
<
xsl:
if test="/adm:tag[@name=$name][2]">
<
xsl:
message terminate="yes">
select="concat('Tag ', @name, ' is already defined in this managed object')" />
Make sure that this tag does not override an existing tag. <
xsl:
message terminate="yes">
select="concat('Tag ', @name, ' is already defined in a parent managed object')" />
Get the referenced package. <
xsl:
variable name="uri">
<
xsl:
call-
template name="get-managed-object-uri">
<
xsl:
with-
param name="package" <
xsl:
with-
param name="name" select="'root'" />
<
xsl:
if test="not(document($uri)/adm:root-managed-object)">
<
xsl:
message terminate="yes">
select="concat('Root managed object definition not found in ', $uri, '.')" />
<
xsl:
message terminate="yes">
select="concat('Tag "', $name, '" not defined in root managed object definition.')" />
<
xsl:
element name="adm:tag">
<
xsl:
copy-
of select="@*" />
<
xsl:
apply-
templates mode="pre-process">
<
xsl:
with-
param name="moname" select="$moname" />
<
xsl:
with-
param name="mopackage" select="$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 property override pulling in the inherited property definition and by adding a "preprocessor" profile which contains information about where the property was redefined. <
xsl:
template match="adm:property-override" mode="pre-process">
<
xsl:
param name="mopackage" select="/.." />
<
xsl:
param name="moname" select="/.." />
<
xsl:
param name="hierarchy" />
Make sure that this property override does not have the same name as another property override in this managed object. <
xsl:
variable name="name" select="@name" />
<
xsl:
if test="/adm:property-override[@name=$name][2]">
<
xsl:
message terminate="yes">
select="concat('Property override ', @name, ' is already overridden in this managed object')" />
Make sure that this property overrides an existing property. <
xsl:
message terminate="yes">
select="concat('Cannot find inherited property ', @name, ' for property override')" />
Copy the inherited property definition taking care to override the default behavior and admin action if required. <
xsl:
variable name="property" <
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" />
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="/.." />
Make sure that if this relation uses a naming property that the naming property exists, is single-valued, mandatory, and read-only. <
xsl:
if test="@naming-property">
<
xsl:
variable name="naming-property-name" select="@naming-property" />
FIXME: this does not cope with the situation where the property is inherited, referenced, or overridden. <
xsl:
variable name="naming-property" <
xsl:
if test="not($naming-property)">
<
xsl:
message terminate="yes">
select="concat('Relation ', ../@name, ' references an unknown naming property ', $naming-property-name, ' in ', $managed-object/@name, '.')" />
<
xsl:
if test="not($naming-property/@read-only='true')">
<
xsl:
message terminate="yes">
select="concat('Relation ', ../@name, ' references the naming property ', $naming-property-name, ' in ', $managed-object/@name, ' which is not read-only. ', 'Naming properties must be read-only.')" />
<
xsl:
if test="not($naming-property/@mandatory='true')">
<
xsl:
message terminate="yes">
select="concat('Relation ', ../@name, ' references the naming property ', $naming-property-name, ' in ', $managed-object/@name, ' which is not mandatory. ', 'Naming properties must be mandatory.')" />
<
xsl:
if test="$naming-property/@multi-valued='true'">
<
xsl:
message terminate="yes">
select="concat('Relation ', ../@name, ' references the naming property ', $naming-property-name, ' in ', $managed-object/@name, ' which is multi-valued. ', 'Naming properties must be single-valued.')" />
<
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 relative inherited default behavior <
xsl:
template match="adm:relative" mode="pre-process">
<
xsl:
param name="mopackage" select="/.." />
<
xsl:
param name="moname" select="/.." />
<
xsl:
param name="hierarchy" select="/.." />
<
xsl:
copy-
of select="@*" />
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="$mopackage" />
Apply templates to subordinate elements. <
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" />
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="_top-name" select="$this/adm:profile[@name='preprocessor']/admpp:parent-managed-object[last()]/@name" />
<
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:
variable name="this-short-name">
<
xsl:
when test="$this-is-root">
<
xsl:
value-
of select="''" />
<
xsl:
when test="not($_top-name)">
<
xsl:
value-
of select="''" />
<
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" />