changeset 7:3fe157be5141

sync
author cin
date Tue, 06 Mar 2018 19:27:25 +0300
parents 1f4009d4afb6
children 5fe2e5724331
files xslt/generator.csharp.xsl xslt/model.xsl
diffstat 2 files changed, 82 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/xslt/generator.csharp.xsl	Mon Mar 05 10:37:47 2018 +0300
+++ b/xslt/generator.csharp.xsl	Tue Mar 06 19:27:25 2018 +0300
@@ -73,21 +73,11 @@
 
 	<xsl:template match="*|text()" mode="members" />
 
-	<xsl:template match="m:primaryKey | m:property | m:thisKey | clr:association" mode="members">
+	<xsl:template match="m:primaryKey | m:property" mode="members">
 		<t:trace msg="{name()} {@name}"/>
 		<xsl:apply-templates select="." mode="property"/>
 	</xsl:template>
 	
-	<!-- hasA and hasMany doesn't generate members itself, they delegate this work to inner members -->
-	<xsl:template match="m:hasA | m:hasMany" mode="members">
-		<t:trace msg="{name()} {@name}" />
-		<xsl:apply-templates mode="members" />
-	</xsl:template>
-	
-	<xsl:template match="m:hasA/clr:lazy" mode="members">
-		<xsl:apply-templates select="." mode="field"/>
-	</xsl:template>
-
 	<!-- member-name -->
 	<xsl:template match="*|text()|@*" mode="member-name" />
 
--- a/xslt/model.xsl	Mon Mar 05 10:37:47 2018 +0300
+++ b/xslt/model.xsl	Tue Mar 06 19:27:25 2018 +0300
@@ -167,4 +167,85 @@
 		</xsl:call-template>
 	</xsl:template>
 	
+	<!-- expand-member templates are used to process relations
+	and keys and provide usefull information like properties of
+	the entity which are members of this relation or key.
+	
+	@special - means that the member is a composite part and isn't
+	accessible directly
+	-->
+	
+	<!-- short form of primaryKey{@name, @type} -->
+	<xsl:template match="m:primaryKey" mode="expand-member">
+		<xsl:copy>
+			<xsl:copy-of select="@*"/>
+			<m:property special="true">
+				<xsl:copy-of select="@*" />
+				<xsl:copy-of select="*" />
+			</m:property>
+		</xsl:copy>
+	</xsl:template>
+	
+	<!-- long form of primaryKey{ member{@name}+, property{@name, @type} }  -->
+	<xsl:template match="m:primaryKey[m:member | m:property]" mode="expand-member">
+		<xsl:copy>
+			<xsl:copy-of select="@*"/>
+			<xsl:apply-templates mode="expand-member"/>
+		</xsl:copy>
+	</xsl:template>
+	
+	<!-- stand alone properties -->
+	<xsl:template match="m:property" mode="expand-member">
+		<xsl:copy-of select="."/>
+	</xsl:template>
+	
+	<!-- properties declared inside relations, they are @special -->
+	<xsl:template match="m:primaryKey/m:property | m:thisKey/m:property" mode="expand-member">
+		<xsl:copy>
+			<xsl:attribute name="special">true</xsl:attribute>
+			<xsl:copy-of select="@*"/>
+			<xsl:copy-of select="*"/>
+		</xsl:copy>
+	</xsl:template>
+	
+	<xsl:template match="m:member" mode="expand-member">
+		<xsl:param name="declaringType"/>
+		<xsl:variable name="expanded">
+			<xsl:call-template name="getMembers">
+				<xsl:with-param name="memberName" select="@name"/>
+				<xsl:with-param name="type" select="$declaringType"/>
+			</xsl:call-template>
+		</xsl:variable>
+		<!-- recusive expand -->
+		<xsl:apply-templates select="exsl:node-set($expanded)" mode="expand-member"/>
+	</xsl:template>
+	
+	<xsl:template match="m:hasA" mode="expand-member">
+		<xsl:copy>
+			<xsl:copy-of select="@*"/>
+			
+			<xsl:apply-templates mode="expand-member"/>
+		</xsl:copy>
+	</xsl:template>
+	
+	<xsl:template match="m:thisKey" mode="expand-member">
+		<xsl:variable name="otherKey">
+			<xsl:call-template name="getPrimaryKey">
+				<xsl:with-param name="type" select="../@type"/>
+			</xsl:call-template>
+		</xsl:variable>
+		<xsl:variable name="otherKeyExpanded">
+			<xsl:apply-templates select="exsl:node-set($otherKey)" mode="expand-member"/>
+		</xsl:variable>
+		<xsl:variable name="pk" select="exsl:node-set($otherKeyExpanded)[1]"/>
+		
+		<m:property name="{@name}" type="{$pk/@type}" hidden="true">
+			<m:related name="{$pk/@name}" type="{../@type}"/>
+		</m:property>
+	</xsl:template>
+	
+	<xsl:template match="m:thisKey[m:member | property]">
+		<xsl:apply-templates mode="expand-member"/>
+	</xsl:template>
+	
 </xsl:stylesheet>