More impreovements based on experience with ASL
This commit is contained in:
parent
e423b325a4
commit
95e8e5ae30
|
@ -9,8 +9,8 @@
|
|||
Transform ADL into (partial) controller classes
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.12 $
|
||||
$Date: 2008-03-04 17:30:52 $
|
||||
$Revision: 1.13 $
|
||||
$Date: 2008-03-05 11:05:12 $
|
||||
-->
|
||||
|
||||
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
|
||||
|
@ -61,7 +61,7 @@
|
|||
with the revision number of the generated file if the generated file is
|
||||
stored to CVS -->
|
||||
<xsl:variable name="transform-rev1"
|
||||
select="substring( '$Revision: 1.12 $', 11)"/>
|
||||
select="substring( '$Revision: 1.13 $', 11)"/>
|
||||
<xsl:variable name="transform-revision"
|
||||
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
|
||||
|
||||
|
@ -172,11 +172,30 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
else
|
||||
{
|
||||
/* it's existing, retrieve it */
|
||||
<!-- TODO: this does not correctly handle entities with composite primary keys -->
|
||||
<!-- 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<<xsl:value-of select="$keytype"/>>();
|
||||
|
||||
record =
|
||||
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @name)"/>))
|
||||
.Add(Expression.Eq("<xsl:value-of select="$key"/>", id))
|
||||
.Add(Expression.Eq("<xsl:value-of select="$key"/>", eid))
|
||||
.UniqueResult<<xsl:value-of select="concat( $entityns, '.', @name)"/>>();
|
||||
</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<<xsl:value-of select="concat( $entityns, '.', @name)"/>>();
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
||||
}
|
||||
|
||||
if ( record != null)
|
||||
|
@ -317,7 +336,7 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
Session[ NHibernateHelper.USERTOKEN],
|
||||
Session[NHibernateHelper.PASSTOKEN]
|
||||
</xsl:if>);
|
||||
}
|
||||
}
|
||||
|
||||
<xsl:call-template name="menus">
|
||||
<xsl:with-param name="entity" select="."/>
|
||||
|
@ -673,16 +692,18 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
<xsl:param name="entity"/>
|
||||
<xsl:if test="not( $entity)">
|
||||
<xsl:message terminate="yes">
|
||||
No entity?
|
||||
ADL: ERROR: No entity passed to template primary-key-csharp-type
|
||||
</xsl:message>
|
||||
</xsl:if>
|
||||
<xsl:if test="not($entity/adl:key/adl:property)">
|
||||
<xsl:message terminate="yes">
|
||||
ADL: ERROR: entity '<xsl:value-of select="$entity/@name"/>' has no primary key.
|
||||
<xsl:message terminate="no">
|
||||
ADL: WARNING: entity '<xsl:value-of select="$entity/@name"/>' has no primary key.
|
||||
You will have to manually edit <xsl:value-of select="concat( $entity/@name, 'Controller.auto.cs')"/>
|
||||
</xsl:message>
|
||||
</xsl:if>
|
||||
<xsl:call-template name="csharp-type">
|
||||
<xsl:with-param name="property" select="$entity/adl:key/adl:property[ position() = 1]"/>
|
||||
<xsl:with-param name="entityns" select="$entityns"/>
|
||||
</xsl:call-template>
|
||||
</xsl:template>
|
||||
|
||||
|
@ -690,37 +711,21 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
<!-- return the name of the primary key of the entity with this name -->
|
||||
<xsl:param name="entity"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$entity/@natural-key">
|
||||
<xsl:value-of select="$entity/@natural-key"/>
|
||||
<xsl:when test="$entity/adl:key/adl:property[position()=2]">
|
||||
<xsl:message terminate="no">
|
||||
ADL: WARNING: Entity <xsl:value-of select="$entity/@name"/> has a composite primary key.
|
||||
You will need to manually edit <xsl:value-of select="concat( $entity/@name, 'Controller.auto.cs')"/>
|
||||
</xsl:message>
|
||||
<xsl:value-of select="$entity/adl:key/adl:property[position()=1]/@name"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$entity/key">
|
||||
<xsl:choose>
|
||||
<xsl:when test="count($entity/adl:key/adl:property) > 1">
|
||||
<xsl:message terminate="no">
|
||||
ADL: WARNING: entity '<xsl:value-of select="$entity/@name"/>' has a compound primary key;
|
||||
adl2controllerclasses is not yet clever enough to generate appropriate code.
|
||||
</xsl:message>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$entity/adl:key/adl:property[position()=1]"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:when test="$entity/adl:key/adl:property">
|
||||
<xsl:value-of select="$entity/adl:key/adl:property[position()=1]/@name"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$abstract-key-name-convention='Name'">
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$abstract-key-name-convention = 'NameId'">
|
||||
<xsl:value-of select="concat( $entity/@name, 'Id')"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$abstract-key-name-convention = 'Name_Id'">
|
||||
<xsl:value-of select="concat( $entity/@name, '_Id')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'Id'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:message terminate="no">
|
||||
ADL: WARNING: Entity <xsl:value-of select="$entity/@name"/> has no primary key.
|
||||
You will need to manually edit <xsl:value-of select="concat( $entity/@name, 'Controller.auto.cs')"/>
|
||||
</xsl:message>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
Transform ADL into entity classes
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.9 $
|
||||
$Date: 2008-03-03 17:35:28 $
|
||||
$Revision: 1.10 $
|
||||
$Date: 2008-03-05 11:05:12 $
|
||||
-->
|
||||
|
||||
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
|
||||
|
@ -61,7 +61,7 @@
|
|||
stored to CVS -->
|
||||
|
||||
<xsl:variable name="transform-rev1"
|
||||
select="substring( '$Revision: 1.9 $', 11)"/>
|
||||
select="substring( '$Revision: 1.10 $', 11)"/>
|
||||
<xsl:variable name="transform-revision"
|
||||
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
|
||||
|
||||
|
@ -301,7 +301,7 @@
|
|||
<xsl:when test="@cascade='all-delete-orphan'"/>
|
||||
<xsl:when test="@cascade='delete'"/>
|
||||
<xsl:otherwise>
|
||||
if ( <xsl:value-of select="concat( ' _', @name)"/>.Count > 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
Transform ADL into velocity view templates
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.8 $
|
||||
$Date: 2008-03-04 17:30:52 $
|
||||
$Revision: 1.9 $
|
||||
$Date: 2008-03-05 11:05:12 $
|
||||
-->
|
||||
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
|
||||
Whitespace (or lack of it) is significant! -->
|
||||
|
@ -44,7 +44,7 @@
|
|||
stored to CVS -->
|
||||
|
||||
<xsl:variable name="transform-rev1"
|
||||
select="substring( '$Revision: 1.8 $', 11)"/>
|
||||
select="substring( '$Revision: 1.9 $', 11)"/>
|
||||
<xsl:variable name="transform-revision"
|
||||
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
|
||||
|
||||
|
@ -654,6 +654,7 @@
|
|||
</td>
|
||||
<td class="widget" colspan="2">
|
||||
<xsl:value-of select="concat( '$t.Msg( $instance.', @name, ')')"/>
|
||||
$FormHelper.HiddenField( "instance.<xsl:value-of select="@name"/>")
|
||||
</td>
|
||||
</tr>
|
||||
</xsl:template>
|
||||
|
@ -1108,9 +1109,9 @@
|
|||
<span class="add">
|
||||
<a>
|
||||
<xsl:attribute name="href">
|
||||
<xsl:value-of select="concat( ../form[position() = 1]/@name, '.rails')"/>
|
||||
<xsl:value-of select="concat( ancestor::adl:entity/adl:form[position()=1]/@name, '.rails')"/>
|
||||
</xsl:attribute>
|
||||
Add a new <xsl:value-of select="../@name"/>
|
||||
Add a new <xsl:value-of select="ancestor::adl:entity/@name"/>
|
||||
</a>
|
||||
</span>
|
||||
</xsl:if>
|
||||
|
@ -1164,15 +1165,17 @@
|
|||
#end
|
||||
</xsl:when>
|
||||
<xsl:when test="ancestor::adl:entity//adl:property[@name=$prop]/@type='message'">
|
||||
#if ( $instance.<xsl:value-of select="$prop"/>)
|
||||
$t.Msg( $instance.<xsl:value-of select="$prop"/>)
|
||||
#end
|
||||
</xsl:when>
|
||||
<xsl:when test="ancestor::adl:entity//adl:property[@name=$prop]/@type='entity'">
|
||||
#if( $instance.<xsl:value-of select="$prop"/>)
|
||||
$instance.<xsl:value-of select="$prop"/>.UserIdentifier
|
||||
#end
|
||||
#if( $instance.<xsl:value-of select="$prop"/>)
|
||||
$instance.<xsl:value-of select="$prop"/>.UserIdentifier
|
||||
#end
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
$!instance.<xsl:value-of select="$prop"/>
|
||||
$!instance.<xsl:value-of select="$prop"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</td>
|
||||
|
@ -1239,19 +1242,29 @@
|
|||
#end
|
||||
<tr class="$oddity">
|
||||
<xsl:for-each select="ancestor::adl:entity//adl:property[@distinct='user']">
|
||||
<td>
|
||||
<xsl:choose>
|
||||
<xsl:when test="@type='entity'">
|
||||
#if( $instance.<xsl:value-of select="@name"/>)
|
||||
$instance.<xsl:value-of select="@name"/>.UserIdentifier
|
||||
#end
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
$!instance.<xsl:value-of select="@name"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</td>
|
||||
</xsl:for-each>
|
||||
<td>
|
||||
<xsl:choose>
|
||||
<xsl:when test="@type = 'date'">
|
||||
#if ( $instance.<xsl:value-of select="@name"/>)
|
||||
$instance.<xsl:value-of select="@name"/>.ToString( 'd')
|
||||
#end
|
||||
</xsl:when>
|
||||
<xsl:when test="@type='message'">
|
||||
#if ( $instance.<xsl:value-of select="@name"/>)
|
||||
$t.Msg( $instance.<xsl:value-of select="@name"/>)
|
||||
#end
|
||||
</xsl:when>
|
||||
<xsl:when test="@type='entity'">
|
||||
#if( $instance.<xsl:value-of select="@name"/>)
|
||||
$instance.<xsl:value-of select="@name"/>.UserIdentifier
|
||||
#end
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
$!instance.<xsl:value-of select="@name"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</td>
|
||||
</xsl:for-each>
|
||||
<xsl:variable name="keys">
|
||||
<!-- assemble keys in a Velocity-friendly format, then splice it into
|
||||
the HREF below -->
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
one place for ease of maintenance
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.4 $
|
||||
$Date: 2008-02-27 17:38:42 $
|
||||
$Revision: 1.5 $
|
||||
$Date: 2008-03-05 11:05:12 $
|
||||
-->
|
||||
|
||||
<xsl:stylesheet version="1.0"
|
||||
|
@ -27,6 +27,7 @@
|
|||
of the keyfield of that entity, and so on. -->
|
||||
<xsl:template name="csharp-base-type">
|
||||
<xsl:param name="property"/>
|
||||
<xsl:param name="entityns"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$property/@type = 'entity'">
|
||||
<xsl:variable name="entityname" select="$property/@entity"/>
|
||||
|
@ -36,6 +37,7 @@
|
|||
<xsl:call-template name="csharp-base-type">
|
||||
<xsl:with-param name="property"
|
||||
select="//adl:entity[@name=$entityname]/adl:key/adl:property[position()=1]"/>
|
||||
<xsl:with-param name="entityns" select="$entityns"/>
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
|
@ -48,6 +50,7 @@
|
|||
<xsl:otherwise>
|
||||
<xsl:call-template name="csharp-type">
|
||||
<xsl:with-param name="property" select="$property"/>
|
||||
<xsl:with-param name="entityns" select="$entityns"/>
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
@ -56,6 +59,7 @@
|
|||
<!-- return the C# type of the property which is passed as a parameter -->
|
||||
<xsl:template name="csharp-type">
|
||||
<xsl:param name="property"/>
|
||||
<xsl:param name="entityns"/>
|
||||
<xsl:variable name="base-type">
|
||||
<xsl:call-template name="base-type">
|
||||
<xsl:with-param name="property" select="$property"/>
|
||||
|
@ -79,7 +83,14 @@
|
|||
<xsl:when test="$base-type = 'real'">double</xsl:when>
|
||||
<xsl:when test="$base-type = 'money'">Decimal</xsl:when>
|
||||
<xsl:when test="$base-type = 'entity'">
|
||||
<xsl:value-of select="$property/@entity"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$entityns">
|
||||
<xsl:value-of select="concat( $entityns, '.', $property/@entity)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$property/@entity"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>[unknown?]</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
|
Loading…
Reference in a new issue