Bringing into line with current b_development

This commit is contained in:
sb 2008-10-02 10:43:42 +00:00
parent ffbdce8989
commit d5c557f93e
8 changed files with 1156 additions and 199 deletions

View file

@ -5,11 +5,11 @@
(c) 2007 Cygnet Solutions Ltd
Transform ADL into entity classes
Transform ADL into C# entity classes
$Author: sb $
$Revision: 1.12 $
$Date: 2008-08-26 11:10:57 $
$Revision: 1.13 $
$Date: 2008-10-02 10:43:42 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -30,7 +30,7 @@
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="locale" select="en-UK"/>
<xsl:param name="locale" select="en-GB"/>
<!-- The C# namespace within which I shall generate controllers -->
<xsl:param name="controllerns" select="Unset"/>
@ -40,7 +40,12 @@
<!-- the name and version of the product being built -->
<xsl:param name="product-version" select="'Application Description Language Framework'"/>
<!-- strings used in normalising names for constants.
NOTE NOTE NOTE:
this deliberately converts space and punctuation to underscore -->
<xsl:variable name="notpermittedinconstantname">abcdefghijklmnopqrstuvwxyz .,;:?/()</xsl:variable>
<xsl:variable name="permittedinconstantname">ABCDEFGHIJKLMNOPQRSTUVWXYZ_________</xsl:variable>
<xsl:template match="adl:application">
<xsl:apply-templates select="adl:entity"/>
@ -61,7 +66,7 @@
// (c)2007 Cygnet Solutions Ltd
//
// Automatically generated from application description using
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.12 $', 10)"/>
// adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.13 $', 10)"/>
//
// <xsl:value-of select="/adl:application/@revision"/>
//
@ -77,6 +82,8 @@
using Cygnet.Exceptions;
using Cygnet.Entities;
using Iesi.Collections.Generic;
using NHibernate;
using NHibernate.Classic;
namespace <xsl:value-of select="$entityns"/>
{
@ -85,7 +92,7 @@
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// Automatically generated from description of entity <xsl:value-of select="@name"/>
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.12 $', 10)"/>.
/// using adl2entityclass.xsl revision <xsl:value-of select="substring( '$Revision: 1.13 $', 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.
///
@ -153,7 +160,7 @@
return result.ToString();
}
}
/// &lt;summary&gt;
/// True if I have not yet been persisted to the database, else false.
/// NOTE: This code is experimental and may change!
@ -162,24 +169,24 @@
get {
Boolean result = false;
<xsl:for-each select="descendant::adl:property[adl:generator]">
<xsl:choose>
<xsl:when test="@type='integer'">
if ( <xsl:value-of select="@name"/> == 0) {
result = true;
}
</xsl:when>
<xsl:when test="@type='string'">
if ( String.IsNullOrEmpty( <xsl:value-of select="@name"/>)) {
result = true;
}
</xsl:when>
<xsl:otherwise>
/* TODO: ADL does not yet correctly generate IsNew for
* properties of type <xsl:value-of select="@type"/> */
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
return result;
<xsl:choose>
<xsl:when test="@type='integer'">
if ( <xsl:value-of select="@name"/> == 0) {
result = true;
}
</xsl:when>
<xsl:when test="@type='string'">
if ( String.IsNullOrEmpty( <xsl:value-of select="@name"/>)) {
result = true;
}
</xsl:when>
<xsl:otherwise>
/* TODO: ADL does not yet correctly generate IsNew for
* properties of type <xsl:value-of select="@type"/> */
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
return result;
}
}
@ -278,6 +285,28 @@
return result;
}
}
/// &lt;summary&gt;
/// Should I permit myself to be deleted? If I have a valid NoDeleteReason then no. Otherwise
/// I should remove my backlinks to entities which list me in lists which have 'inverse="true"'
/// &lt;/summary&gt;
/// &lt;returns&gt;a veto if I should not be deleted; else no veto&lt;/returns&gt;
public override LifecycleVeto OnDelete(ISession hibernator) {
string ndr = NoDeleteReason;
LifecycleVeto result = LifecycleVeto.NoVeto;
if ( ndr != null) {
result = LifecycleVeto.Veto;
} else {
_indeletion = true;
<xsl:for-each select="adl:property[ @type='entity']">
<!-- if the property is not a magic backlink, nulling it before deleting does no harm.
if it is a magic backlink, nulling it will(?) clear the reference at the far end. -->
<xsl:value-of select="@name"/> = null;
</xsl:for-each>
}
return result;
}
<!-- 'descendant' to catch properties inside keys as well as properties which are direct children -->
<xsl:apply-templates select="descendant::adl:property"/>
}
@ -338,7 +367,16 @@
<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:when test="$csharp-type = 'String'">
<xsl:choose>
<xsl:when test="@required='true'">
= ""
</xsl:when>
<xsl:otherwise>
= null
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:variable>
@ -356,6 +394,34 @@
private Regex <xsl:value-of select="@name"/>Validator = new Regex( "<xsl:value-of select="$validationpattern"/>");
</xsl:if>
<xsl:if test="$base-type = 'integer'">
<xsl:for-each select="adl:option">
<xsl:variable name="constname">
<xsl:call-template name="constname">
<xsl:with-param name="option" select="."/>
<xsl:with-param name="locale" select="$locale"/>
</xsl:call-template>
</xsl:variable>
public const int <xsl:value-of select="$constname"/> =
<xsl:choose>
<xsl:when test="@value">
<xsl:value-of select="@value"/>
</xsl:when>
<xsl:when test="adl:prompt[@locale='default']/@prompt">
<xsl:value-of select="adl:prompt[@locale='default']/@prompt"/>
</xsl:when>
<xsl:when test="adl:prompt[@locale=$locale]/@prompt">
<xsl:value-of select="adl:prompt[@locale=$locale]/@prompt"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
ADL: ERROR: Cannot infer a value for option
</xsl:message>
</xsl:otherwise>
</xsl:choose>;
</xsl:for-each>
</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)"/>;
/// &lt;summary&gt;
@ -371,7 +437,18 @@
/// <xsl:value-of select="normalize-space( help[@locale=$locale])"/>
</xsl:if>
/// &lt;/summary&gt;
<xsl:apply-templates select="adl:prompt"/>
<!-- TODO: this should get the size right if type = 'defined', but hasn't been tested -->
<xsl:if test="$base-type = 'string'">
<xsl:variable name="base-size">
<xsl:call-template name="base-size">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:variable>
[FieldWidth(<xsl:value-of select="$base-size"/>)]
</xsl:if>
<xsl:if test="@distinct = 'user' or @distinct = 'all'">[IsUserDistinct()]</xsl:if>
<xsl:if test="@type = 'money'">[Dimension( "money",Unit="<xsl:value-of select="ancestor::adl:application/@currency"/>")]</xsl:if>
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 {
@ -395,7 +472,7 @@
</xsl:when>
<xsl:when test="@type='boolean'"/>
<xsl:otherwise>
if ( value == null)
if ( ! _indeletion &amp;&amp; value == null)
{
throw new DataRequiredException( <xsl:choose>
<xsl:when test="ifmissing[@locale=$locale]">
@ -439,6 +516,52 @@
}
</xsl:if>
</xsl:if>
<xsl:if test="adl:option">
<xsl:choose>
<xsl:when test="$base-type = 'integer'">
<xsl:choose>
<xsl:when test="@required='true'"/>
<xsl:otherwise>
if ( value != null){
</xsl:otherwise>
</xsl:choose>
switch ( value ) {
<xsl:for-each select="adl:option">
case <xsl:call-template name="constname">
<xsl:with-param name="option" select="."/>
<xsl:with-param name="locale" select="$locale"/>
</xsl:call-template>:
</xsl:for-each>
break;
default:
throw new DataRangeException( string.Format( "The value supplied ({0}) is not an acceptable value for <xsl:value-of select="@name"/>", value));
}
<xsl:choose>
<xsl:when test="@required='true'"/>
<xsl:otherwise>
} <!-- matches brace on 'if ( value != null) {' above -->
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$base-type = 'string'">
bool acceptable = false;
<xsl:choose>
<xsl:when test="@required='true'"/>
<xsl:otherwise>
if ( value == null) { acceptable = true; } else
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="adl:option">
if ( "<xsl:value-of select="@value"/>".Equals( value)) { acceptable = true; }
<xsl:if test="position() != last()">else</xsl:if>
</xsl:for-each>
if ( ! acceptable) {
throw new DataRangeException( string.Format( "The value supplied ('{0}') is not an acceptable value for <xsl:value-of select="@name"/>", value));
}
</xsl:when>
</xsl:choose>
</xsl:if>
<xsl:if test="@size and $csharp-type='String'">
if ( value != null &amp;&amp; value.Length > <xsl:value-of select="@size"/>)
{
@ -488,6 +611,10 @@
</xsl:if>
</xsl:template>
<xsl:template match="adl:prompt">
[LocalisedDisplayName( "<xsl:value-of select="@prompt"/>", Locale="<xsl:value-of select="@locale"/>")]
</xsl:template>
<xsl:template match="ifmissing">
<xsl:if test="@locale=$locale">
"<xsl:value-of select="normalize-space(.)"/>"
@ -518,4 +645,31 @@
</xsl:for-each>
</xsl:template>
<!-- produce a name for a constant value from an option entity -->
<xsl:template name="constname">
<xsl:param name="option"/>
<xsl:param name="locale"/>
<xsl:variable name="unnormalisedname">
<xsl:choose>
<xsl:when test="$option/adl:prompt[@locale='default']">
<xsl:value-of select="concat( $option/ancestor::adl:property/@name, '_',
$option/adl:prompt[@locale='default']/@prompt, '_value')"/>
</xsl:when>
<xsl:when test="$option/adl:prompt[@locale=$locale]">
<xsl:value-of select="concat( $option/ancestor::adl:property/@name, '_',
$option/adl:prompt[@locale=$locale]/@prompt, '_value')"/>
</xsl:when>
<xsl:when test="$option/@value">
<xsl:value-of select="concat( $option/ancestor::adl:property/@name, '_',
$option/@value, '_value')"/>
</xsl:when>
<xsl:otherwise>
<!-- this one's dodgy but shouldn't be hit often (perhaps never) -->
<xsl:value-of select="concat( $option/ancestor::adl:property/@name, '_',
position(), '_value')"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="translate($unnormalisedname,
$notpermittedinconstantname, $permittedinconstantname)"/>
</xsl:template>
</xsl:stylesheet>