preprocessor.xsl revision 408b8eb145348cb8f251a8abfec96e7e4e80f630
0N/A<!-- CDDL HEADER START
494N/A !
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 ! with the License.
0N/A !
0N/A ! You can obtain a copy of the license at
0N/A ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
0N/A ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
0N/A ! See the License for the specific language governing permissions
0N/A ! and limitations under the License.
0N/A !
0N/A ! When distributing Covered Code, include this CDDL HEADER in each
0N/A ! file and include the License file at
0N/A ! trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
0N/A ! add the following below this CDDL HEADER, with the fields enclosed
0N/A ! by brackets "[]" replaced with your own identifying information:
0N/A ! Portions Copyright [yyyy] [name of copyright owner]
0N/A !
0N/A ! CDDL HEADER END
0N/A !
0N/A !
0N/A ! Portions Copyright 2007 Sun Microsystems, Inc.
0N/A ! -->
0N/A<xsl:stylesheet version="1.0" xmlns:adm="http://www.opends.org/admin"
0N/A xmlns:admpp="http://www.opends.org/admin-preprocessor"
0N/A xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
0N/A xmlns:exsl="http://exslt.org/common">
0N/A <xsl:import href="java-utilities.xsl" />
0N/A <xsl:output method="xml" indent="yes" />
0N/A <!--
0N/A Global parameter: the absolute path of the base directory where
0N/A XML managed object definitions can be found.
0N/A -->
0N/A <xsl:param name="base-dir" select="'.'" />
0N/A <!--
0N/A Get an absolute URI from a package, object name, and suffix.
0N/A -->
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 <!--
0N/A Convert the package name to a relative path.
0N/A -->
0N/A <xsl:variable name="rpath" select="translate($package, '.', '/')" />
0N/A <!--
0N/A Convert the managed object name to a file name.
0N/A -->
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 </xsl:variable>
0N/A <!--
0N/A Get the absolute path.
0N/A -->
0N/A <xsl:value-of
0N/A select="concat($base-dir, '/', $rpath, '/', $java-name, $suffix)" />
0N/A </xsl:template>
0N/A <!--
0N/A Get the URI of the named package definition.
0N/A -->
0N/A <xsl:template name="get-package-uri">
0N/A <xsl:param name="package" select="/.." />
0N/A <xsl:call-template name="get-uri">
0N/A <xsl:with-param name="package" select="$package" />
0N/A <xsl:with-param name="name" select="'package'" />
0N/A </xsl:call-template>
0N/A </xsl:template>
0N/A <!--
0N/A Get the URI of the named managed object definition.
0N/A -->
0N/A <xsl:template name="get-managed-object-uri">
0N/A <xsl:param name="package" select="/.." />
0N/A <xsl:param name="name" select="/.." />
0N/A <xsl:call-template name="get-uri">
0N/A <xsl:with-param name="package" select="$package" />
0N/A <xsl:with-param name="name"
0N/A select="concat($name, '-configuration')" />
0N/A </xsl:call-template>
0N/A </xsl:template>
0N/A <!--
0N/A Pre-process the current managed object element.
0N/A -->
0N/A <xsl:template name="pre-process-managed-object">
0N/A <xsl:if test="not(adm:root-managed-object | adm:managed-object)">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of select="'No managed object definition found.'" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:apply-templates
0N/A select="adm:root-managed-object | adm:managed-object"
0N/A mode="pre-process" />
0N/A </xsl:template>
0N/A <!--
0N/A Pre-process a managed object definition: pull in the managed object's
0N/A inherited property definitions and relations.
0N/A -->
0N/A <xsl:template match="adm:managed-object" mode="pre-process">
0N/A <xsl:if test="not(@name)">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="'Managed object definition does not specify managed object name.'" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:if test="not(@package)">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="'Managed object definition does not specify managed object package.'" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:variable name="parent-name" select="@extends" />
0N/A <xsl:variable name="parent-package">
0N/A <!--
0N/A The parent package defaults to this managed object's package.
0N/A -->
0N/A <xsl:choose>
0N/A <xsl:when test="@parent-package">
0N/A <xsl:value-of select="@parent-package" />
0N/A </xsl:when>
0N/A <xsl:otherwise>
0N/A <xsl:value-of select="@package" />
0N/A </xsl:otherwise>
0N/A </xsl:choose>
0N/A </xsl:variable>
0N/A <!--
0N/A Get this managed object's hierarchy if there is one.
0N/A -->
0N/A <xsl:variable name="_hierarchy">
0N/A <xsl:if test="$parent-name">
0N/A <xsl:variable name="uri">
0N/A <xsl:call-template name="get-managed-object-uri">
0N/A <xsl:with-param name="package" select="$parent-package" />
0N/A <xsl:with-param name="name" select="$parent-name" />
0N/A </xsl:call-template>
0N/A </xsl:variable>
0N/A <xsl:if test="not(document($uri)/adm:managed-object)">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('No managed object definition found in ', $uri, '.')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:if
0N/A test="not(document($uri)/adm:managed-object[@name=$parent-name and @package=$parent-package])">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Managed object definition found in ', $uri, ' but it did not define a managed object ', $parent-name, ' in package ', $parent-package, '.')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:apply-templates select="document($uri)/adm:managed-object"
0N/A mode="pre-process" />
0N/A </xsl:if>
0N/A </xsl:variable>
0N/A <xsl:variable name="hierarchy" select="exsl:node-set($_hierarchy)" />
0N/A <!--
0N/A Now pre-process this managed object.
0N/A -->
0N/A <xsl:copy>
0N/A <!--
0N/A Shallow copy this element and its attributes.
0N/A -->
0N/A <xsl:copy-of select="@*" />
0N/A <!--
0N/A Pre-process this managed object's elements.
0N/A -->
0N/A <xsl:apply-templates
0N/A select="adm:TODO|adm:synopsis|adm:description"
0N/A mode="pre-process">
0N/A <xsl:with-param name="moname" select="@name" />
0N/A <xsl:with-param name="mopackage" select="@package" />
0N/A <xsl:with-param name="hierarchy" select="$hierarchy" />
0N/A </xsl:apply-templates>
0N/A <!--
0N/A Copy all inherited tags plus locally defined tags.
0N/A -->
0N/A <xsl:copy-of select="$hierarchy/adm:managed-object/adm:tag" />
0N/A <xsl:apply-templates select="adm:tag" mode="pre-process">
0N/A <xsl:with-param name="moname" select="@name" />
0N/A <xsl:with-param name="mopackage" select="@package" />
0N/A <xsl:with-param name="hierarchy" select="$hierarchy" />
0N/A </xsl:apply-templates>
0N/A <!--
0N/A Copy profile elements.
0N/A -->
0N/A <xsl:apply-templates select="adm:profile" mode="pre-process">
0N/A <xsl:with-param name="moname" select="@name" />
0N/A <xsl:with-param name="mopackage" select="@package" />
0N/A <xsl:with-param name="hierarchy" select="$hierarchy" />
0N/A </xsl:apply-templates>
0N/A <!--
0N/A Add a pre-processor element defining this managed object's uppermost
0N/A definition.
0N/A -->
0N/A <xsl:if test="$parent-name">
0N/A <xsl:element name="adm:profile">
0N/A <xsl:attribute name="name">
0N/A <xsl:value-of select="'preprocessor'" />
0N/A </xsl:attribute>
0N/A <xsl:element name="admpp:parent-managed-object">
0N/A <xsl:attribute name="name">
0N/A <xsl:value-of select="$parent-name" />
0N/A </xsl:attribute>
0N/A <xsl:attribute name="package">
0N/A <xsl:value-of select="$parent-package" />
0N/A </xsl:attribute>
0N/A </xsl:element>
0N/A <xsl:copy-of
0N/A select="$hierarchy/adm:managed-object/adm:profile[@name='preprocessor']/admpp:parent-managed-object" />
0N/A </xsl:element>
0N/A </xsl:if>
0N/A <!--
0N/A Copy all inherited relations.
0N/A -->
0N/A <xsl:copy-of select="$hierarchy/adm:managed-object/adm:relation" />
0N/A <!--
0N/A Copy all local relations.
0N/A -->
0N/A <xsl:apply-templates select="adm:relation" mode="pre-process">
0N/A <xsl:with-param name="moname" select="@name" />
0N/A <xsl:with-param name="mopackage" select="@package" />
0N/A <xsl:with-param name="hierarchy" select="$hierarchy" />
0N/A </xsl:apply-templates>
0N/A <!--
0N/A Copy all inherited properties.
0N/A -->
0N/A <xsl:variable name="property-overrides"
0N/A select="adm:property-override" />
0N/A <xsl:copy-of
0N/A select="$hierarchy/adm:managed-object/adm:property[not(@name=$property-overrides/@name)]" />
0N/A <!--
0N/A Copy all local properties.
0N/A -->
0N/A <xsl:apply-templates
0N/A select="adm:property|adm:property-reference|adm:property-override"
0N/A mode="pre-process">
0N/A <xsl:with-param name="moname" select="@name" />
0N/A <xsl:with-param name="mopackage" select="@package" />
0N/A <xsl:with-param name="hierarchy" select="$hierarchy" />
0N/A </xsl:apply-templates>
0N/A </xsl:copy>
0N/A </xsl:template>
0N/A <!--
0N/A Pre-process a managed object definition: pull in the managed object's
0N/A inherited property definitions and relations.
0N/A -->
0N/A <xsl:template match="adm:root-managed-object" mode="pre-process">
0N/A <!--
0N/A Now pre-process this root managed object.
0N/A By definition it has no hierarchy.
0N/A -->
0N/A <xsl:copy>
0N/A <!--
0N/A Shallow copy this element and its attributes.
0N/A -->
0N/A <xsl:copy-of select="@*" />
0N/A <!--
0N/A Pre-process this managed object's elements.
0N/A -->
0N/A <xsl:apply-templates mode="pre-process">
0N/A <xsl:with-param name="moname" select="'root'" />
0N/A <xsl:with-param name="mopackage"
0N/A select="'org.opends.server.admin.std'" />
0N/A </xsl:apply-templates>
0N/A </xsl:copy>
0N/A </xsl:template>
0N/A <!--
0N/A Pre-process a tag and validate it and by adding a "preprocessor"
0N/A profile which contains information about where the tag was defined.
0N/A -->
0N/A <xsl:template match="adm:tag" mode="pre-process">
0N/A <xsl:param name="mopackage" select="/.." />
0N/A <xsl:param name="moname" select="/.." />
0N/A <xsl:param name="hierarchy" />
0N/A <!--
0N/A Make sure that this tag is not duplicated.
0N/A -->
0N/A <xsl:variable name="name" select="@name" />
0N/A <xsl:if test="/adm:tag[@name=$name][2]">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Tag ', @name, ' is already defined in this managed object')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <!--
0N/A Make sure that this tag does not override an existing tag.
0N/A -->
0N/A <xsl:if test="$hierarchy/adm:managed-object/adm:tag[@name=$name]">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Tag ', @name, ' is already defined in a parent managed object')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <!--
0N/A Get the referenced package.
0N/A -->
0N/A <xsl:variable name="uri">
0N/A <xsl:call-template name="get-managed-object-uri">
0N/A <xsl:with-param name="package"
0N/A select="'org.opends.server.admin.std'" />
0N/A <xsl:with-param name="name" select="'root'" />
0N/A </xsl:call-template>
0N/A </xsl:variable>
0N/A <xsl:if test="not(document($uri)/adm:root-managed-object)">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Root managed object definition not found in ', $uri, '.')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:if
0N/A test="not(document($uri)/adm:root-managed-object/adm:tag-definition[@name=$name])">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Tag &quot;', $name,
0N/A '&quot; not defined in root managed object definition.')" />
494N/A </xsl:message>
0N/A </xsl:if>
0N/A <!--
0N/A Copy the tag.
0N/A -->
0N/A <xsl:element name="adm:tag">
0N/A <xsl:copy-of select="@*" />
0N/A <xsl:apply-templates mode="pre-process">
0N/A <xsl:with-param name="moname" select="$moname" />
0N/A <xsl:with-param name="mopackage" select="$mopackage" />
0N/A </xsl:apply-templates>
0N/A </xsl:element>
0N/A </xsl:template>
0N/A <!--
0N/A Pre-process a property definition by adding a "preprocessor" profile
0N/A which contains information about where the property was defined.
0N/A -->
0N/A <xsl:template match="adm:property" mode="pre-process">
494N/A <xsl:param name="mopackage" select="/.." />
494N/A <xsl:param name="moname" select="/.." />
0N/A <xsl:param name="hierarchy" select="/.." />
0N/A <!--
494N/A Make sure that this property does not have the same name as another
494N/A property or reference in this managed object.
0N/A -->
0N/A <xsl:variable name="name" select="@name" />
0N/A <xsl:if
0N/A test="/adm:property[@name=$name][2] |
0N/A /adm:property-reference[@name=$name]">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
494N/A select="concat('Property definition ', @name, ' is already defined in this managed object')" />
0N/A </xsl:message>
494N/A </xsl:if>
0N/A <!--
0N/A Make sure that this property does not override an existing property.
0N/A -->
0N/A <xsl:if
0N/A test="$hierarchy/adm:managed-object/adm:property[@name=$name]">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Property definition ', @name, ' is already defined in a parent managed object')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:copy>
0N/A <!--
0N/A Shallow copy this element and its attributes.
0N/A -->
0N/A <xsl:copy-of select="@*" />
0N/A <!--
0N/A Apply templates to subordinate elements (e.g. descriptions).
0N/A -->
0N/A <xsl:apply-templates mode="pre-process">
0N/A <xsl:with-param name="mopackage" select="$mopackage" />
0N/A <xsl:with-param name="moname" select="$moname" />
0N/A <xsl:with-param name="hierarchy" select="$hierarchy" />
0N/A </xsl:apply-templates>
0N/A <!--
0N/A Now append the preprocessor profile.
0N/A -->
0N/A <xsl:element name="adm:profile">
0N/A <xsl:attribute name="name">
0N/A <xsl:value-of select="'preprocessor'" />
0N/A </xsl:attribute>
0N/A <xsl:element name="admpp:managed-object">
0N/A <xsl:attribute name="name">
0N/A <xsl:value-of select="$moname" />
0N/A </xsl:attribute>
0N/A <xsl:attribute name="package">
0N/A <xsl:value-of select="$mopackage" />
0N/A </xsl:attribute>
0N/A </xsl:element>
0N/A </xsl:element>
0N/A </xsl:copy>
0N/A </xsl:template>
0N/A <!--
0N/A Pre-process a property reference pulling in the referenced property
0N/A definition and by adding a "preprocessor" profile which contains
0N/A information about where the property was defined.
0N/A -->
0N/A <xsl:template match="adm:property-reference" mode="pre-process">
0N/A <xsl:param name="mopackage" select="/.." />
0N/A <xsl:param name="moname" select="/.." />
0N/A <xsl:param name="hierarchy" />
0N/A <!--
0N/A Make sure that this property reference does not have the same name as another
0N/A property or reference in this managed object.
0N/A -->
0N/A <xsl:variable name="name" select="@name" />
0N/A <xsl:if
0N/A test="/adm:property[@name=$name] |
0N/A /adm:property-reference[@name=$name][2]">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Property definition ', @name, ' is already defined in this managed object')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <!--
0N/A Make sure that this property does not override an existing property.
0N/A -->
0N/A <xsl:if
0N/A test="$hierarchy/adm:managed-object/adm:property[@name=$name]">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Property reference ', @name, ' is already defined in a parent managed object')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <!--
0N/A Determine the package containing the reference property definition.
0N/A -->
0N/A <xsl:variable name="package">
0N/A <xsl:choose>
0N/A <xsl:when test="@package">
0N/A <xsl:value-of select="@package" />
0N/A </xsl:when>
0N/A <xsl:otherwise>
0N/A <xsl:value-of select="$mopackage" />
0N/A </xsl:otherwise>
0N/A </xsl:choose>
0N/A </xsl:variable>
0N/A <!--
0N/A Get the referenced package.
0N/A -->
0N/A <xsl:variable name="uri">
0N/A <xsl:call-template name="get-package-uri">
0N/A <xsl:with-param name="package" select="$package" />
0N/A </xsl:call-template>
0N/A </xsl:variable>
0N/A <xsl:if test="not(document($uri)/adm:package)">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('No package definition found in ', $uri, '.')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:if test="not(document($uri)/adm:package[@name=$package])">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Package definition found in ', $uri, ' but it did not define package ', $package, '.')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <xsl:if
0N/A test="not(document($uri)/adm:package[@name=$package]/adm:property[@name=$name])">
0N/A <xsl:message terminate="yes">
0N/A <xsl:value-of
0N/A select="concat('Referenced property definition &quot;', $name,
0N/A '&quot; not found in package definition &quot;', $package,
0N/A '&quot;.')" />
0N/A </xsl:message>
0N/A </xsl:if>
0N/A <!--
0N/A Copy the referenced property definition taking care to override
0N/A the default behavior and admin action if required.
0N/A -->
0N/A <xsl:variable name="property"
0N/A select="document($uri)/adm:package[@name=$package]/adm:property[@name=$name]" />
0N/A <xsl:element name="adm:property">
0N/A <xsl:copy-of select="$property/@*" />
0N/A <xsl:apply-templates
0N/A select="$property/adm:TODO | $property/adm:synopsis | $property/adm:description"
0N/A mode="pre-process">
0N/A <xsl:with-param name="mopackage" select="$mopackage" />
0N/A <xsl:with-param name="moname" select="$moname" />
0N/A <xsl:with-param name="hierarchy" select="$hierarchy" />
0N/A </xsl:apply-templates>
0N/A <xsl:choose>
0N/A <xsl:when test="adm:requires-admin-action">
0N/A <xsl:apply-templates select="adm:requires-admin-action"
0N/A mode="pre-process">
0N/A <xsl:with-param name="mopackage" select="$mopackage" />
0N/A <xsl:with-param name="moname" select="$moname" />
0N/A <xsl:with-param name="hierarchy" select="$hierarchy" />
0N/A </xsl:apply-templates>
0N/A </xsl:when>
0N/A <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 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">
<xsl:value-of
select="concat('Property override ', @name, ' is already overridden in this managed object')" />
</xsl:message>
</xsl:if>
<!--
Make sure that this property overrides an existing property.
-->
<xsl:if
test="not($hierarchy/adm:managed-object/adm:property[@name=$name])">
<xsl:message terminate="yes">
<xsl:value-of
select="concat('Cannot find inherited property ', @name, ' for property override')" />
</xsl:message>
</xsl:if>
<!--
Copy the inherited property definition taking care to override
the default behavior and admin action if required.
-->
<xsl:variable name="property"
select="$hierarchy/adm:managed-object/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[@name!='preprocessor']"
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: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 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>
<!--
Shallow copy.
-->
<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" />
</xsl:attribute>
</xsl:if>
<!--
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" />
</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="_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: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: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>