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

matthew_swift
14.28.2007 e9d59ae1b6f7da18a4de6ae58cb5ba275cc0bbfc
Add support to the admin framework code generation scripts so that properties can define their own syntax specific getters and setters.
4 files modified
406 ■■■■■ changed files
opends/resource/admin/clientMO.xsl 14 ●●●● patch | view | raw | blame | history
opends/resource/admin/metaMO.xsl 136 ●●●●● patch | view | raw | blame | history
opends/resource/admin/property-types.xsl 252 ●●●●● patch | view | raw | blame | history
opends/resource/admin/serverMO.xsl 4 ●●● patch | view | raw | blame | history
opends/resource/admin/clientMO.xsl
@@ -362,19 +362,24 @@
    <xsl:call-template name="generate-import-statements">
      <xsl:with-param name="imports">
        <xsl:for-each select="$this-local-properties">
          <xsl:call-template name="get-property-java-imports" />
          <xsl:call-template name="get-property-java-imports">
            <xsl:with-param name="interface" select="'client'" />
          </xsl:call-template>
        </xsl:for-each>
        <xsl:if test="$this-local-properties[@multi-valued='true']">
          <import>java.util.Collection</import>
          <import>java.util.SortedSet</import>
        </xsl:if>
        <xsl:if test="$this-local-properties[not(@monitoring='true')]">
        <xsl:if
          test="$this-local-properties[not(@monitoring='true')]">
          <import>
            org.opends.server.admin.IllegalPropertyValueException
          </import>
        </xsl:if>
        <xsl:if test="$this-local-properties[@read-only='true']">
          <import>org.opends.server.admin.PropertyIsReadOnlyException</import>
          <import>
            org.opends.server.admin.PropertyIsReadOnlyException
          </import>
        </xsl:if>
        <xsl:if test="$this-local-relations">
          <import>
@@ -396,7 +401,8 @@
            org.opends.server.admin.client.CommunicationException
          </import>
        </xsl:if>
        <xsl:for-each select="$this-local-relations[adm:one-to-zero-or-one]|$this-local-relations[adm:one-to-many]">
        <xsl:for-each
          select="$this-local-relations[adm:one-to-zero-or-one]|$this-local-relations[adm:one-to-many]">
          <xsl:variable name="java-class-name">
            <xsl:call-template name="name-to-java">
              <xsl:with-param name="value"
opends/resource/admin/metaMO.xsl
@@ -368,13 +368,13 @@
      <xsl:text>&#xa;</xsl:text>
      <xsl:text>&#xa;</xsl:text>
      <xsl:text>&#xa;</xsl:text>
      <xsl:call-template name="generate-property-getter">
      <xsl:call-template name="generate-property-getter-implementation">
        <xsl:with-param name="interface" select="'client'" />
      </xsl:call-template>
      <xsl:text>&#xa;</xsl:text>
      <xsl:text>&#xa;</xsl:text>
      <xsl:text>&#xa;</xsl:text>
      <xsl:call-template name="generate-property-setter" />
      <xsl:call-template name="generate-property-setter-implementation" />
    </xsl:for-each>
    <!--
      Relation methods.
@@ -485,7 +485,7 @@
      <xsl:text>&#xa;</xsl:text>
      <xsl:text>&#xa;</xsl:text>
      <xsl:text>&#xa;</xsl:text>
      <xsl:call-template name="generate-property-getter">
      <xsl:call-template name="generate-property-getter-implementation">
        <xsl:with-param name="interface" select="'server'" />
      </xsl:call-template>
    </xsl:for-each>
