<?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">
<!--
    Stylesheet parameter: name of Java package where PropertyInitializer
    belongs to.
-->
<xsl:param name="packageName"></xsl:param>
<xsl:output method="text"/>

<xsl:template match="/">
<xsl:text>/*
 *
 *
 * 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.
 */

package </xsl:text>
    <xsl:value-of select="$packageName"/>
<xsl:text>;

import java.security.AccessController;
import java.security.PrivilegedAction;
import com.sun.cdc.config.DynamicProperties;
import com.sun.j2me.main.Configuration;

public class PropertyInitializer {
    static {
</xsl:text>
    <xsl:for-each select="/configuration/properties">
        <xsl:if test="boolean(property[@Scope = 'system' and not(@Callout)])">
<xsl:text>        AccessController.doPrivileged(
            new PrivilegedAction() {
                public Object run() {
</xsl:text>
            <xsl:for-each select="property[@Scope = 'system' and not(@Callout)]">
                <xsl:sort select="@Key"/>
                <xsl:text>                    System.setProperty("</xsl:text>
                <xsl:value-of select="@Key"/>
                <xsl:text>", "</xsl:text>
                <xsl:value-of select="@Value"/>
<xsl:text>");
</xsl:text>
            </xsl:for-each>
<xsl:text>                    return null;
                }
            }
        );
</xsl:text>
        </xsl:if>
        <xsl:for-each select="property[@Scope = 'system' and @Callout]">
            <xsl:sort select="@Key"/>
            <xsl:text>        DynamicProperties.put("</xsl:text>
            <xsl:value-of select="@Key"/>
            <xsl:text>", </xsl:text>
            <xsl:value-of select="@Callout"/>
<xsl:text>.getInstance());
</xsl:text>
        </xsl:for-each>
        <xsl:for-each select="property[@Scope = 'internal']">
            <xsl:sort select="@Key"/>
            <xsl:text>        Configuration.setProperty("</xsl:text>
            <xsl:value-of select="@Key"/>
            <xsl:text>", "</xsl:text>
            <xsl:value-of select="@Value"/>
<xsl:text>");
</xsl:text>
        </xsl:for-each>

    </xsl:for-each>
<xsl:text>    }
}
</xsl:text>
</xsl:template>

</xsl:stylesheet>
