Copied all the currently working transforms from 'transforms01' to 'transforms'; created new schema 'adl-0-1-0.xsd' which once tested should become the new
normative reference.
This commit is contained in:
parent
bf13d05877
commit
e2130bc4c4
20 changed files with 6161 additions and 3159 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
C1873 SRU Hospitality
|
||||
Application Description Language framework
|
||||
adl2entityclass.xsl
|
||||
|
||||
(c) 2007 Cygnet Solutions Ltd
|
||||
|
|
@ -8,204 +8,284 @@
|
|||
Transform ADL into entity classes
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.4 $
|
||||
$Date: 2008-02-29 16:28:51 $
|
||||
$Revision: 1.5 $
|
||||
$Date: 2008-05-29 16:39:38 $
|
||||
-->
|
||||
|
||||
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
|
||||
Whitespace (or lack of it) is significant! -->
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:exsl="http://exslt.org/common"
|
||||
xmlns:a="http://cygnets.co.uk/schemas/adl-1.2"
|
||||
xmlns:adl="http://cygnets.co.uk/schemas/adl-1.2"
|
||||
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
|
||||
|
||||
<xsl:import href="types.xslt"/>
|
||||
|
||||
<xsl:output encoding="UTF-8" method="text"/>
|
||||
<xsl:include href="csharp-type-include.xslt"/>
|
||||
|
||||
<!-- The locale for which these entities are generated
|
||||
<xsl:output encoding="UTF-8" method="text"/>
|
||||
|
||||
<!-- The locale for which these entities are generated
|
||||
TODO: Entities should NOT be locale specific. Instead, the
|
||||
entity should generate messages based on the
|
||||
client's locale. However, there may still need to be a concept of a
|
||||
'default locale', for when we don't have messages which suit the
|
||||
client's locale -->
|
||||
<xsl:param name="lang" select="en-UK"/>
|
||||
<xsl:param name="locale" select="en-UK"/>
|
||||
|
||||
<!-- The C# namespace within which I shall generate controllers -->
|
||||
<xsl:param name="controllerns" select="Unset"/>
|
||||
<!-- The C# namespace within which I shall generate entities -->
|
||||
<xsl:param name="entityns" select="Unset"/>
|
||||
<!-- The C# namespace within which I shall generate controllers -->
|
||||
<xsl:param name="controllerns" select="Unset"/>
|
||||
|
||||
<xsl:template match="a:application">
|
||||
<xsl:apply-templates select="a:entity"/>
|
||||
</xsl:template>
|
||||
<!-- The C# namespace within which I shall generate entities -->
|
||||
<xsl:param name="entityns" select="Unset"/>
|
||||
|
||||
<xsl:template match="a:entity">
|
||||
<!-- what's all this about? the objective is to get the revision number of the
|
||||
transform into the output, /without/ getting that revision number overwritten
|
||||
with the revision number of the generated file if the generated file is
|
||||
stored to CVS -->
|
||||
<!-- the name and version of the product being built -->
|
||||
<xsl:param name="product-version" select="'Application Description Language Framework'"/>
|
||||
|
||||
<xsl:variable name="transform-rev1"
|
||||
select="substring( '$Revision: 1.4 $', 11)"/>
|
||||
<xsl:variable name="transform-revision"
|
||||
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
|
||||
|
||||
<xsl:variable name="keynames" select="a:key/a:property" />
|
||||
<xsl:template match="adl:application">
|
||||
<xsl:apply-templates select="adl:entity"/>
|
||||
</xsl:template>
|
||||
|
||||
/* ---- [ cut here: next file '<xsl:value-of select="@name"/>.auto.cs'] ---------------- */
|
||||
<!-- Don't bother generating anything for foreign entities -->
|
||||
<xsl:template match="adl:entity[@foreign='true']"/>
|
||||
|
||||
<xsl:template match="adl:entity">
|
||||
|
||||
/* ---- [ cut here: next file '<xsl:value-of select="@name"/>.auto.cs'] ---------------- */
|
||||
|
||||
//-------------------------------------------------------------
|
||||
//
|
||||
// Application Description Framework
|
||||
// <xsl:value-of select="$product-version"/>
|
||||
// <xsl:value-of select="@name"/>.auto.cs
|
||||
//
|
||||
// (c)2007 Cygnet Solutions Ltd
|
||||
//
|
||||
// Automatically generated from application description using
|
||||
// adl2entityclass.xsl version <xsl:value-of select="$transform-revision"/>
|
||||
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.5 $', 10)"/>
|
||||
//
|
||||
// This file is automatically generated; DO NOT EDIT IT.
|
||||
//
|
||||
//-------------------------------------------------------------
|
||||
namespace <xsl:value-of select="$entityns"/>
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Cygnet.Entities;
|
||||
using Cygnet.Exceptions;
|
||||
using Iesi.Collections.Generic;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Cygnet.Exceptions;
|
||||
using Cygnet.Entities;
|
||||
using Iesi.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// <xsl:value-of select="normalize-space( adl:documentation)"/>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Automatically generated from description of entity <xsl:value-of select="@name"/>
|
||||
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.5 $', 10)"/>.
|
||||
/// Note that manually maintained parts of this class may be defined in
|
||||
/// a separate file called <xsl:value-of select="@name"/>.manual.cs, q.v.
|
||||
///
|
||||
/// DO NOT EDIT THIS FILE!
|
||||
/// </remarks>
|
||||
public partial class <xsl:value-of select="@name"/> : Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// Auto-generated no-args constructor; does nothing (but probably should
|
||||
/// ensure ID slot is initialised correctly)
|
||||
/// </summary>
|
||||
public <xsl:value-of select="@name"/>() : base(){
|
||||
<xsl:call-template name="initialise-lists"/>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Automatically generated from description of entity <xsl:value-of select="@name"/>
|
||||
/// using adl2entityclass.xsl. Note that manually maintained parts of this
|
||||
/// class may be defined in a separate file called <xsl:value-of select="@name"/>.cs, q.v.
|
||||
///
|
||||
/// DO NOT EDIT THIS FILE!
|
||||
/// </summary>
|
||||
public partial class <xsl:value-of select="@name"/> : Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// Auto-generated no-args constructor; does nothing (but probably should
|
||||
/// ensure ID slot is initialised correctly)
|
||||
/// </summary>
|
||||
public <xsl:value-of select="@name"/>() : base(){
|
||||
<xsl:call-template name="initialise-lists"/>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Auto-generated overridden property for the Key slot, maps onto
|
||||
/// </summary>
|
||||
public override string KeyString {
|
||||
get {
|
||||
<xsl:choose>
|
||||
<xsl:when test="count($keynames)=0">
|
||||
return null; // No primary key; return null.
|
||||
<xsl:when test="@natural-key">
|
||||
/* natural primary key exists - not generating abstract key */
|
||||
</xsl:when>
|
||||
<xsl:when test="count($keynames)=1">
|
||||
return <xsl:value-of select="$keynames[1]/@name"/>.ToString(); // Single key.
|
||||
<xsl:when test="adl:key">
|
||||
/* primary key exists - not generating abstract key */
|
||||
|
||||
/// <summary>
|
||||
/// Auto-generated constructor; initialises each of the slots within
|
||||
/// the primary key and also all one-to-many and many-to-many slots
|
||||
/// </summary>
|
||||
public <xsl:value-of select="@name"/>( <xsl:for-each select="adl:key/adl:property">
|
||||
<xsl:variable name="csharp-type">
|
||||
<xsl:call-template name="csharp-type">
|
||||
<xsl:with-param name="property" select="."/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:value-of select="concat( $csharp-type, ' ', @name)"/>
|
||||
<xsl:if test="not( position() = last())">, </xsl:if>
|
||||
</xsl:for-each>){
|
||||
<xsl:call-template name="initialise-lists"/>
|
||||
<xsl:call-template name="initialise-messages"/>
|
||||
|
||||
<xsl:for-each select="adl:key/adl:property">
|
||||
this.<xsl:value-of select="@name"/> = <xsl:value-of select="@name"/>;
|
||||
</xsl:for-each>
|
||||
}
|
||||
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
StringBuilder result = new StringBuilder();
|
||||
<xsl:for-each select="$keynames">
|
||||
<xsl:message terminate="yes">
|
||||
ADL: ERROR: Entity '<xsl:value-of select="@name"/>' has no key. Was the
|
||||
canonicalise stage missed in the build process?
|
||||
</xsl:message>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
/// <summary>
|
||||
/// Auto-generated overridden property for the Key slot, maps onto
|
||||
/// </summary>
|
||||
public override string KeyString {
|
||||
get {
|
||||
StringBuilder result = new StringBuilder();
|
||||
<xsl:for-each select="adl:key/adl:property">
|
||||
result.Append(<xsl:value-of select="@name"/><xsl:if test="@type='entity'">.KeyString</xsl:if>);
|
||||
<xsl:if test="position()!=last()">
|
||||
result.Append('|');
|
||||
result.Append('|');
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
return result.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A user readable distinct identifying string
|
||||
/// </summary>
|
||||
public override string UserIdentifier
|
||||
{
|
||||
get {
|
||||
StringBuilder result = new StringBuilder();
|
||||
<xsl:choose>
|
||||
<xsl:when test="descendant::adl:property[@distinct='user' or @distinct='all']">
|
||||
<xsl:for-each select="descendant::adl:property[@distinct='user' or @distinct='all']">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@type='message'">
|
||||
if ( <xsl:value-of select="@name"/> != null)
|
||||
result.Append( <xsl:value-of select="concat( @name, '.LocalText')"/>);
|
||||
</xsl:when>
|
||||
<xsl:when test="@type='entity'">
|
||||
<!-- TODO: this is dangerous and could potentially give rise to
|
||||
infinite loops; find a way of stopping it running away! -->
|
||||
if ( <xsl:value-of select="@name"/> != null)
|
||||
result.Append( <xsl:value-of select="concat( @name, '.UserIdentifier')"/>);
|
||||
</xsl:when>
|
||||
<xsl:when test="@type='date'">
|
||||
<!-- if what we've got is just a date, we only want to see the date part of it -->
|
||||
if ( <xsl:value-of select="@name"/> != null)
|
||||
result.Append(<xsl:value-of select="@name"/>.ToString( "d"));
|
||||
</xsl:when>
|
||||
<xsl:when test="@type='time'">
|
||||
<!-- if what we've got is just a time, we only want to see the time part of it -->
|
||||
if ( <xsl:value-of select="@name"/> != null)
|
||||
result.Append(<xsl:value-of select="@name"/>.ToString( "t"));
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
if ( <xsl:value-of select="@name"/> != null)
|
||||
result.Append(<xsl:value-of select="@name"/>);
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:choose>
|
||||
<xsl:when test="position() = last()"/>
|
||||
<xsl:otherwise>
|
||||
result.Append( ", ");
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
result.AppendFormat( "<xsl:value-of select="@name"/>#{0}", KeyString);
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
||||
return result.ToString();
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If I should not be deleted, return a message explaining why I should not be deleted; else null.
|
||||
/// </summary>
|
||||
/// <returns>a message explaining why I should not be deleted; else null</returns>
|
||||
public override string NoDeleteReason {
|
||||
get {
|
||||
string result = null;
|
||||
<xsl:if test="adl:property[@type='list']|adl:property[@type='link']">
|
||||
StringBuilder bob = new StringBuilder();
|
||||
<!-- TODO: we ought to start worrying about internationalisation NOW, not later! -->
|
||||
|
||||
<xsl:for-each select="adl:property[@type='list']|adl:property[@type='link']">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@cascade='manual'"/>
|
||||
<xsl:when test="@cascade='all'"/>
|
||||
<xsl:when test="@cascade='all-delete-orphan'"/>
|
||||
<xsl:when test="@cascade='delete'"/>
|
||||
<xsl:when test="@concrete='false'"/>
|
||||
<xsl:otherwise>
|
||||
if ( <xsl:value-of select="concat( ' _', @name)"/> != null && <xsl:value-of select="concat( ' _', @name)"/>.Count > 0) {
|
||||
bob.AppendFormat("Cannot delete this <xsl:value-of select="../@name"/> as it has {0} dependent <xsl:value-of select="@name"/>; ", <xsl:value-of select="concat( ' _', @name)"/>.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A user readable distinct identifying string
|
||||
/// </summary>
|
||||
public override string UserIdentifier {
|
||||
get {
|
||||
StringBuilder result = new StringBuilder();
|
||||
<xsl:choose>
|
||||
<xsl:when test="a:key/a:property">
|
||||
<xsl:for-each select="a:key/a:property">
|
||||
result.Append(<xsl:value-of select="@name"/><xsl:if test="@type='entity'">.UserIdentifier</xsl:if>);
|
||||
<xsl:if test="position() != last()">
|
||||
result.Append( ", ");
|
||||
</xsl:if>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
result.AppendFormat( "<xsl:value-of select="@name"/>#{0}", <xsl:call-template name="list-properties"/>);
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
||||
return result.ToString();
|
||||
if (bob.Length > 0) {
|
||||
result = bob.ToString();
|
||||
}
|
||||
</xsl:if>
|
||||
return result;
|
||||
}
|
||||
}
|
||||
<!-- 'descendant' to catch properties inside keys as well as properties which are direct children -->
|
||||
<xsl:apply-templates select="descendant::adl:property"/>
|
||||
}
|
||||
}
|
||||
|
||||
<xsl:apply-templates select="a:key/a:property|a:property|a:set|a:one-to-one"/>
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- [ cut here: next file 'junk'] ------------------------- */
|
||||
|
||||
</xsl:template>
|
||||
|
||||
<!-- Creates a comma-separated list of all the properties passed in, or all the key properties by default. -->
|
||||
<xsl:template name="list-properties">
|
||||
<xsl:param name="props" select="a:key/a:property"/>
|
||||
<xsl:if test="count($props)!=0">
|
||||
<xsl:value-of select="$props[1]/@name"/>
|
||||
<xsl:if test="count($props)!=1">, </xsl:if>
|
||||
<xsl:call-template name="list-properties">
|
||||
<xsl:with-param name="props" select="$props[position()!=1]"/>
|
||||
</xsl:call-template>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="a:property[@concrete='false']">
|
||||
<xsl:template match="adl:property[@concrete='false']">
|
||||
<!-- generate nothing for non-concrete properties -->
|
||||
/* NOTE: property '<xsl:value-of select="@name"/>' is marked as being abstract; it must
|
||||
* be supported by manually maintained code */
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="adl:property">
|
||||
// auto generating iv/property pair for slot with name <xsl:value-of select="@name"/>
|
||||
<xsl:apply-templates select="help"/>
|
||||
|
||||
<xsl:template match="a:property">
|
||||
// auto generating iv/property pair for slot with name <xsl:value-of select="@name"/>
|
||||
<xsl:apply-templates select="a:help"/>
|
||||
|
||||
<xsl:variable name="type-nullable">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@type='link' or @type='list' or @type='entity'">true</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="type-nullable">
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:variable name="base-type">
|
||||
<xsl:call-template name="base-type">
|
||||
<xsl:with-param name="property" select="."/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="type">
|
||||
<xsl:variable name="csharp-type">
|
||||
<xsl:call-template name="csharp-type">
|
||||
<xsl:with-param name="property" select="."/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="nullable-decoration">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@type = 'link'">
|
||||
ICollection<<xsl:value-of select="@entity"/>>
|
||||
</xsl:when>
|
||||
<xsl:when test="@type = 'list'">
|
||||
ICollection<<xsl:value-of select="@entity"/>>
|
||||
</xsl:when>
|
||||
<xsl:when test="@type = 'entity'">
|
||||
<xsl:value-of select="@entity"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="type-declarator">
|
||||
<xsl:with-param name="nullable" select="@not-null!='true'"/>
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
<xsl:when test="@required='true'"/>
|
||||
<!-- when required is 'true' null is not permitted anyway; otherwise... -->
|
||||
<xsl:when test="@type='message'"/>
|
||||
<xsl:when test="$base-type='entity'"/>
|
||||
<xsl:when test="$base-type='string'"/>
|
||||
<xsl:when test="$base-type='text'"/>
|
||||
<!-- entities and strings are always nullable, don't need decoration -->
|
||||
<xsl:when test="$base-type='list'"/>
|
||||
<xsl:when test="$base-type='link'"/>
|
||||
<!-- things which are collections are not nullable -->
|
||||
<xsl:otherwise>?</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="initialiser">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@default">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$type = 'String'">
|
||||
<xsl:when test="$csharp-type = 'String'">
|
||||
= "<xsl:value-of select="@default"/>"
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
|
|
@ -213,178 +293,166 @@
|
|||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
<xsl:when test="normalize-space( $nullable-decoration) = '?'"> = null</xsl:when>
|
||||
<xsl:when test="$base-type = 'Boolean'"> = false</xsl:when>
|
||||
<xsl:when test="$base-type = 'int'"> = 0</xsl:when>
|
||||
<xsl:when test="$csharp-type = 'Decimal'"> = 0.0M</xsl:when>
|
||||
<xsl:when test="$base-type = 'real'"> = 0.0</xsl:when>
|
||||
<xsl:when test="$base-type='String'"> = null</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="validationpattern">
|
||||
<xsl:if test="not(@type='link' or @type='list' or @type='entity')">
|
||||
<xsl:call-template name="type-attr">
|
||||
<xsl:with-param name="attr" select="'pattern'" />
|
||||
</xsl:call-template>
|
||||
</xsl:if>
|
||||
<xsl:choose>
|
||||
<xsl:when test="@type='defined'">
|
||||
<xsl:variable name="definition">
|
||||
<xsl:value-of select="@typedef"/>
|
||||
</xsl:variable>
|
||||
<xsl:value-of select="//adl:typedef[@name=$definition]/@pattern"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<xsl:if test="string-length( $validationpattern) > 0">
|
||||
private Regex <xsl:value-of select="@name"/>Validator = new Regex( "<xsl:value-of select="$validationpattern"/>");
|
||||
private Regex <xsl:value-of select="@name"/>Validator = new Regex( "<xsl:value-of select="$validationpattern"/>");
|
||||
</xsl:if>
|
||||
|
||||
private <xsl:value-of select="$type"/> <xsl:value-of select="concat( '_', @name)"/> <xsl:value-of select="$initialiser"/>;
|
||||
private <xsl:value-of select="normalize-space( $csharp-type)"/><xsl:value-of select="normalize-space( $nullable-decoration)"/> <xsl:value-of select="concat( ' _', @name)"/> <xsl:value-of select="normalize-space( $initialiser)"/>;
|
||||
|
||||
public virtual <xsl:value-of select="$type"/><xsl:text> </xsl:text> <xsl:value-of select="@name"/>
|
||||
{
|
||||
get { return <xsl:value-of select="concat( '_', @name)"/>; }
|
||||
set {
|
||||
<xsl:if test="@not-null='true' and $type-nullable='true'">
|
||||
if ( value == null)
|
||||
{
|
||||
throw new DataRequiredException( <xsl:choose>
|
||||
<xsl:when test="ifmissing[@locale=$lang]">
|
||||
<xsl:apply-templates select="ifmissing"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
"The value for <xsl:value-of select="@name"/> may not be set to null"
|
||||
/// <summary>
|
||||
/// <xsl:choose>
|
||||
<xsl:when test="adl:documentation">
|
||||
<xsl:value-of select="normalize-space( adl:documentation)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>Auto generated property for field <xsl:value-of select="@name"/></xsl:otherwise>
|
||||
</xsl:choose><xsl:if test="help[@locale=$locale]">:
|
||||
/// <xsl:value-of select="normalize-space( help[@locale=$locale])"/></xsl:if>
|
||||
/// </summary>
|
||||
public virtual <xsl:value-of select="normalize-space( $csharp-type)"/><xsl:value-of select="normalize-space( $nullable-decoration)"/><xsl:text> </xsl:text> <xsl:value-of select="@name"/>
|
||||
{
|
||||
get {
|
||||
<xsl:if test="$base-type='list'">
|
||||
if ( <xsl:value-of select="concat( ' _', @name)"/> == null) {
|
||||
<xsl:value-of select="concat( '_', @name)"/> = new HashedSet<<xsl:value-of select="@entity"/>>();
|
||||
}
|
||||
</xsl:if>
|
||||
|
||||
return <xsl:value-of select="concat( ' _', @name)"/>;
|
||||
}
|
||||
set {
|
||||
<xsl:if test="@required='true'">
|
||||
if ( value == null)
|
||||
{
|
||||
throw new DataRequiredException( <xsl:choose>
|
||||
<xsl:when test="ifmissing[@locale=$locale]">
|
||||
<xsl:apply-templates select="ifmissing"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
"The value for <xsl:value-of select="@name"/> may not be set to null"
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
);
|
||||
}
|
||||
</xsl:if>
|
||||
<xsl:if test="@type='defined'">
|
||||
<xsl:variable name="definition">
|
||||
<xsl:value-of select="@typedef"/>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="maximum">
|
||||
<xsl:value-of select="//adl:typedef[@name=$definition]/@maximum"/>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="minimum">
|
||||
<xsl:value-of select="//adl:typedef[@name=$definition]/@minimum"/>
|
||||
</xsl:variable>
|
||||
<xsl:if test="string-length( $maximum) > 0">
|
||||
if ( value > <xsl:value-of select="$maximum"/>)
|
||||
{
|
||||
throw new DataRangeException( "The maximum permitted value for <xsl:value-of select="@name"/> is <xsl:value-of select="$maximum"/>");
|
||||
}
|
||||
</xsl:if>
|
||||
<xsl:if test="string-length( $minimum) > 0">
|
||||
if ( value < <xsl:value-of select="$minimum"/>)
|
||||
{
|
||||
throw new DataRangeException( "The minimum permitted value for <xsl:value-of select="@name"/> is <xsl:value-of select="$minimum"/>");
|
||||
}
|
||||
</xsl:if>
|
||||
<xsl:if test="string-length( $validationpattern) > 0">
|
||||
if ( value != null && ! <xsl:value-of select="@name"/>Validator.IsMatch( value))
|
||||
{
|
||||
throw new DataFormatException( string.Format( "The value supplied ({0}) does not match the format required by <xsl:value-of select="@name"/>", value));
|
||||
}
|
||||
</xsl:if>
|
||||
</xsl:if>
|
||||
<xsl:if test="@size and $csharp-type='String'">
|
||||
if ( value != null && value.Length > <xsl:value-of select="@size"/>)
|
||||
{
|
||||
value = value.Substring( 0, <xsl:value-of select="@size"/>);
|
||||
}
|
||||
</xsl:if>
|
||||
<xsl:value-of select="concat( ' _', @name)"/> = value;
|
||||
}
|
||||
}
|
||||
|
||||
<xsl:if test="parent::adl:key and @type='entity'">
|
||||
/* generate primitive value getter/setter for key property of type entity (experimental) */
|
||||
<xsl:variable name="csharp-base-type">
|
||||
<xsl:call-template name="csharp-base-type">
|
||||
<xsl:with-param name="property" select="."/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
private <xsl:value-of select="concat( $csharp-base-type, ' _', @name, '_Value')"/> <xsl:choose>
|
||||
<xsl:when test="$csharp-base-type = 'Boolean'"> = false</xsl:when>
|
||||
<xsl:when test="$csharp-base-type = 'int'"> = 0</xsl:when>
|
||||
<xsl:when test="$csharp-base-type = 'Decimal'"> = 0.0M</xsl:when>
|
||||
<xsl:when test="$csharp-base-type = 'real'"> = 0.0</xsl:when>
|
||||
<xsl:when test="$csharp-base-type='String'"> = null</xsl:when>
|
||||
<xsl:otherwise>[unknown? <xsl:value-of select="$csharp-base-type"/>]
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
);
|
||||
}
|
||||
</xsl:if>
|
||||
<xsl:if test="not(@type='link' or @type='list' or @type='entity')">
|
||||
<xsl:variable name="maximum">
|
||||
<xsl:call-template name="type-attr">
|
||||
<xsl:with-param name="attr" select="'maximum'" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="minimum">
|
||||
<xsl:call-template name="type-attr">
|
||||
<xsl:with-param name="attr" select="'minimum'" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:if test="string-length( $maximum) > 0">
|
||||
if ( value > <xsl:value-of select="$maximum"/>)
|
||||
{
|
||||
throw new DataRangeException( "The maximum permitted value for <xsl:value-of select="@name"/> is <xsl:value-of select="$maximum"/>");
|
||||
</xsl:choose>;
|
||||
|
||||
public virtual <xsl:value-of select="concat( $csharp-base-type, ' ', @name, '_Value')"/> {
|
||||
get { return <xsl:value-of select="concat( '_', @name, '_Value')"/>; }
|
||||
set { <xsl:value-of select="concat( '_', @name, '_Value')"/> = value; }
|
||||
}
|
||||
</xsl:if>
|
||||
<xsl:if test="string-length( $minimum) > 0">
|
||||
if ( value < <xsl:value-of select="$minimum"/>)
|
||||
{
|
||||
throw new DataRangeException( "The minimum permitted value for <xsl:value-of select="@name"/> is <xsl:value-of select="$minimum"/>");
|
||||
}
|
||||
</xsl:if>
|
||||
<xsl:if test="string-length( $validationpattern) > 0">
|
||||
if ( value != null && ! <xsl:value-of select="@name"/>Validator.IsMatch( value))
|
||||
{
|
||||
throw new DataFormatException( string.Format( "The value supplied ({0}) does not match the format required by <xsl:value-of select="@name"/>", value));
|
||||
}
|
||||
</xsl:if>
|
||||
</xsl:if>
|
||||
<xsl:if test="@size and $type='String'">
|
||||
if ( value != null && value.Length > <xsl:value-of select="@size"/>)
|
||||
{
|
||||
value = value.Substring( 0, <xsl:value-of select="@size"/>);
|
||||
}
|
||||
</xsl:if>
|
||||
<xsl:value-of select="concat( '_', @name)"/> = value;
|
||||
}
|
||||
}
|
||||
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="a:one-to-one">
|
||||
// auto generating for one-to-one with name <xsl:value-of select="@name"/>
|
||||
private <xsl:value-of select="@class"/><xsl:text> </xsl:text>_<xsl:value-of select="@name"/>;
|
||||
|
||||
public virtual <xsl:value-of select="@class"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>
|
||||
{
|
||||
get { return _<xsl:value-of select="@name"/>; }
|
||||
set { _<xsl:value-of select="@name"/> = value; }
|
||||
}
|
||||
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="a:set[a:many-to-many]">
|
||||
// auto generating for set with name <xsl:value-of select="@name"/>, having many-to-many child
|
||||
private ICollection<<xsl:value-of
|
||||
select="a:many-to-many/@entity"/>><xsl:text> </xsl:text><xsl:value-of select="concat( '_', @name)"/>;
|
||||
|
||||
public virtual ICollection<<xsl:value-of select="a:many-to-many/@entity"/>> <xsl:value-of select="@name"/>
|
||||
{
|
||||
get { return <xsl:value-of select="concat( '_', @name)"/>; }
|
||||
set { <xsl:value-of select="concat( '_', @name)"/> = value; }
|
||||
}
|
||||
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="a:set[a:one-to-many]">
|
||||
// auto generating for set with name <xsl:value-of select="@name"/>, having one-to-many child
|
||||
private ICollection<<xsl:value-of
|
||||
select="a:one-to-many/@entity"/>><xsl:text> </xsl:text><xsl:value-of select="concat( '_', @name)"/>;
|
||||
|
||||
public virtual ICollection<<xsl:value-of select="a:one-to-many/@entity"/>> <xsl:value-of select="@name"/>
|
||||
{
|
||||
get { return <xsl:value-of select="concat( '_', @name)"/>; }
|
||||
set { <xsl:value-of select="concat( '_', @name)"/> = value; }
|
||||
}
|
||||
|
||||
</xsl:template>
|
||||
|
||||
|
||||
|
||||
|
||||
<xsl:template name="type-declarator">
|
||||
<xsl:param name="nullable" select="false()"/>
|
||||
<xsl:call-template name="type-attr">
|
||||
<xsl:with-param name="attr" select="'dotnet'"/>
|
||||
</xsl:call-template>
|
||||
<xsl:variable name="kind">
|
||||
<xsl:call-template name="type-attr">
|
||||
<xsl:with-param name="attr" select="'dotnet-kind'"/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:if test="$nullable and $kind='value'">?</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="type-nullable">
|
||||
<xsl:variable name="kind">
|
||||
<xsl:call-template name="type-attr">
|
||||
<xsl:with-param name="attr" select="'dotnet-kind'"/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:if test="$kind!='value'">true</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
|
||||
<xsl:template match="help">
|
||||
<xsl:if test="@lang=$lang">
|
||||
<!-- might conceivably be more than one line -->
|
||||
<xsl:template match="adl:help">
|
||||
<xsl:if test="@locale=$locale">
|
||||
<!-- might conceivably be more than one line -->
|
||||
<xsl:text>
|
||||
/* </xsl:text><xsl:apply-templates/> */
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
|
||||
<xsl:template match="ifmissing">
|
||||
<xsl:if test="@lang=$lang">
|
||||
<xsl:if test="@locale=$locale">
|
||||
"<xsl:value-of select="normalize-space(.)"/>"
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="initialise-lists">
|
||||
<!-- initialise all cocrete lists and links -->
|
||||
<xsl:for-each select="property[@type='list']">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@concrete='false'"/>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="concat( '_', @name)"/> = new HashedSet<<xsl:value-of select="@entity"/>>();
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
<xsl:for-each select="property[@type='link']">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@concrete='false'"/>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="concat( '_', @name)"/> = new HashedSet<<xsl:value-of select="@entity"/>>();
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
<xsl:template name="initialise-messages">
|
||||
<!-- each IV of type message needs to be initialised -->
|
||||
<xsl:for-each select="adl:property[@type='message']">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@concrete='false'"/>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="concat( ' _', @name)"/> = new Message();
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="initialise-lists">
|
||||
<!-- initialise all concrete lists and links -->
|
||||
<xsl:for-each select="adl:property[@type='list' or @type='link']">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@concrete='false'"/>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="concat( ' _', @name)"/> = new HashedSet<<xsl:value-of select="@entity"/>>();
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
Loading…
Add table
Add a link
Reference in a new issue