@@ -1022,131 +1022,6 @@
    </xsl:choose>
  </xsl:template>
  <!--
    Generate a property value getter.
  -->
  <xsl:template name="generate-property-getter">
    <xsl:param name="interface" select="/.." />
    <xsl:variable name="java-prop-name">
      <xsl:call-template name="name-to-java">
        <xsl:with-param name="value" select="@name" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:value-of
      select="concat('    /**&#xa;',
                     '     * {@inheritDoc}&#xa;',
                     '     */&#xa;',
                     '    public ')" />
    <xsl:choose>
      <xsl:when test="string(@multi-valued) != 'true'">
        <xsl:choose>
          <xsl:when test="adm:default-behavior/adm:defined">
            <!--
              The method is guaranteed to return a value since there is a
              well-defined default value.
            -->
            <xsl:call-template name="get-property-java-primitive-type" />
          </xsl:when>
          <xsl:when
            test="$interface = 'server' and @mandatory = 'true'">
            <!--
              The method is guaranteed to return a value in the server interface, but
              not necessarily in the client, since the mandatory property might not
              have been created yet.
            -->
            <xsl:call-template name="get-property-java-primitive-type" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="get-property-java-type" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="'SortedSet&lt;'" />
        <xsl:call-template name="get-property-java-type" />
        <xsl:value-of select="'&gt;'" />
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="adm:syntax/adm:boolean">
        <xsl:value-of select="' is'" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="' get'" />
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="string(@multi-valued) != 'true'">
        <xsl:value-of
          select="concat($java-prop-name, '() {&#xa;',
                                     '      return impl.getPropertyValue',
                                     '(INSTANCE.get', $java-prop-name ,
                                     'PropertyDefinition());&#xa;' ,
                                     '    }&#xa;')" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of
          select="concat($java-prop-name, '() {&#xa;',
                                     '      return impl.getPropertyValues',
                                     '(INSTANCE.get', $java-prop-name ,
                                     'PropertyDefinition());&#xa;' ,
                                     '    }&#xa;')" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--
    Generate a property value setter.
  -->
  <xsl:template name="generate-property-setter">
    <xsl:if test="not(@monitoring='true')">
      <xsl:variable name="java-prop-name">
        <xsl:call-template name="name-to-java">
          <xsl:with-param name="value" select="@name" />
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of
        select="concat('    /**&#xa;',
                     '     * {@inheritDoc}&#xa;',
                     '     */&#xa;',
                     '    public void set',
                     $java-prop-name ,
                     '(')" />
      <xsl:choose>
        <xsl:when test="not(@multi-valued='true')">
          <xsl:choose>
            <xsl:when test="@mandatory='true'">
              <xsl:call-template
                name="get-property-java-primitive-type" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="get-property-java-type" />
            </xsl:otherwise>
          </xsl:choose>
          <xsl:value-of select="' value)'" />
          <xsl:if test="@read-only='true'">
            <xsl:value-of
              select="' throws PropertyIsReadOnlyException'" />
          </xsl:if>
          <xsl:value-of
            select="concat(' {&#xa;' ,
                     '      impl.setPropertyValue(INSTANCE.get',
                     $java-prop-name ,
                     'PropertyDefinition(), value);&#xa;',
                     '    }&#xa;')" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'Collection&lt;'" />
          <xsl:call-template name="get-property-java-type" />
          <xsl:value-of
            select="concat('&gt; values) {&#xa;' ,
                     '      impl.setPropertyValues(INSTANCE.get',
                     $java-prop-name ,
                     'PropertyDefinition(), values);&#xa;',
                     '    }&#xa;')" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>
  <!--
    Generate client relation methods.
  -->
  <xsl:template name="generate-client-relation-methods">
@@ -1718,7 +1593,6 @@
          <import>
            org.opends.server.admin.AbsoluteInheritedDefaultBehaviorProvider
          </import>
          <import>org.opends.server.admin.ManagedObjectPath</import>
        </xsl:if>
        <xsl:if
          test="$this-local-properties/adm:default-behavior/adm:inherited/adm:relative">
