<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:import href="keyval-common.xsl" />

  <xsl:output method="text" indent="no"/>

  <xsl:preserve-space elements="*"/>

<xsl:template match="keyval">

  <xsl:text>/*----------------------------------------------------------------
 * AUTOMATICALLY GENERATED FROM XML - DO NOT EDIT!
 * 
 * (c) 2004 - Vaisala */
//----------------------------------------------------------------

package </xsl:text>
  <xsl:value-of select="(@package)"/>

  <xsl:text>;

//----------------------------------------------------------------
/** Class which loads the configuration associated with the </xsl:text>
  <xsl:value-of select="(@class)"/>
  <xml:text> objects.
 *
 * &#60;p&#62;This "bean" maintains the following state:&#60;/p&#62;
 *
 * &#60;ul&#62;
 *
 * &#60;li&#62;Attributes can not be set to 'null'. Attempting to set one to
 * null will result in an {@link NullPointerException}.&#60;/p&#62;
 *
 * &#60;li&#62;Attributes which have no default value defined will trigger a 
 * {@link IllegalStateException} if you attempt to access them prior to
 * setting them to a legal value.&#60;/p&#62;
 *
 * &#60;li&#62;Attributes are always within their legal range (if one
 * is defined). Attempting to set a attribute outside of its legal range
 * will result in an {@link IllegalArgumentException}.&#60;/p&#62;
 * 
 * &#60;/ul&#62;
 *
 * &#60;p&#62;This class is automatically generated from a XML document
 * which defines the configuration entries used by the application.&#60;/p&#62; */
//----------------------------------------------------------------

public class </xml:text>
  <xsl:value-of select="(@class)"/>
  <xml:text> {

  //----------------------------------------------------------------
  /** Constructor for the </xml:text>
  <xsl:value-of select="(@class)"/>
  <xml:text> class.
   * 
   * &#60;p&#62;This constructor initializes the object with the default
   * values as defined in the source XML document.&#60;/p&#62; */
  //----------------------------------------------------------------

  public </xml:text>
  <xsl:value-of select="(@class)"/>
  <xml:text>() {
    setDefaultValues();
  }

  //----------------------------------------------------------------
  /** Get the name of the application the configuration is intended for.
   *
   * @return Name of application the configuration was designed for. */
  //----------------------------------------------------------------

  public String toString() {
    return "</xml:text>
  <xsl:value-of select="(@class)"/>
  <xml:text>";
  }

  //----------------------------------------------------------------
  /** Clears current settings and loads default values.
   *
   * &#60;p&#62;Any required fields (those which don't have a default value
   * defined) will be cleared. You will need to be explicitly set them
   * prior to attempting to access them.&#60;/p&#62; */
  //----------------------------------------------------------------
	
  public void setDefaultValues() {

</xml:text>

  <xsl:for-each select="*">
    <xsl:text>    _</xsl:text>
    <xsl:value-of select="(@varname)"/>
    <xsl:text> = </xsl:text>

    <xsl:choose>

      <xsl:when test="@jtype='boolean'">
        <xsl:value-of select="(@default)"/>
      </xsl:when>

      <xsl:when test="@default='REQUIRED'">
        <xsl:text>null</xsl:text>
      </xsl:when>

      <xsl:when test="@jtype='String'">
        <xsl:text>"</xsl:text>
        <xsl:value-of select="(@default)"/>
        <xsl:text>"</xsl:text>
      </xsl:when>

      <xsl:otherwise>
        <xsl:text>new </xsl:text>
        <xsl:value-of select="(@jtype)"/>
        <xsl:text>(</xsl:text>
        <xsl:if test="(@default)">
          <xsl:call-template name="format-cctype-value">
            <xsl:with-param name="cctype" select="@cctype" />
            <xsl:with-param name="value" select="@default" />
          </xsl:call-template>
        </xsl:if>
        <xsl:text>)</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>;
</xsl:text>
  </xsl:for-each>

  <xsl:text>  }

</xsl:text>

  <xsl:apply-templates/>
  <xsl:text>}
</xsl:text>

</xsl:template>


