bug 1946: rewritten UserIdentifier generator to fix this, along with many other changes including extensive refactoring of adl2controllerclasses.

This commit is contained in:
sb 2008-06-06 15:52:48 +00:00
parent f5b524e5c7
commit 8f5573d224
3 changed files with 1035 additions and 1084 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!-- <!--
Application Description Language framework Application Description Language framework
adl2entityclass.xsl adl2entityclass.xsl
@ -8,11 +8,11 @@
Transform ADL into entity classes Transform ADL into entity classes
$Author: sb $ $Author: sb $
$Revision: 1.5 $ $Revision: 1.6 $
$Date: 2008-05-29 16:39:38 $ $Date: 2008-06-06 15:52:48 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
Whitespace (or lack of it) is significant! --> Whitespace (or lack of it) is significant! -->
<xsl:stylesheet version="1.0" <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
@ -53,383 +53,390 @@
/* ---- [ cut here: next file '<xsl:value-of select="@name"/>.auto.cs'] ---------------- */ /* ---- [ cut here: next file '<xsl:value-of select="@name"/>.auto.cs'] ---------------- */
//------------------------------------------------------------- //-------------------------------------------------------------
// //
// <xsl:value-of select="$product-version"/> // <xsl:value-of select="$product-version"/>
// <xsl:value-of select="@name"/>.auto.cs // <xsl:value-of select="@name"/>.auto.cs
// //
// (c)2007 Cygnet Solutions Ltd // (c)2007 Cygnet Solutions Ltd
// //
// Automatically generated from application description using // Automatically generated from application description using
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.5 $', 10)"/> // adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.6 $', 10)"/>
// //
// This file is automatically generated; DO NOT EDIT IT. // This file is automatically generated; DO NOT EDIT IT.
// //
//------------------------------------------------------------- //-------------------------------------------------------------
namespace <xsl:value-of select="$entityns"/> using System;
{ using System.Configuration;
using System; using System.Collections;
using System.Configuration; using System.Collections.Generic;
using System.Collections; using System.Text;
using System.Collections.Generic; using System.Text.RegularExpressions;
using System.Text; using Cygnet.Exceptions;
using System.Text.RegularExpressions; using Cygnet.Entities;
using Cygnet.Exceptions; using Iesi.Collections.Generic;
using Cygnet.Entities;
using Iesi.Collections.Generic;
/// &lt;summary&gt; namespace <xsl:value-of select="$entityns"/>
/// <xsl:value-of select="normalize-space( adl:documentation)"/> {
/// &lt;/summary&gt; /// &lt;summary&gt;
/// &lt;remarks&gt; /// <xsl:value-of select="normalize-space( adl:documentation)"/>
/// Automatically generated from description of entity <xsl:value-of select="@name"/> /// &lt;/summary&gt;
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.5 $', 10)"/>. /// &lt;remarks&gt;
/// Note that manually maintained parts of this class may be defined in /// Automatically generated from description of entity <xsl:value-of select="@name"/>
/// a separate file called <xsl:value-of select="@name"/>.manual.cs, q.v. /// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.6 $', 10)"/>.
/// /// Note that manually maintained parts of this class may be defined in
/// DO NOT EDIT THIS FILE! /// a separate file called <xsl:value-of select="@name"/>.manual.cs, q.v.
/// &lt;/remarks&gt; ///
public partial class <xsl:value-of select="@name"/> : Entity /// DO NOT EDIT THIS FILE!
{ /// &lt;/remarks&gt;
/// &lt;summary&gt; public partial class <xsl:value-of select="@name"/> : Entity
/// Auto-generated no-args constructor; does nothing (but probably should {
/// ensure ID slot is initialised correctly) /// &lt;summary&gt;
/// &lt;/summary&gt; /// Auto-generated no-args constructor; does nothing (but probably should
public <xsl:value-of select="@name"/>() : base(){ /// ensure ID slot is initialised correctly)
<xsl:call-template name="initialise-lists"/> /// &lt;/summary&gt;
} public <xsl:value-of select="@name"/>() : base(){
<xsl:call-template name="initialise-lists"/>
}
<xsl:choose> <xsl:choose>
<xsl:when test="@natural-key"> <xsl:when test="@natural-key">
/* natural primary key exists - not generating abstract key */ /* natural primary key exists - not generating abstract key */
</xsl:when> </xsl:when>
<xsl:when test="adl:key"> <xsl:when test="adl:key">
/* primary key exists - not generating abstract key */ /* primary key exists - not generating abstract key */
/// &lt;summary&gt; /// &lt;summary&gt;
/// Auto-generated constructor; initialises each of the slots within /// Auto-generated constructor; initialises each of the slots within
/// the primary key and also all one-to-many and many-to-many slots /// the primary key and also all one-to-many and many-to-many slots
/// &lt;/summary&gt; /// &lt;/summary&gt;
public <xsl:value-of select="@name"/>( <xsl:for-each select="adl:key/adl:property"> public <xsl:value-of select="@name"/>( <xsl:for-each select="adl:key/adl:property">
<xsl:variable name="csharp-type"> <xsl:variable name="csharp-type">
<xsl:call-template name="csharp-type"> <xsl:call-template name="csharp-type">
<xsl:with-param name="property" select="."/> <xsl:with-param name="property" select="."/>
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable>
<xsl:value-of select="concat( $csharp-type, ' ', @name)"/> <xsl:value-of select="concat( $csharp-type, ' ', @name)"/>
<xsl:if test="not( position() = last())">, </xsl:if> <xsl:if test="not( position() = last())">, </xsl:if>
</xsl:for-each>){ </xsl:for-each>){
<xsl:call-template name="initialise-lists"/> <xsl:call-template name="initialise-lists"/>
<xsl:call-template name="initialise-messages"/> <xsl:call-template name="initialise-messages"/>
<xsl:for-each select="adl:key/adl:property"> <xsl:for-each select="adl:key/adl:property">
this.<xsl:value-of select="@name"/> = <xsl:value-of select="@name"/>; this.<xsl:value-of select="@name"/> = <xsl:value-of select="@name"/>;
</xsl:for-each> </xsl:for-each>
} }
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:message terminate="yes"> <xsl:message terminate="yes">
ADL: ERROR: Entity '<xsl:value-of select="@name"/>' has no key. Was the ADL: ERROR: Entity '<xsl:value-of select="@name"/>' has no key. Was the
canonicalise stage missed in the build process? canonicalise stage missed in the build process?
</xsl:message> </xsl:message>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
/// &lt;summary&gt; /// &lt;summary&gt;
/// Auto-generated overridden property for the Key slot, maps onto /// Auto-generated overridden property for the Key slot, maps onto
/// &lt;/summary&gt; /// &lt;/summary&gt;
public override string KeyString { public override string KeyString {
get { get {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
<xsl:for-each select="adl:key/adl:property"> <xsl:for-each select="adl:key/adl:property">
result.Append(<xsl:value-of select="@name"/><xsl:if test="@type='entity'">.KeyString</xsl:if>); result.Append(<xsl:value-of select="@name"/><xsl:if test="@type='entity'">.KeyString</xsl:if>);
<xsl:if test="position()!=last()"> <xsl:if test="position()!=last()">
result.Append('|'); result.Append('|');
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
return result.ToString(); return result.ToString();
} }
} }
/// &lt;summary&gt; /// &lt;summary&gt;
/// A user readable distinct identifying string /// A user readable distinct identifying string
/// &lt;/summary&gt; /// &lt;/summary&gt;
public override string UserIdentifier public override string UserIdentifier
{ {
get { get {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
<xsl:choose> <xsl:choose>
<xsl:when test="descendant::adl:property[@distinct='user' or @distinct='all']"> <xsl:when test="descendant::adl:property[@distinct='user' or @distinct='all']">
<xsl:for-each select="descendant::adl:property[@distinct='user' or @distinct='all']"> <xsl:for-each select="descendant::adl:property[@distinct='user' or @distinct='all']">
<xsl:choose> if ( <xsl:value-of select="@name"/> != null){
<xsl:when test="@type='message'"> <xsl:choose>
if ( <xsl:value-of select="@name"/> != null) <xsl:when test="@type='message'">
result.Append( <xsl:value-of select="concat( @name, '.LocalText')"/>); result.Append( <xsl:value-of select="concat( @name, '.LocalText')"/>);
</xsl:when> </xsl:when>
<xsl:when test="@type='entity'"> <xsl:when test="@type='entity'">
<!-- TODO: this is dangerous and could potentially give rise to <!-- TODO: this is dangerous and could potentially give rise to
infinite loops; find a way of stopping it running away! --> 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')"/>);
result.Append( <xsl:value-of select="concat( @name, '.UserIdentifier')"/>); </xsl:when>
</xsl:when> <xsl:when test="@type='date'">
<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 what we've got is just a date, we only want to see the date part of it --> result.Append(<xsl:value-of select="@name"/>.ToString( "d"));
if ( <xsl:value-of select="@name"/> != null) </xsl:when>
result.Append(<xsl:value-of select="@name"/>.ToString( "d")); <xsl:when test="@type='time'">
</xsl:when> <!-- if what we've got is just a time, we only want to see the time part of it -->
<xsl:when test="@type='time'"> result.Append(<xsl:value-of select="@name"/>.ToString( "t"));
<!-- if what we've got is just a time, we only want to see the time part of it --> </xsl:when>
if ( <xsl:value-of select="@name"/> != null) <xsl:otherwise>
result.Append(<xsl:value-of select="@name"/>.ToString( "t")); result.Append(<xsl:value-of select="@name"/>);
</xsl:when> </xsl:otherwise>
<xsl:otherwise> </xsl:choose>
if ( <xsl:value-of select="@name"/> != null) <xsl:choose>
result.Append(<xsl:value-of select="@name"/>); <xsl:when test="position() = last()"/>
</xsl:otherwise> <xsl:otherwise>
</xsl:choose> result.Append( ",");
<xsl:choose> </xsl:otherwise>
<xsl:when test="position() = last()"/> </xsl:choose>
<xsl:otherwise> }
result.Append( ", "); </xsl:for-each>
</xsl:otherwise> </xsl:when>
</xsl:choose> <xsl:otherwise>
</xsl:for-each> result.AppendFormat( "<xsl:value-of select="@name"/>#{0}", KeyString);
</xsl:when> </xsl:otherwise>
<xsl:otherwise> </xsl:choose>
result.AppendFormat( "<xsl:value-of select="@name"/>#{0}", KeyString);
</xsl:otherwise>
</xsl:choose>
return result.ToString(); return result.ToString();
} }
} }
/// &lt;summary&gt; /// &lt;summary&gt;
/// If I should not be deleted, return a message explaining why I should not be deleted; else null. /// If I should not be deleted, return a message explaining why I should not be deleted; else null.
/// &lt;/summary&gt; /// &lt;/summary&gt;
/// &lt;returns&gt;a message explaining why I should not be deleted; else null&lt;/returns&gt; /// &lt;returns&gt;a message explaining why I should not be deleted; else null&lt;/returns&gt;
public override string NoDeleteReason { public override string NoDeleteReason {
get { get {
string result = null; string result = null;
<xsl:if test="adl:property[@type='list']|adl:property[@type='link']"> <xsl:if test="adl:property[@type='list']|adl:property[@type='link']">
StringBuilder bob = new StringBuilder(); StringBuilder bob = new StringBuilder();
<!-- TODO: we ought to start worrying about internationalisation NOW, not later! --> <!-- TODO: we ought to start worrying about internationalisation NOW, not later! -->
<xsl:for-each select="adl:property[@type='list']|adl:property[@type='link']"> <xsl:for-each select="adl:property[@type='list']|adl:property[@type='link']">
<xsl:choose> <xsl:choose>
<xsl:when test="@cascade='manual'"/> <xsl:when test="@cascade='manual'"/>
<xsl:when test="@cascade='all'"/> <xsl:when test="@cascade='all'"/>
<xsl:when test="@cascade='all-delete-orphan'"/> <xsl:when test="@cascade='all-delete-orphan'"/>
<xsl:when test="@cascade='delete'"/> <xsl:when test="@cascade='delete'"/>
<xsl:when test="@concrete='false'"/> <xsl:when test="@concrete='false'"/>
<xsl:otherwise> <xsl:otherwise>
if ( <xsl:value-of select="concat( ' _', @name)"/> != null &amp;&amp; <xsl:value-of select="concat( ' _', @name)"/>.Count > 0) { if ( <xsl:value-of select="concat( ' _', @name)"/> != null &amp;&amp; <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); 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);
} }
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:for-each> </xsl:for-each>
if (bob.Length > 0) { if (bob.Length > 0) {
result = bob.ToString(); result = bob.ToString();
} }
</xsl:if> </xsl:if>
return result; return result;
} }
} }
<!-- 'descendant' to catch properties inside keys as well as properties which are direct children --> <!-- '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="descendant::adl:property"/>
} }
} }
/* ---- [ cut here: next file 'junk'] ------------------------- */ /* ---- [ cut here: next file 'junk'] ------------------------- */
</xsl:template> </xsl:template>
<xsl:template match="adl:property[@concrete='false']"> <xsl:template match="adl:property[@concrete='false']">
<!-- generate nothing for non-concrete properties --> <!-- generate nothing for non-concrete properties -->
/* NOTE: property '<xsl:value-of select="@name"/>' is marked as being abstract; it must /* NOTE: property '<xsl:value-of select="@name"/>' is marked as being abstract; it must
* be supported by manually maintained code */ * be supported by manually maintained code */
</xsl:template> </xsl:template>
<xsl:template match="adl:property"> <xsl:template match="adl:property">
// auto generating iv/property pair for slot with name <xsl:value-of select="@name"/> // auto generating iv/property pair for slot with name <xsl:value-of select="@name"/>
<xsl:apply-templates select="help"/> <xsl:apply-templates select="help"/>
<xsl:variable name="base-type"> <xsl:variable name="base-type">
<xsl:call-template name="base-type"> <xsl:call-template name="base-type">
<xsl:with-param name="property" select="."/> <xsl:with-param name="property" select="."/>
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable>
<xsl:variable name="csharp-type"> <xsl:variable name="csharp-type">
<xsl:call-template name="csharp-type"> <xsl:call-template name="csharp-type">
<xsl:with-param name="property" select="."/> <xsl:with-param name="property" select="."/>
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable>
<xsl:variable name="nullable-decoration"> <xsl:variable name="nullable-decoration">
<xsl:choose> <xsl:choose>
<xsl:when test="@required='true'"/> <xsl:when test="@required='true'"/>
<!-- when required is 'true' null is not permitted anyway; otherwise... --> <!-- when required is 'true' null is not permitted anyway; otherwise... -->
<xsl:when test="@type='message'"/> <xsl:when test="@type='message'"/>
<xsl:when test="$base-type='entity'"/> <xsl:when test="$base-type='entity'"/>
<xsl:when test="$base-type='string'"/> <xsl:when test="$base-type='string'"/>
<xsl:when test="$base-type='text'"/> <xsl:when test="$base-type='text'"/>
<!-- entities and strings are always nullable, don't need decoration --> <!-- entities and strings are always nullable, don't need decoration -->
<xsl:when test="$base-type='list'"/> <xsl:when test="$base-type='list'"/>
<xsl:when test="$base-type='link'"/> <xsl:when test="$base-type='link'"/>
<!-- things which are collections are not nullable --> <!-- things which are collections are not nullable -->
<xsl:otherwise>?</xsl:otherwise> <xsl:otherwise>?</xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<xsl:variable name="initialiser"> <xsl:variable name="initialiser">
<xsl:choose> <xsl:choose>
<xsl:when test="@default"> <xsl:when test="@default">
<xsl:choose> <xsl:choose>
<xsl:when test="$csharp-type = 'String'"> <xsl:when test="$csharp-type = 'String'">
= "<xsl:value-of select="@default"/>" = "<xsl:value-of select="@default"/>"
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
= <xsl:value-of select="@default"/> = <xsl:value-of select="@default"/>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:when> </xsl:when>
<xsl:when test="normalize-space( $nullable-decoration) = '?'"> = null</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 = 'Boolean'"> = false</xsl:when>
<xsl:when test="$base-type = 'int'"> = 0</xsl:when> <xsl:when test="$base-type = 'int'"> = 0</xsl:when>
<xsl:when test="$csharp-type = 'Decimal'"> = 0.0M</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 = 'real'"> = 0.0</xsl:when>
<xsl:when test="$base-type='String'"> = null</xsl:when> <xsl:when test="$base-type='String'"> = null</xsl:when>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<xsl:variable name="validationpattern"> <xsl:variable name="validationpattern">
<xsl:choose> <xsl:choose>
<xsl:when test="@type='defined'"> <xsl:when test="@type='defined'">
<xsl:variable name="definition"> <xsl:variable name="definition">
<xsl:value-of select="@typedef"/> <xsl:value-of select="@typedef"/>
</xsl:variable> </xsl:variable>
<xsl:value-of select="//adl:typedef[@name=$definition]/@pattern"/> <xsl:value-of select="//adl:typedef[@name=$definition]/@pattern"/>
</xsl:when> </xsl:when>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<xsl:if test="string-length( $validationpattern) &gt; 0"> <xsl:if test="string-length( $validationpattern) &gt; 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> </xsl:if>
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)"/>; 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)"/>;
/// &lt;summary&gt; /// &lt;summary&gt;
/// <xsl:choose> <xsl:choose>
<xsl:when test="adl:documentation"> <xsl:when test="adl:documentation">
<xsl:value-of select="normalize-space( adl:documentation)"/> /// <xsl:value-of select="normalize-space( adl:documentation)"/>
</xsl:when> </xsl:when>
<xsl:otherwise>Auto generated property for field <xsl:value-of select="@name"/></xsl:otherwise> <xsl:otherwise>
</xsl:choose><xsl:if test="help[@locale=$locale]">: /// Auto generated property for field <xsl:value-of select="@name"/>
/// <xsl:value-of select="normalize-space( help[@locale=$locale])"/></xsl:if> </xsl:otherwise>
/// &lt;/summary&gt; </xsl:choose>
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"/> <xsl:if test="help[@locale=$locale]">
{ /// <xsl:value-of select="normalize-space( help[@locale=$locale])"/>
get { </xsl:if>
<xsl:if test="$base-type='list'"> /// &lt;/summary&gt;
if ( <xsl:value-of select="concat( ' _', @name)"/> == null) { 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"/>
<xsl:value-of select="concat( '_', @name)"/> = new HashedSet&lt;<xsl:value-of select="@entity"/>&gt;(); {
} get {
</xsl:if> <xsl:if test="$base-type='list'">
if ( <xsl:value-of select="concat( ' _', @name)"/> == null) {
<xsl:value-of select="concat( '_', @name)"/> = new HashedSet&lt;<xsl:value-of select="@entity"/>&gt;();
}
</xsl:if>
return <xsl:value-of select="concat( ' _', @name)"/>; return <xsl:value-of select="concat( ' _', @name)"/>;
} }
set { set {
<xsl:if test="@required='true'"> <xsl:if test="@required='true'">
if ( value == null) if ( value == null)
{ {
throw new DataRequiredException( <xsl:choose> throw new DataRequiredException( <xsl:choose>
<xsl:when test="ifmissing[@locale=$locale]"> <xsl:when test="ifmissing[@locale=$locale]">
<xsl:apply-templates select="ifmissing"/> <xsl:apply-templates select="ifmissing"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
"The value for <xsl:value-of select="@name"/> may not be set to null" "The value for <xsl:value-of select="@name"/> may not be set to null"
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
); );
} }
</xsl:if> </xsl:if>
<xsl:if test="@type='defined'"> <xsl:if test="@type='defined'">
<xsl:variable name="definition"> <xsl:variable name="definition">
<xsl:value-of select="@typedef"/> <xsl:value-of select="@typedef"/>
</xsl:variable> </xsl:variable>
<xsl:variable name="maximum"> <xsl:variable name="maximum">
<xsl:value-of select="//adl:typedef[@name=$definition]/@maximum"/> <xsl:value-of select="//adl:typedef[@name=$definition]/@maximum"/>
</xsl:variable> </xsl:variable>
<xsl:variable name="minimum"> <xsl:variable name="minimum">
<xsl:value-of select="//adl:typedef[@name=$definition]/@minimum"/> <xsl:value-of select="//adl:typedef[@name=$definition]/@minimum"/>
</xsl:variable> </xsl:variable>
<xsl:if test="string-length( $maximum) &gt; 0"> <xsl:if test="string-length( $maximum) &gt; 0">
if ( value &gt; <xsl:value-of select="$maximum"/>) if ( value &gt; <xsl:value-of select="$maximum"/>)
{ {
throw new DataRangeException( "The maximum permitted value for <xsl:value-of select="@name"/> is <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>
<xsl:if test="string-length( $minimum) &gt; 0"> <xsl:if test="string-length( $minimum) &gt; 0">
if ( value &lt; <xsl:value-of select="$minimum"/>) if ( value &lt; <xsl:value-of select="$minimum"/>)
{ {
throw new DataRangeException( "The minimum permitted value for <xsl:value-of select="@name"/> is <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>
<xsl:if test="string-length( $validationpattern) &gt; 0"> <xsl:if test="string-length( $validationpattern) &gt; 0">
if ( value != null &amp;&amp; ! <xsl:value-of select="@name"/>Validator.IsMatch( value)) if ( value != null &amp;&amp; ! <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)); 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> </xsl:if>
<xsl:if test="@size and $csharp-type='String'"> <xsl:if test="@size and $csharp-type='String'">
if ( value != null &amp;&amp; value.Length > <xsl:value-of select="@size"/>) if ( value != null &amp;&amp; value.Length > <xsl:value-of select="@size"/>)
{ {
value = value.Substring( 0, <xsl:value-of select="@size"/>); value = value.Substring( 0, <xsl:value-of select="@size"/>);
} }
</xsl:if> </xsl:if>
<xsl:value-of select="concat( ' _', @name)"/> = value; <xsl:value-of select="concat( ' _', @name)"/> = value;
} }
} }
<xsl:if test="parent::adl:key and @type='entity'"> <xsl:if test="parent::adl:key and @type='entity'">
/* generate primitive value getter/setter for key property of type entity (experimental) */ /// &lt;summary&gt;
<xsl:variable name="csharp-base-type"> /// auto generated primitive value for key property of type entity (experimental)
<xsl:call-template name="csharp-base-type"> /// &lt;/summary&gt;
<xsl:with-param name="property" select="."/> <xsl:variable name="csharp-base-type">
</xsl:call-template> <xsl:call-template name="csharp-base-type">
</xsl:variable> <xsl:with-param name="property" select="."/>
private <xsl:value-of select="concat( $csharp-base-type, ' _', @name, '_Value')"/> <xsl:choose> </xsl:call-template>
<xsl:when test="$csharp-base-type = 'Boolean'"> = false</xsl:when> </xsl:variable>
<xsl:when test="$csharp-base-type = 'int'"> = 0</xsl:when> private <xsl:value-of select="concat( $csharp-base-type, ' _', @name, '_Value')"/> <xsl:choose>
<xsl:when test="$csharp-base-type = 'Decimal'"> = 0.0M</xsl:when> <xsl:when test="$csharp-base-type = 'Boolean'"> = false</xsl:when>
<xsl:when test="$csharp-base-type = 'real'"> = 0.0</xsl:when> <xsl:when test="$csharp-base-type = 'int'"> = 0</xsl:when>
<xsl:when test="$csharp-base-type='String'"> = null</xsl:when> <xsl:when test="$csharp-base-type = 'Decimal'"> = 0.0M</xsl:when>
<xsl:otherwise>[unknown? <xsl:value-of select="$csharp-base-type"/>] <xsl:when test="$csharp-base-type = 'real'"> = 0.0</xsl:when>
</xsl:otherwise> <xsl:when test="$csharp-base-type='String'"> = null</xsl:when>
</xsl:choose>; <xsl:otherwise>
[unknown? <xsl:value-of select="$csharp-base-type"/>]
</xsl:otherwise>
</xsl:choose>;
public virtual <xsl:value-of select="concat( $csharp-base-type, ' ', @name, '_Value')"/> { /// &lt;summary&gt;
get { return <xsl:value-of select="concat( '_', @name, '_Value')"/>; } /// auto generated primitive value getter/setter for key property of type entity (experimental)
set { <xsl:value-of select="concat( '_', @name, '_Value')"/> = value; } /// &lt;/summary&gt;
} public virtual <xsl:value-of select="concat( $csharp-base-type, ' ', @name, '_Value')"/> {
</xsl:if> get { return <xsl:value-of select="concat( '_', @name, '_Value')"/>; }
set { <xsl:value-of select="concat( '_', @name, '_Value')"/> = value; }
}
</xsl:if>
</xsl:template> </xsl:template>
<xsl:template match="adl:help"> <xsl:template match="adl:help">
<xsl:if test="@locale=$locale"> <xsl:if test="@locale=$locale">
<!-- might conceivably be more than one line --> <!-- might conceivably be more than one line -->
<xsl:text> <xsl:text>
/* </xsl:text><xsl:apply-templates/> */ /* </xsl:text><xsl:apply-templates/> */
</xsl:if> </xsl:if>
</xsl:template> </xsl:template>
<xsl:template match="ifmissing"> <xsl:template match="ifmissing">
<xsl:if test="@locale=$locale"> <xsl:if test="@locale=$locale">
"<xsl:value-of select="normalize-space(.)"/>" "<xsl:value-of select="normalize-space(.)"/>"
</xsl:if> </xsl:if>
</xsl:template> </xsl:template>
<xsl:template name="initialise-messages"> <xsl:template name="initialise-messages">
<!-- each IV of type message needs to be initialised --> <!-- each IV of type message needs to be initialised -->
@ -437,7 +444,7 @@
<xsl:choose> <xsl:choose>
<xsl:when test="@concrete='false'"/> <xsl:when test="@concrete='false'"/>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="concat( ' _', @name)"/> = new Message(); <xsl:value-of select="concat( ' _', @name)"/> = new Message();
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:for-each> </xsl:for-each>
@ -449,7 +456,7 @@
<xsl:choose> <xsl:choose>
<xsl:when test="@concrete='false'"/> <xsl:when test="@concrete='false'"/>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="concat( ' _', @name)"/> = new HashedSet&lt;<xsl:value-of select="@entity"/>&gt;(); <xsl:value-of select="concat( ' _', @name)"/> = new HashedSet&lt;<xsl:value-of select="@entity"/>&gt;();
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:for-each> </xsl:for-each>

View file

@ -13,8 +13,8 @@
Transform ADL into velocity view templates Transform ADL into velocity view templates
$Author: sb $ $Author: sb $
$Revision: 1.7 $ $Revision: 1.8 $
$Date: 2008-06-06 08:46:27 $ $Date: 2008-06-06 15:52:48 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
Whitespace (or lack of it) is significant! --> Whitespace (or lack of it) is significant! -->
@ -124,7 +124,7 @@
Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>, Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.7 $', 10)"/> Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.8 $', 10)"/>
</xsl:comment> </xsl:comment>
<xsl:call-template name="maybe-delete"> <xsl:call-template name="maybe-delete">
<xsl:with-param name="entity" select="."/> <xsl:with-param name="entity" select="."/>
@ -162,7 +162,7 @@
Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>, Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.7 $', 10)"/> Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.8 $', 10)"/>
</xsl:comment> </xsl:comment>
<xsl:call-template name="install-scripts"/> <xsl:call-template name="install-scripts"/>
</head> </head>
@ -243,7 +243,7 @@
Auto generated Velocity <xsl:value-of select="@name"/> form for <xsl:value-of select="ancestor::adl:entity/@name"/>, Auto generated Velocity <xsl:value-of select="@name"/> form for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.7 $', 10)"/> Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.8 $', 10)"/>
</xsl:comment> </xsl:comment>
#capturefor( title) #capturefor( title)
#if ( $instance) #if ( $instance)
@ -364,7 +364,7 @@
Auto generated Velocity form for <xsl:value-of select="ancestor::adl:entity/@name"/>, Auto generated Velocity form for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xsl <xsl:value-of select="substring( '$Revision: 1.7 $', 10)"/> Generated using adl2views.xsl <xsl:value-of select="substring( '$Revision: 1.8 $', 10)"/>
</xsl:comment> </xsl:comment>
<xsl:call-template name="install-scripts"/> <xsl:call-template name="install-scripts"/>
<script type='text/javascript' language='JavaScript1.2'> <script type='text/javascript' language='JavaScript1.2'>
@ -963,7 +963,7 @@
Auto generated Velocity list for <xsl:value-of select="@name"/>, Auto generated Velocity list for <xsl:value-of select="@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.7 $', 10)"/> Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.8 $', 10)"/>
</xsl:comment> </xsl:comment>
#capturefor( title) #capturefor( title)
@ -1002,7 +1002,7 @@
Auto generated Velocity list for <xsl:value-of select="ancestor::adl:entity/@name"/>, Auto generated Velocity list for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL. generated from ADL.
Generated using adl2listview.xsl <xsl:value-of select="substring( '$Revision: 1.7 $', 10)"/> Generated using adl2listview.xsl <xsl:value-of select="substring( '$Revision: 1.8 $', 10)"/>
</xsl:comment> </xsl:comment>
<xsl:call-template name="install-scripts"/> <xsl:call-template name="install-scripts"/>
</head> </head>
@ -1188,7 +1188,7 @@
</xsl:variable> </xsl:variable>
<xsl:choose> <xsl:choose>
<xsl:when test="@type='entity'"> <xsl:when test="@type='entity'">
<xsl:value-of select="concat( $sep, @name, '_Value=$', $entity/@name, '.', @name, '_Value')"/> <xsl:value-of select="concat( $sep, @name, '=$', $entity/@name, '.', @name, '_Value')"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="concat( $sep, @name, '=$', $entity/@name, '.', @name)"/> <xsl:value-of select="concat( $sep, @name, '=$', $entity/@name, '.', @name)"/>
@ -1327,7 +1327,7 @@
</xsl:variable> </xsl:variable>
<xsl:choose> <xsl:choose>
<xsl:when test="@type='entity'"> <xsl:when test="@type='entity'">
<xsl:value-of select="concat( $sep, @name, '_Value=$', $entity/@name, '.', @name, '_Value')"/> <xsl:value-of select="concat( $sep, @name, '=$', $entity/@name, '.', @name, '_Value')"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="concat( $sep, @name, '=$', $entity/@name, '.', @name)"/> <xsl:value-of select="concat( $sep, @name, '=$', $entity/@name, '.', @name)"/>