@@ -1759,7 +1633,9 @@
            select="concat($this-package, '.server.', $this-java-class, 'Cfg')" />
        </xsl:element>
        <xsl:for-each select="$this-inherited-properties">
          <xsl:call-template name="get-property-java-imports" />
          <xsl:call-template name="get-property-java-imports">
            <xsl:with-param name="interface" select="'server'" />
          </xsl:call-template>
        </xsl:for-each>
        <xsl:for-each select="$this-all-properties">
          <xsl:call-template
opends/resource/admin/property-types.xsl
@@ -90,7 +90,9 @@
    By default property values are represented using strings which
    don't require an import statement - so do nothing.
  -->
  <xsl:template match="*" mode="java-value-imports" />
  <xsl:template match="*" mode="java-value-imports">
    <xsl:param name="interface" select="/.." />
  </xsl:template>
  <!--
    Generate the Java definition type used to define the property.
    
@@ -114,7 +116,9 @@
      <xsl:value-of select="'org.opends.server.admin.'" />
      <xsl:apply-templates select="." mode="java-definition-type" />
    </xsl:element>
    <xsl:apply-templates select="." mode="java-value-imports" />
    <xsl:apply-templates select="." mode="java-value-imports">
      <xsl:with-param name="interface" select="'server'" />
    </xsl:apply-templates>
  </xsl:template>
  <!--
    If the property definition is generic, get the generic type. Otherwise,
@@ -136,6 +140,48 @@
  -->
  <xsl:template match="*" mode="java-definition-post-ctor" />
  <!--
    Generate property getter declaration(s).
    By default, generate a single getter with minimal documentation.
  -->
  <xsl:template match="*" mode="java-property-getter-declaration">
    <xsl:param name="interface" select="/.." />
    <xsl:call-template
      name="generate-default-property-getter-declaration">
      <xsl:with-param name="interface" select="$interface" />
    </xsl:call-template>
  </xsl:template>
  <!--
    Generate property getter implementation(s).
    By default, generate a single getter.
  -->
  <xsl:template match="*" mode="java-property-getter-implementation">
    <xsl:param name="interface" select="/.." />
    <xsl:call-template
      name="generate-default-property-getter-implementation">
      <xsl:with-param name="interface" select="$interface" />
    </xsl:call-template>
  </xsl:template>
  <!--
    Generate property setter declaration(s).
    By default, generate a single setter with minimal documentation.
  -->
  <xsl:template match="*" mode="java-property-setter-declaration">
    <xsl:call-template
      name="generate-default-property-setter-declaration" />
  </xsl:template>
  <!--
    Generate property setter implementation(s).
    By default, generate a single setter.
  -->
  <xsl:template match="*" mode="java-property-setter-implementation">
    <xsl:call-template
      name="generate-default-property-setter-implementation" />
  </xsl:template>
  <!--
    
    
    Wrapper templates which can be called directly instead of
@@ -148,8 +194,11 @@
    Get the Java imports required for a property's values.
  -->
  <xsl:template name="get-property-java-imports">
    <xsl:param name="interface" select="/.." />
    <xsl:apply-templates select="adm:syntax/*"
      mode="java-value-imports" />
      mode="java-value-imports">
      <xsl:with-param name="interface" select="$interface" />
    </xsl:apply-templates>
  </xsl:template>
  <!-- 
    Get the Java imports required for a property's definition.
