Now handling composite primary keys and (recursively) primary keys of type entity; also i18n handling considerably improved.

This commit is contained in:
sb 2008-03-10 17:01:26 +00:00
parent 95e8e5ae30
commit cadaf246f4
3 changed files with 270 additions and 159 deletions

View file

@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes Transform ADL into (partial) controller classes
$Author: sb $ $Author: sb $
$Revision: 1.13 $ $Revision: 1.14 $
$Date: 2008-03-05 11:05:12 $ $Date: 2008-03-10 17:01:26 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -61,11 +61,11 @@
with the revision number of the generated file if the generated file is with the revision number of the generated file if the generated file is
stored to CVS --> stored to CVS -->
<xsl:variable name="transform-rev1" <xsl:variable name="transform-rev1"
select="substring( '$Revision: 1.13 $', 11)"/> select="substring( '$Revision: 1.14 $', 11)"/>
<xsl:variable name="transform-revision" <xsl:variable name="transform-revision"
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/> select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
<xsl:variable name="key"> <!-- xsl:variable name="key">
<xsl:call-template name="primary-key-name"> <xsl:call-template name="primary-key-name">
<xsl:with-param name="entity" select="."/> <xsl:with-param name="entity" select="."/>
</xsl:call-template> </xsl:call-template>
@ -79,7 +79,7 @@
</xsl:when> </xsl:when>
<xsl:otherwise>[no primary key]</xsl:otherwise> <xsl:otherwise>[no primary key]</xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable -->
/* ---- [ cut here: next file '<xsl:value-of select="@name"/>Controller.auto.cs'] ---------------- */ /* ---- [ cut here: next file '<xsl:value-of select="@name"/>Controller.auto.cs'] ---------------- */
@ -148,83 +148,112 @@ namespace <xsl:value-of select="$controllerns"/> {
Session[NHibernateHelper.PASSTOKEN]</xsl:if>); Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
List&lt;string&gt; messages = new List&lt;string&gt;(); List&lt;string&gt; messages = new List&lt;string&gt;();
<xsl:value-of select="$entityns"/>.<xsl:value-of select="@name"/> record; <xsl:apply-templates select="descendant::adl:property"/>
<xsl:apply-templates select="adl:property"/> <xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="."/>
</xsl:call-template>
<!-- TODO: this does not corectly handle entities with composite primary keys --> if ( record == null) {
string id = Form["<xsl:value-of select="concat( 'instance.', $key)"/>"]; /* it seems to be new, create persistent object */
try {
if ( String.IsNullOrEmpty( id)) record = new <xsl:value-of select="concat($entityns, '.', @name)"/>(<xsl:for-each select="adl:key/adl:property">
{ <xsl:variable name="basetype">
/* it's new, create persistent object */ <xsl:call-template name="base-type">
record = new <xsl:value-of select="$entityns"/>.<xsl:value-of select="@name"/>(<xsl:for-each select="adl:property[@distinct='system']">Form[<xsl:value-of select="concat( 'instance.', @name)"/>]<xsl:choose> <xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$basetype='integer'">Int32.Parse( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])</xsl:when>
<xsl:when test="$basetype='entity'">
<!-- Maybe TODO: this doesn't work recursively - if an entity has a key which is an entity
and the key of that entity is an entity, you're on your own, mate! -->
<xsl:variable name="keyentity" select="@entity"/>
<xsl:variable name="keyenttype">
<xsl:call-template name="primary-key-csharp-type">
<xsl:with-param name="entity" select="//adl:entity[@name=$keyentity]"/>
</xsl:call-template>
</xsl:variable>
hibernator.CreateCriteria( typeof( <xsl:value-of select="concat( $entityns, '.', $keyentity)"/>))
.Add(Expression.Eq( "<xsl:value-of select="//adl:entity[@name=$keyentity]/adl:key/adl:property[position()=1]/@name"/>",<xsl:choose>
<xsl:when test="$keyenttype = 'int'">Int32.Parse( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"])</xsl:when>
<xsl:otherwise>Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"]</xsl:otherwise>
</xsl:choose>))
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', $keyentity)"/>&gt;()</xsl:when>
<xsl:otherwise>Form["<xsl:value-of select="concat( 'instance.', @name)"/>"]</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="position() = last()"/> <xsl:when test="position() = last()"/>
<xsl:otherwise>, </xsl:otherwise> <xsl:otherwise>, </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:for-each>); </xsl:for-each>);
}
catch ( FormatException) {
/* failed to parse a number - not wholly unexpected, since it's most likely
that an empty string was passed in */
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>();
}
catch ( NullReferenceException) {
/* again, probably more normal than otherwise */
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>();
}
/* perform any domain knowledge behaviour on the new record /* perform any domain knowledge behaviour on the new record
* after instantiation */ * after instantiation */
record.AfterCreationHook( hibernator); record.AfterCreationHook( hibernator);
messages.Add( "New <xsl:value-of select="@name"/> record created"); messages.Add( "New <xsl:value-of select="@name"/> record created");
} }
else
{
/* it's existing, retrieve it */
<!-- TODO: this does not correctly handle entities with composite primary keys -->
<xsl:choose>
<xsl:when test="adl:key/adl:property[position()=1]/@type='entity'">
<!-- Maybe TODO: this doesn't work recursively - if an entity has a key which is an entity
and the key of that entity is an entity, you're on your own, mate! -->
<xsl:variable name="keyentity" select="adl:key/adl:property[position()=1]/@entity"/>
<xsl:value-of select="$keytype"/> eid =
hibernator.CreateCriteria( typeof( <xsl:value-of select="$keytype"/>))
.Add(Expression.Eq( "<xsl:value-of select="//adl:entity[@name=$keyentity]/adl:key/adl:property[position()=1]/@name"/>", id))
.UniqueResult&lt;<xsl:value-of select="$keytype"/>&gt;();
record = if ( record != null) {
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @name)"/>)) try {
.Add(Expression.Eq("<xsl:value-of select="$key"/>", eid))
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', @name)"/>&gt;();
</xsl:when>
<xsl:otherwise>
record =
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @name)"/>))
.Add(Expression.Eq("<xsl:value-of select="$key"/>", id))
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', @name)"/>&gt;();
</xsl:otherwise>
</xsl:choose>
}
if ( record != null)
{
try
{
/* actually update the record */ /* actually update the record */
BindObjectInstance( record, ParamStore.Form, "instance"); BindObjectInstance( record, ParamStore.Form, "instance");
<xsl:for-each select="adl:property[@type='entity']"> <xsl:if test="descendant::adl:property[@type='message']">
/* there is at least one slot whose value is an internationalised message;
* if these have yet to be initialised they must be handled specially */
Locale locale = GetBestLocaleForUser();
<xsl:for-each select="descendant::adl:property[@type='message']">
if ( ! String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'i18n.instance.', @name)"/>"])){
/* there's an uninitialised message for this slot */
Message mess = record.<xsl:value-of select="@name"/>;
if ( mess == null){
mess = new Message();
}
hibernator.Save( mess);
Translation trans = mess.GetTranslationObject( locale, hibernator);
if ( trans == null) {
trans = new Translation( mess, locale);
}
trans.MessageText = Form["<xsl:value-of select="concat( 'i18n.instance.', @name)"/>"];
record.<xsl:value-of select="@name"/> = mess;
hibernator.Save( trans);
}
</xsl:for-each>
</xsl:if>
<xsl:for-each select="descendant::adl:property[@type='entity']">
/* for properties of type 'entity', it should not be necessary to do anything /* for properties of type 'entity', it should not be necessary to do anything
* special - BindObjectInstance /should/ do it all. Unfortunately it sometimes * special - BindObjectInstance /should/ do it all. Unfortunately it sometimes
* doesn't, and I haven't yet characterised why not. */ * doesn't, and I haven't yet characterised why not. */
<!-- TODO: Fix this! -->
<xsl:variable name="entityname" select="@entity"/> <xsl:variable name="entityname" select="@entity"/>
<xsl:choose>
// The broken bit: Entity name is <xsl:value-of select="$entityname"/> <xsl:when test="//adl:entity[@name=$entityname]">
<!-- <xsl:variable name="linkkeytype"> if ( ! String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"]))
<xsl:call-template name="primary-key-csharp-type"> {
<xsl:with-param name="entity" select="//entity[@name=$entityname]"/> record.<xsl:value-of select="@name"/> = <xsl:call-template name="fetch-property-instance">
</xsl:call-template> <xsl:with-param name="property" select="."/>
</xsl:variable> <xsl:with-param name="valuename" select="concat( 'instance.', @name)"/>
record.<xsl:value-of select="@name"/> = </xsl:call-template>;
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @entity)"/>)) }
.Add(Expression.Eq("<xsl:call-template name="primary-key-name"> </xsl:when>
<xsl:with-param name="entity" select="//entity[@name=@entity]"/> <xsl:otherwise>
</xsl:call-template>", ((<xsl:value-of select="$linkkeytype"/>)Form["<xsl:value-of select="concat( $entityns, '.', @entity)"/>"]))) <xsl:message terminate="yes">
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', @entity)"/>&gt;(); ADL: ERROR: Could not fix up value of <xsl:value-of select="@name "/>, because no
--> entity was found called <xsl:value-of select="$entityname"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each> </xsl:for-each>
<xsl:for-each select="property[@type='link']"> <xsl:for-each select="property[@type='link']">
@ -256,7 +285,7 @@ namespace <xsl:value-of select="$controllerns"/> {
} }
</xsl:for-each> </xsl:for-each>
<xsl:for-each select="adl:property[@type='list']"> <xsl:for-each select="descendant::adl:property[@type='list']">
/* with a list we cannot just smash the old values! Instead we need to check /* with a list we cannot just smash the old values! Instead we need to check
* each one and exclude it if no longer required */ * each one and exclude it if no longer required */
if ( Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>") != null) if ( Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>") != null)
@ -346,7 +375,7 @@ namespace <xsl:value-of select="$controllerns"/> {
} }
else else
{ {
throw new Exception( String.Format( "No record of type <xsl:value-of select="@name"/> with key value {0} found", id)); throw new DataRequiredException( "Record not found");
} }
} }
</xsl:if> </xsl:if>
@ -356,30 +385,26 @@ namespace <xsl:value-of select="$controllerns"/> {
/// &lt;summary&gt; /// &lt;summary&gt;
/// Actually delete the selected record /// Actually delete the selected record
/// &lt;/summary&gt; /// &lt;/summary&gt;
[AccessibleThrough(Verb.Get)] [AccessibleThrough(Verb.Post)]
public void Delete() public void Delete()
{ {
ISession hibernator = ISession hibernator =
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN], NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>); Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
string id = Params["<xsl:value-of select="concat( 'instance.', $key)"/>"];
string reallydelete = Params["reallydelete"]; string reallydelete = Params["reallydelete"];
if ( "true".Equals( reallydelete)) if ( "true".Equals( reallydelete))
{ {
<xsl:value-of select="concat($entityns, '.', @name)"/> record = <xsl:call-template name="fetch-instance">
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat($entityns, '.', @name)"/>)) <xsl:with-param name="entity" select="."/>
.Add(Expression.Eq("<xsl:value-of select="$key"/>", id)) </xsl:call-template>
.UniqueResult&lt;<xsl:value-of select="concat($entityns, '.', @name)"/>&gt;();
if ( record != null) if ( record != null)
{ {
record.BeforeDeleteHook( hibernator); record.BeforeDeleteHook( hibernator);
hibernator.Delete( hibernator.Delete( record);
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat($entityns, '.', @name)"/>))
.Add(Expression.Eq("<xsl:value-of select="$key"/>", id))
.UniqueResult&lt;<xsl:value-of select="concat($entityns, '.', @name)"/>&gt;());
hibernator.Flush(); hibernator.Flush();
} }
@ -461,7 +486,7 @@ namespace <xsl:value-of select="$controllerns"/> {
</xsl:template> </xsl:template>
<xsl:template match="adl:form"> <xsl:template match="adl:form">
<xsl:variable name="key"> <!-- xsl:variable name="key">
<xsl:call-template name="primary-key-name"> <xsl:call-template name="primary-key-name">
<xsl:with-param name="entity" select="ancestor::adl:entity"/> <xsl:with-param name="entity" select="ancestor::adl:entity"/>
</xsl:call-template> </xsl:call-template>
@ -470,7 +495,7 @@ namespace <xsl:value-of select="$controllerns"/> {
<xsl:call-template name="primary-key-csharp-type"> <xsl:call-template name="primary-key-csharp-type">
<xsl:with-param name="entity" select="ancestor::adl:entity"/> <xsl:with-param name="entity" select="ancestor::adl:entity"/>
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable -->
/// &lt;summary&gt; /// &lt;summary&gt;
/// Handle the submission of the form named <xsl:value-of select="@name"/> /// Handle the submission of the form named <xsl:value-of select="@name"/>
/// &lt;/summary&gt; /// &lt;/summary&gt;
@ -498,15 +523,15 @@ namespace <xsl:value-of select="$controllerns"/> {
ISession hibernator = ISession hibernator =
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN], NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>); Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
string id = Form["<xsl:value-of select="concat( 'instance.', $key)"/>"];
<xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="ancestor::adl:entity"/>
</xsl:call-template>
<xsl:if test="$authentication-layer = 'Database'"> <xsl:if test="$authentication-layer = 'Database'">
PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN];
</xsl:if> </xsl:if>
PropertyBag["instance"] = PropertyBag["instance"] = record;
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat($entityns, '.', ancestor::adl:entity/@name)"/>))
.Add(Expression.Eq("<xsl:value-of select="$key"/>", id))
.UniqueResult&lt;<xsl:value-of select="concat($entityns, '.', ancestor::adl:entity/@name)"/>&gt;();
RenderViewWithFailover( "maybedelete.vm", "maybedelete.auto.vm"); RenderViewWithFailover( "maybedelete.vm", "maybedelete.auto.vm");
} }
@ -710,6 +735,11 @@ namespace <xsl:value-of select="$controllerns"/> {
<xsl:template name="primary-key-name"> <xsl:template name="primary-key-name">
<!-- return the name of the primary key of the entity with this name --> <!-- return the name of the primary key of the entity with this name -->
<xsl:param name="entity"/> <xsl:param name="entity"/>
<xsl:if test="not($entity/adl:key)">
<xsl:message terminate="yes">
ADL: ERROR: No key for entity: <xsl:value-of select="$entity/@name"/>
</xsl:message>
</xsl:if>
<xsl:choose> <xsl:choose>
<xsl:when test="$entity/adl:key/adl:property[position()=2]"> <xsl:when test="$entity/adl:key/adl:property[position()=2]">
<xsl:message terminate="no"> <xsl:message terminate="no">
@ -729,4 +759,84 @@ namespace <xsl:value-of select="$controllerns"/> {
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:template> </xsl:template>
<xsl:template name="fetch-property-instance">
<!-- the property for which the instance is sought; it is assumed that
the property passed has type 'entity' -->
<xsl:param name="property"/>
<!-- the name of the value in the returned values from which the instance
must be resolved -->
<xsl:param name="valuename"/>
<xsl:if test="not( $property/@type='entity')">
<xsl:message terminate="yes">
ADL: ERROR: property passed to fetch-property-instance whose type is not 'entity'
</xsl:message>
</xsl:if>
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', $property/@entity)"/>))
<xsl:for-each select="//adl:entity[@name=$property/@entity]/adl:key/adl:property">
.Add(Expression.Eq("<xsl:value-of select="@name"/>",<xsl:choose>
<xsl:when test="@type='entity'"><xsl:call-template name="fetch-property-instance">
<!-- recurse -->
<xsl:with-param name="property" select="."/>
<xsl:with-param name="valuename" select="$valuename"/>
</xsl:call-template></xsl:when>
<xsl:when test="@type='integer'">Int32.Parse( Form["<xsl:value-of select="$valuename"/>"])</xsl:when>
<xsl:otherwise>Form["<xsl:value-of select="$valuename"/>"]</xsl:otherwise>
</xsl:choose>))
</xsl:for-each>
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', @entity)"/>&gt;()
</xsl:template>
<!-- this is essentially just a macro and doesn't really do anything clever.
It finds the current instance of the entity for which this is the controller,
and returns it as the value of a variable (which must have been previously
declared) called 'record' -->
<xsl:template name="fetch-instance">
<xsl:param name="entity"/>
<xsl:value-of select="concat($entityns, '.', $entity/@name)"/> record = null;
/* check whether values for all key slots have been passed in; if so, we're probably dealing with an
* existing record */
bool allkeys = true;
<xsl:for-each select="$entity/adl:key/adl:property">
if ( String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
allkeys = false;
}
else if ( "<xsl:value-of select="concat('$instance.', @name)"/>".Equals( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
/* nasty artefact of NVelocity forms - default 'null value' is dollar followed by fieldname */
allkeys = false;
}
</xsl:for-each>
if ( allkeys){
/* it's (probably) existing, retrieve it */
record = hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', $entity/@name)"/>))
<xsl:for-each select="$entity/adl:key/adl:property">
<xsl:variable name="basetype">
<xsl:call-template name="base-type">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:variable>
.Add( Expression.Eq( "<xsl:value-of select="@name"/>", <xsl:choose>
<xsl:when test="$basetype='integer'">Int32.Parse( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"])</xsl:when>
<xsl:when test="$basetype='entity'">
<!-- Maybe TODO: this doesn't work recursively - if an entity has a key which is an entity
and the key of that entity is an entity, you're on your own, mate! -->
<xsl:variable name="keyentity" select="@entity"/>
<xsl:variable name="keyenttype">
<xsl:call-template name="primary-key-csharp-type">
<xsl:with-param name="entity" select="//adl:entity[@name=$keyentity]"/>
</xsl:call-template>
</xsl:variable>
hibernator.CreateCriteria( typeof( <xsl:value-of select="$keyenttype"/>))
.Add(Expression.Eq( "<xsl:value-of select="//adl:entity[@name=$keyentity]/adl:key/adl:property[position()=1]/@name"/>",<xsl:choose>
<xsl:when test="$keyenttype = 'int'">Int32.Parse( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"])</xsl:when>
<xsl:otherwise>Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"]</xsl:otherwise></xsl:choose>))
.UniqueResult&lt;<xsl:value-of select="$keyenttype"/>&gt;()</xsl:when>
<xsl:otherwise>Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"]</xsl:otherwise></xsl:choose>))
</xsl:for-each>
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', $entity/@name)"/>&gt;();
}
</xsl:template>
</xsl:stylesheet> </xsl:stylesheet>

View file

@ -8,8 +8,8 @@
Transform ADL into entity classes Transform ADL into entity classes
$Author: sb $ $Author: sb $
$Revision: 1.10 $ $Revision: 1.11 $
$Date: 2008-03-05 11:05:12 $ $Date: 2008-03-10 17:01:26 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -61,7 +61,7 @@
stored to CVS --> stored to CVS -->
<xsl:variable name="transform-rev1" <xsl:variable name="transform-rev1"
select="substring( '$Revision: 1.10 $', 11)"/> select="substring( '$Revision: 1.11 $', 11)"/>
<xsl:variable name="transform-revision" <xsl:variable name="transform-revision"
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/> select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
@ -201,19 +201,6 @@
/// &lt;/summary&gt; /// &lt;/summary&gt;
public override string KeyString { public override string KeyString {
get { get {
<xsl:choose>
<xsl:when test="@natural-key">
<xsl:variable name="key" select="@natural-key"/>
<xsl:choose>
<xsl:when test="adl:property[@name=$key]/@type = 'entity'">
<xsl:value-of select="concat( 'return ', adl:property[@name=$key]/@entity, '.KeyString;')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat( 'return ', $key, '.ToString();')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="adl:key">
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>);
@ -222,11 +209,6 @@
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
return result.ToString(); return result.ToString();
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat( 'return ', @name, 'Id.ToString();')"/>
</xsl:otherwise>
</xsl:choose>
} }
} }

View file

@ -12,8 +12,8 @@
Transform ADL into velocity view templates Transform ADL into velocity view templates
$Author: sb $ $Author: sb $
$Revision: 1.9 $ $Revision: 1.10 $
$Date: 2008-03-05 11:05:12 $ $Date: 2008-03-10 17:01:26 $
--> -->
<!-- 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! -->
@ -44,7 +44,7 @@
stored to CVS --> stored to CVS -->
<xsl:variable name="transform-rev1" <xsl:variable name="transform-rev1"
select="substring( '$Revision: 1.9 $', 11)"/> select="substring( '$Revision: 1.10 $', 11)"/>
<xsl:variable name="transform-revision" <xsl:variable name="transform-revision"
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/> select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
@ -100,18 +100,33 @@
</head> </head>
<body> <body>
<xsl:call-template name="top"/> <xsl:call-template name="top"/>
<form action="delete.rails"> <form action="delete.rails" method="post">
<xsl:for-each select="adl:key/adl:property">
<xsl:choose> <xsl:choose>
<xsl:when test="@natural-key"> <xsl:when test="@type='entity'">
<!-- create a hidden widget for the natural primary key --> <xsl:variable name="entityname" select="@entity"/>
${FormHelper.HiddenField( "instance.<xsl:value-of select="@natural-key"/>")} <xsl:variable name="entitykeyname" select="//adl:entity[@name=$entityname]/adl:key/adl:property[position()=1]/@name"/>
<input type="hidden">
<xsl:attribute name="name">
<xsl:value-of select="concat( 'instance.', @name)"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="concat('$instance.', @name, '.', $entitykeyname)"/>
</xsl:attribute>
</input>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<!-- there isn't a natural primary key; create a hidden widget <input type="hidden">
for the abstract primary key --> <xsl:attribute name="name">
${FormHelper.HiddenField( "instance.<xsl:value-of select="$keyfield"/>")} <xsl:value-of select="concat( 'instance.', @name)"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="concat('$instance.', @name)"/>
</xsl:attribute>
</input>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:for-each>
<table> <table>
<tr align="left" valign="top" class="actionDangerous"> <tr align="left" valign="top" class="actionDangerous">
<td class="actionDangerous"> <td class="actionDangerous">
@ -290,33 +305,19 @@
<xsl:attribute name="id"> <xsl:attribute name="id">
<xsl:value-of select="$formname"/> <xsl:value-of select="$formname"/>
</xsl:attribute> </xsl:attribute>
<xsl:variable name="form" select="."/>
<xsl:for-each select="ancestor::adl:entity/adl:key/adl:property">
<xsl:variable name="keyname" select="@name"/>
<xsl:choose> <xsl:choose>
<xsl:when test="ancestor::adl:entity/@natural-key"> <xsl:when test="$form/adl:field[@property=$keyname]">
<xsl:variable name="keyfield" select="ancestor::adl:entity/@natural-key"/> <!-- it's already a field of the form - no need to add a hidden one -->
<xsl:choose>
<xsl:when test="@properties='all'">
<!-- no need to emit a hidden widget for the natural key, as there will be a
non-hidden one anyway -->
</xsl:when>
<xsl:when test="adl:field[@name=$keyfield]">
<!-- no need to emit a hidden widget for the natural key, as there will be a
non-hidden one anyway -->
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<!-- create a hidden widget for the natural primary key --> <!-- create a hidden widget for the natural primary key -->
${FormHelper.HiddenField( "instance.<xsl:value-of select="$keyfield"/>")} ${FormHelper.HiddenField( "instance.<xsl:value-of select="$keyname"/>")}
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- there isn't a natural primary key; create a hidden widget
for the abstract primary key -->
<xsl:variable name="keyfield">
<xsl:value-of select="ancestor::adl:entity/adl:key/adl:property[position()=1]/@name"/>
</xsl:variable>
${FormHelper.HiddenField( "instance.<xsl:value-of select="$keyfield"/>")}
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:for-each>
<xsl:if test="adl:fieldgroup"> <xsl:if test="adl:fieldgroup">
<div id="tabbar"> <div id="tabbar">
<xsl:for-each select="adl:fieldgroup"> <xsl:for-each select="adl:fieldgroup">
@ -653,8 +654,16 @@
</xsl:call-template>")} </xsl:call-template>")}
</td> </td>
<td class="widget" colspan="2"> <td class="widget" colspan="2">
#if( $instance)
<xsl:value-of select="concat( '$t.Msg( $instance.', @name, ')')"/> <xsl:value-of select="concat( '$t.Msg( $instance.', @name, ')')"/>
$FormHelper.HiddenField( "instance.<xsl:value-of select="@name"/>") $FormHelper.HiddenField( "instance.<xsl:value-of select="@name"/>")
#else
<input type="text">
<xsl:attribute name="name">
<xsl:value-of select="concat('i18n.instance.', @name)"/>
</xsl:attribute>
</input>
#end
</td> </td>
</tr> </tr>
</xsl:template> </xsl:template>
@ -997,7 +1006,17 @@
<xsl:otherwise>60</xsl:otherwise> <xsl:otherwise>60</xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
${FormHelper.TextField( "instance.<xsl:value-of select="@name"/>", "%{class='<xsl:value-of select="$class"/>', title='<xsl:value-of select="normalize-space( $if-missing)"/>', size='<xsl:value-of select="$size"/>', maxlength='<xsl:value-of select="@size"/>'}")} <xsl:variable name="maxlength">
<xsl:choose>
<xsl:when test="@size &gt;= 60">
<xsl:value-of select="@size"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$size"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
${FormHelper.TextField( "instance.<xsl:value-of select="@name"/>", "%{class='<xsl:value-of select="$class"/>', title='<xsl:value-of select="normalize-space( $if-missing)"/>', size='<xsl:value-of select="$size"/>', maxlength='<xsl:value-of select="$maxlength"/>'}")}
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</td> </td>