<?xml version="1.0" encoding="UTF-8"?>
<!--
          

        Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
        DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
-->
<!--
    This stylesheet outputs C source file with functions definitions
    for getting/setting properties values during runtime. 
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="/">
<xsl:variable name="properties" select="/configuration/properties"/>
<xsl:call-template name="outputProperties">
<xsl:with-param name="properties" select="$properties"/>
</xsl:call-template> 
</xsl:template>

<xsl:template name="outputProperties">
<xsl:param name="properties"/>
<!-- all properties with internal scope -->
<xsl:variable name="internalProps" select="$properties/property[@Scope = 'internal']"/>
<!-- all properties with system scope -->
<xsl:variable name="systemProps" select="$properties/property[@Scope = 'system']"/>
<!-- all properties with Callout attribute -->
<xsl:variable name="calloutProps" select="$properties/property[boolean(@Callout)]"/>
<xsl:text>
/*
 * midpConfigurationData.h
 *
 * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 *
 */

/*
 * This file is auto generated by Configurator. Do not edit.
 */
#ifndef __MIDPCONFIGURATIONDATA_H
#define __MIDPCONFIGURATIONDATA_H
</xsl:text>

<!-- output array of properties with internal scope keys -->
static const char* internalKey[] = {
<xsl:call-template name="outputKeys">
<xsl:with-param name="nodes" select="$internalProps"/>
</xsl:call-template>NULL};

<!-- output array of properties with internal scope values -->
static char* internalValue[] = {
<xsl:call-template name="outputValues">
<xsl:with-param name="nodes" select="$internalProps"/>
</xsl:call-template>NULL};

<!-- output array of properties with system scope keys -->
static const char* systemKey[] = {
<xsl:call-template name="outputKeys">
<xsl:with-param name="nodes" select="$systemProps"/>
</xsl:call-template>NULL};

<!-- output array of properties with system scope values -->
static char* systemValue[] = {
<xsl:call-template name="outputValues">
<xsl:with-param name="nodes" select="$systemProps"/>
</xsl:call-template>NULL};

<!-- output array of callout keys -->
static char* calloutKey[] = {
<xsl:call-template name="outputKeys">
<xsl:with-param name="nodes" select="$calloutProps"/>
</xsl:call-template>NULL};

<!-- output callout functions declarations -->
<xsl:for-each select="$calloutProps">
<xsl:text>extern char* </xsl:text><xsl:value-of select="@Callout"/><xsl:text>(void);</xsl:text>
<xsl:text>
</xsl:text>
</xsl:for-each>

<!-- output array of pointers to callout functions -->
typedef char* (*CALLOUTPTR)();
static CALLOUTPTR calloutFunction[] = {
<xsl:call-template name="outputCalloutFunctions">
<xsl:with-param name="nodes" select="$calloutProps"/>
</xsl:call-template>NULL};

#endif
</xsl:template>

<!-- output callout functions table -->
<xsl:template name="outputCalloutFunctions">
<!-- template parameter: properties with Callout attribute -->
<xsl:param name="nodes"/>
<xsl:for-each select="$nodes">
<xsl:sort select="@Key"/>
<xsl:text>    </xsl:text>
<xsl:value-of select="@Callout"/>
<xsl:text>,
</xsl:text>
</xsl:for-each>
</xsl:template>

<!-- output properties keys, one key per line, separated by comma -->
<xsl:template name="outputKeys">
<xsl:param name="nodes"/>
<xsl:for-each select="$nodes">
<xsl:sort select="@Key"/>
<xsl:text>    </xsl:text>
<xsl:text>"</xsl:text><xsl:value-of select="@Key"/><xsl:text>"</xsl:text>
<xsl:text>,
</xsl:text>
</xsl:for-each>
</xsl:template>

<!-- output properties values, one value per line, separated by comma -->
<xsl:template name="outputValues">
<xsl:param name="nodes"/>
<xsl:for-each select="$nodes">
<xsl:sort select="@Key"/>
<xsl:text>    </xsl:text>
<xsl:choose>
    <xsl:when test="@Value = ''">NULL</xsl:when>
    <xsl:otherwise>
        <xsl:text>"</xsl:text><xsl:value-of select="@Value"/><xsl:text>"</xsl:text>
    </xsl:otherwise>
</xsl:choose>
<xsl:text>,
</xsl:text>
</xsl:for-each>
</xsl:template>


</xsl:stylesheet>