@@ -202,11 +251,53 @@
    <xsl:apply-templates select="adm:syntax/*"
      mode="java-definition-post-ctor" />
  </xsl:template>
  <!--
  <!--
    Generate the property getter declarations.
  -->
  <xsl:template name="generate-property-getter-declaration">
    <xsl:param name="interface" select="/.." />
    <xsl:apply-templates select="adm:syntax/*"
      mode="java-property-getter-declaration">
      <xsl:with-param name="interface" select="$interface" />
    </xsl:apply-templates>
  </xsl:template>
  <!--
    Generate the property getter implementations.
  -->
  <xsl:template name="generate-property-getter-implementation">
    <xsl:param name="interface" select="/.." />
    <xsl:apply-templates select="adm:syntax/*"
      mode="java-property-getter-implementation">
      <xsl:with-param name="interface" select="$interface" />
    </xsl:apply-templates>
  </xsl:template>
  <!--
    Generate the property setter declarations.
  -->
  <xsl:template name="generate-property-setter-declaration">
    <xsl:apply-templates select="adm:syntax/*"
      mode="java-property-setter-declaration" />
  </xsl:template>
  <!--
    Generate the property setter implementations.
  -->
  <xsl:template name="generate-property-setter-implementation">
    <xsl:apply-templates select="adm:syntax/*"
      mode="java-property-setter-implementation" />
  </xsl:template>
  <!--
    Generate the default property getter declarations.
  -->
  <xsl:template name="generate-default-property-getter-declaration">
    <xsl:param name="interface" select="/.." />
    <xsl:apply-templates select="../.."
      mode="generate-default-property-getter-declaration-aux">
      <xsl:with-param name="interface" select="$interface" />
    </xsl:apply-templates>
  </xsl:template>
  <xsl:template match="adm:property"
    mode="generate-default-property-getter-declaration-aux">
    <xsl:param name="interface" select="/.." />
    <xsl:variable name="name" select="@name" />
    <xsl:variable name="java-property-name">
      <xsl:call-template name="name-to-java">
@@ -215,7 +306,7 @@
    </xsl:variable>
    <xsl:value-of
      select="concat('  /**&#xa;',
                     '   * Get the &quot;', $name,'&quot; property.&#xa;')" />
                     '   * Gets the &quot;', $name,'&quot; property.&#xa;')" />
    <xsl:if test="adm:synopsis">
      <xsl:value-of select="'   * &lt;p&gt;&#xa;'" />
      <xsl:call-template name="add-java-comment">
@@ -282,9 +373,95 @@
                                 '();&#xa;')" />
  </xsl:template>
  <!--
    Generate the property setter declarations.
    Generate the default property getter implementation.
  -->
  <xsl:template name="generate-property-setter-declaration">
  <xsl:template
    name="generate-default-property-getter-implementation">
    <xsl:param name="interface" select="/.." />
    <xsl:apply-templates select="../.."
      mode="generate-default-property-getter-implementation-aux">
      <xsl:with-param name="interface" select="$interface" />
    </xsl:apply-templates>
  </xsl:template>
  <xsl:template match="adm:property"
    mode="generate-default-property-getter-implementation-aux">
    <xsl:param name="interface" select="/.." />
    <xsl:variable name="java-prop-name">
      <xsl:call-template name="name-to-java">
        <xsl:with-param name="value" select="@name" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:value-of
      select="concat('    /**&#xa;',
                     '     * {@inheritDoc}&#xa;',
                     '     */&#xa;',
                     '    public ')" />
    <xsl:choose>
      <xsl:when test="string(@multi-valued) != 'true'">
        <xsl:choose>
          <xsl:when test="adm:default-behavior/adm:defined">
            <!--
              The method is guaranteed to return a value since there is a
              well-defined default value.
            -->
            <xsl:call-template name="get-property-java-primitive-type" />
          </xsl:when>
          <xsl:when
            test="$interface = 'server' and @mandatory = 'true'">
            <!--
              The method is guaranteed to return a value in the server interface, but
              not necessarily in the client, since the mandatory property might not
              have been created yet.
            -->
            <xsl:call-template name="get-property-java-primitive-type" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="get-property-java-type" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="'SortedSet&lt;'" />
        <xsl:call-template name="get-property-java-type" />
        <xsl:value-of select="'&gt;'" />
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="adm:syntax/adm:boolean">
        <xsl:value-of select="' is'" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="' get'" />
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="string(@multi-valued) != 'true'">
        <xsl:value-of
          select="concat($java-prop-name, '() {&#xa;',
                                     '      return impl.getPropertyValue',
                                     '(INSTANCE.get', $java-prop-name ,
                                     'PropertyDefinition());&#xa;' ,
                                     '    }&#xa;')" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of
          select="concat($java-prop-name, '() {&#xa;',
                                     '      return impl.getPropertyValues',
                                     '(INSTANCE.get', $java-prop-name ,
                                     'PropertyDefinition());&#xa;' ,
                                     '    }&#xa;')" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--
    Generate the default property setter declarations.
  -->
  <xsl:template name="generate-default-property-setter-declaration">
    <xsl:apply-templates select="../.."
      mode="generate-default-property-setter-declaration-aux" />
  </xsl:template>
  <xsl:template match="adm:property"
    mode="generate-default-property-setter-declaration-aux">
    <xsl:if test="not(@monitoring='true')">
      <xsl:variable name="name" select="@name" />
      <xsl:variable name="java-property-name">