<xsl:template match="keyval/*">

  <xsl:text>
  //----------------------------------------------------------------
  /** </xsl:text>
  <xsl:value-of select="summary"/>
  <xsl:text>
   *
   * &#60;p&#62;</xsl:text>
  <xsl:value-of select="description"/>
  <xsl:text>&#60;/p&#62;
</xsl:text>

  <xsl:if test="(@min)">
    <xsl:text>   *
   * &#60;p&#62;It has a minimum value of: &#60;b&#62;</xsl:text>
    <xsl:value-of select="(@min)"/>
    <xsl:text>&#60;/b&#62;.&#60;/p&#62;
</xsl:text>
  </xsl:if>

  <xsl:if test="(@max)">
    <xsl:text>   *
   * &#60;p&#62;It has a maximum value of: &#60;b&#62;</xsl:text>
    <xsl:value-of select="(@max)"/>
    <xsl:text>&#60;/b&#62;.&#60;/p&#62;
</xsl:text>
  </xsl:if>

  <xsl:choose>

    <xsl:when test="@default = 'REQUIRED'">
      <xsl:text>   *
   * &#60;p&#62;NOTE: There is no default value associated with this method.
   * You MUST invoke {@link #set</xsl:text>
      <xsl:value-of select="@varname" />
      <xsl:text>} method prior to using this
   * method (otherwise you will get a {@link IllegalStateException}).&#60;/p&#62;</xsl:text>
    </xsl:when>

    <xsl:otherwise>
      <xsl:text>   *
   * &#60;p&#62;It has a default value of: &#60;b&#62;</xsl:text>
      <xsl:call-template name="format-cctype-value">
        <xsl:with-param name="cctype" select="@cctype" />
        <xsl:with-param name="value" select="@default" />
      </xsl:call-template>
      <xsl:text>&#60;/b&#62;.&#60;/p&#62;</xsl:text>
    </xsl:otherwise>
  </xsl:choose>


  <xsl:text>
   *
   * @return </xsl:text>
  <xsl:value-of select="(@type)"/>
  <xsl:text> */
  //----------------------------------------------------------------

  public </xsl:text>

  <xsl:value-of select="(@jtype)"/>
  <xsl:choose>
    <xsl:when test="@jtype='boolean'">
      <xsl:text> is</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text> get</xsl:text>
    </xsl:otherwise>
   </xsl:choose>
   <xsl:value-of select="(@varname)"/>
   <xsl:text>() {
</xsl:text>

   <xsl:if test="@default = 'REQUIRED'">
     <xsl:text>
    if (_</xsl:text>
     <xsl:value-of select="(@varname)"/>
     <xsl:text> == null) {
      throw new IllegalStateException("\"</xsl:text>
     <xsl:value-of select="(@varname)"/>
     <xsl:text>\" has no default and has not been set.");
    }     
</xsl:text>
   </xsl:if>

   <xsl:text>
    return _</xsl:text>
  <xsl:value-of select="(@varname)"/>
  <xsl:text>;

  }

  //----------------------------------------------------------------
  /** </xsl:text>
  <xsl:value-of select="summary"/>
  <xsl:text>
   *
   * &#60;p&#62;</xsl:text>
  <xsl:value-of select="description"/>
  <xsl:text>&#60;/p&#62;
</xsl:text>

  <xsl:if test="(@min)">
    <xsl:text>   *
   * &#60;p&#62;It has a minimum value of: &#60;b&#62;</xsl:text>
    <xsl:value-of select="(@min)"/>
    <xsl:text>&#60;/b&#62;.&#60;/p&#62;
</xsl:text>
  </xsl:if>

  <xsl:if test="(@max)">
    <xsl:text>   *
   * &#60;p&#62;It has a maximum value of: &#60;b&#62;</xsl:text>
    <xsl:value-of select="(@max)"/>
    <xsl:text>&#60;/b&#62;.&#60;/p&#62;
</xsl:text>
  </xsl:if>

  <xsl:if test="@default != 'REQUIRED'">
    <xsl:text>   *
   * &#60;p&#62;It has a default value of: &#60;b&#62;</xsl:text>
    <xsl:call-template name="format-cctype-value">
      <xsl:with-param name="cctype" select="@cctype" />
      <xsl:with-param name="value" select="@default" />
    </xsl:call-template>
    <xsl:text>&#60;/b&#62;.&#60;/p&#62;</xsl:text>
  </xsl:if>

  <xsl:text>
   *
   * @param val The new value to set.
   *
   * @throws IllegalArgumentException if you specify a illegal value.
   *
   * @throws NullPointerException if you pass null. */
  //----------------------------------------------------------------

  public void set</xsl:text>
  <xsl:value-of select="(@varname)"/>
  <xsl:text>(</xsl:text>
  <xsl:value-of select="(@jtype)"/>
  <xsl:text> val)
    throws IllegalArgumentException, NullPointerException {
</xsl:text>

  <xsl:if test="not(@jtype='boolean')">
    <xsl:text>
    if (val == null) throw new NullPointerException();
</xsl:text>
  </xsl:if>

  <xsl:if test="(@min)">
    <xsl:text>
    if (val</xsl:text>
    <xsl:choose>
      <xsl:when test="@jtype='Double'">
        <xsl:text>.doubleValue()</xsl:text>
      </xsl:when>
      <xsl:when test="@jtype='Long'">
        <xsl:text>.longValue()</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:text> &lt; </xsl:text>
    <xsl:value-of select="(@min)"/>
    <xsl:text>) {
      String msg = "minimum value for set</xsl:text>
    <xsl:value-of select="(@varname)"/>
    <xsl:text> is </xsl:text>
    <xsl:value-of select="(@min)"/>
    <xsl:text> ("+
                    val+"was too small)";
      throw new IllegalArgumentException(msg);
    }
</xsl:text>
  </xsl:if>

  <xsl:if test="(@max)">
    <xsl:text>
    if (val</xsl:text>
    <xsl:choose>
      <xsl:when test="@jtype='Double'">
        <xsl:text>.doubleValue()</xsl:text>
      </xsl:when>
      <xsl:when test="@jtype='Long'">
        <xsl:text>.longValue()</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:text> &gt; </xsl:text>
    <xsl:value-of select="(@max)"/>
    <xsl:text>) {
      String msg = "maximum value for set</xsl:text>
    <xsl:value-of select="(@varname)"/>
    <xsl:text> is </xsl:text>
    <xsl:value-of select="(@max)"/>
    <xsl:text> ("+
                    val+"was too large)";
      throw new IllegalArgumentException(msg);
    }
</xsl:text>
  </xsl:if>

  <xsl:text>
    _</xsl:text>
  <xsl:value-of select="(@varname)"/>
  <xsl:text> = val;

  }

  /** </xsl:text>
  <xsl:value-of select="summary"/>
  <xsl:text> */

  private </xsl:text>
  <xsl:value-of select="(@jtype)"/>
  <xsl:text> _</xsl:text>
  <xsl:value-of select="(@varname)"/>
  <xsl:text>;
</xsl:text>

</xsl:template>

</xsl:stylesheet>