@@ -294,7 +471,7 @@
      </xsl:variable>
      <xsl:value-of
        select="concat('  /**&#xa;',
                     '   * Set the &quot;', $name, '&quot; property.&#xa;')" />
                     '   * Sets the &quot;', $name, '&quot; property.&#xa;')" />
      <xsl:if test="adm:synopsis">
        <xsl:value-of select="'   * &lt;p&gt;&#xa;'" />
        <xsl:call-template name="add-java-comment">
@@ -371,4 +548,63 @@
      <xsl:value-of select="';&#xa;'" />
    </xsl:if>
  </xsl:template>
  <!--
    Generate the default property setter implementation.
  -->
  <xsl:template
    name="generate-default-property-setter-implementation">
    <xsl:apply-templates select="../.."
      mode="generate-default-property-setter-implementation-aux" />
  </xsl:template>
  <xsl:template match="adm:property"
    mode="generate-default-property-setter-implementation-aux">
    <xsl:if test="not(@monitoring='true')">
      <xsl:variable name="java-prop-name">
        <xsl:call-template name="name-to-java">
          <xsl:with-param name="value" select="@name" />
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of
        select="concat('    /**&#xa;',
                     '     * {@inheritDoc}&#xa;',
                     '     */&#xa;',
                     '    public void set',
                     $java-prop-name ,
                     '(')" />
      <xsl:choose>
        <xsl:when test="not(@multi-valued='true')">
          <xsl:choose>
            <xsl:when test="@mandatory='true'">
              <xsl:call-template
                name="get-property-java-primitive-type" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="get-property-java-type" />
            </xsl:otherwise>
          </xsl:choose>
          <xsl:value-of select="' value)'" />
          <xsl:if test="@read-only='true'">
            <xsl:value-of
              select="' throws PropertyIsReadOnlyException'" />
          </xsl:if>
          <xsl:value-of
            select="concat(' {&#xa;' ,
                     '      impl.setPropertyValue(INSTANCE.get',
                     $java-prop-name ,
                     'PropertyDefinition(), value);&#xa;',
                     '    }&#xa;')" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'Collection&lt;'" />
          <xsl:call-template name="get-property-java-type" />
          <xsl:value-of
            select="concat('&gt; values) {&#xa;' ,
                     '      impl.setPropertyValues(INSTANCE.get',
                     $java-prop-name ,
                     'PropertyDefinition(), values);&#xa;',
                     '    }&#xa;')" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
opends/resource/admin/serverMO.xsl
@@ -351,7 +351,9 @@
            select="concat($this-package, '.client.', $this-java-class, 'CfgClient')" />
        </xsl:element>
        <xsl:for-each select="$this-local-properties">
          <xsl:call-template name="get-property-java-imports" />
          <xsl:call-template name="get-property-java-imports" >
            <xsl:with-param name="interface" select="'server'" />
          </xsl:call-template>
        </xsl:for-each>
        <xsl:if test="$this-local-properties[@multi-valued='true']">
          <import>java.util.SortedSet</import>