Mercurial > pub > ModelGenerator
comparison xslt/generator.csharp.xsl @ 3:437127ab6a12
non-working version
separate common model templates from csharp templates, plans to support complex
primary and foreign keys
author | cin |
---|---|
date | Wed, 28 Feb 2018 02:10:29 +0300 |
parents | 035de8b7b18e |
children | d240adc2ac70 |
comparison
equal
deleted
inserted
replaced
2:035de8b7b18e | 3:437127ab6a12 |
---|---|
7 exclude-result-prefixes="clr m xsl exsl sql"> | 7 exclude-result-prefixes="clr m xsl exsl sql"> |
8 <xsl:import href="model.xsl"/> | 8 <xsl:import href="model.xsl"/> |
9 | 9 |
10 <xsl:output method="xml" indent="yes" /> | 10 <xsl:output method="xml" indent="yes" /> |
11 | 11 |
12 <!-- generate code for primary package --> | |
13 <xsl:template match="m:package[@primary='true' and @clr:namespace]" mode="document"> | |
14 <cs:namespace name="{@clr:namespace}"> | |
15 <xsl:apply-templates mode="document" /> | |
16 </cs:namespace> | |
17 </xsl:template> | |
18 | |
19 <xsl:template match="m:package[@primary='true']" mode="document"> | |
20 <xsl:apply-templates mode="document" /> | |
21 </xsl:template> | |
22 | |
12 <!-- entity --> | 23 <!-- entity --> |
13 <xsl:template match="m:entity" mode="document"> | 24 <xsl:template match="m:entity" mode="document"> |
14 <xsl:apply-templates select="." mode="entity"/> | 25 <xsl:apply-templates select="." mode="entity"/> |
15 </xsl:template> | 26 </xsl:template> |
16 | 27 |
17 <xsl:template match="m:entity" mode="entity"> | 28 <xsl:template match="m:entity" mode="entity"> |
18 <cs:class name="{@name}" modifiers="partial"> | 29 <cs:class modifiers="partial"> |
19 <xsl:attribute name="name"> | 30 <xsl:attribute name="name"> |
20 <xsl:apply-templates select="." mode="class-name"/> | 31 <xsl:apply-templates select="." mode="class-name"/> |
21 </xsl:attribute> | 32 </xsl:attribute> |
22 <xsl:apply-templates mode="class-attributes" /> | 33 <xsl:apply-templates mode="class-attributes" /> |
23 <xsl:apply-templates mode="members" /> | 34 <xsl:apply-templates mode="members" /> |
111 <!-- property --> | 122 <!-- property --> |
112 | 123 |
113 <xsl:template match="*" mode="property"> | 124 <xsl:template match="*" mode="property"> |
114 <cs:property modifiers="public"> | 125 <cs:property modifiers="public"> |
115 <xsl:attribute name="name"><xsl:apply-templates select="." mode="property-name"/></xsl:attribute> | 126 <xsl:attribute name="name"><xsl:apply-templates select="." mode="property-name"/></xsl:attribute> |
127 <xsl:attribute name="modifiers"><xsl:apply-templates select="." mode="property-modifiers"/></xsl:attribute> | |
116 <xsl:apply-templates select="." mode="property-type"/> | 128 <xsl:apply-templates select="." mode="property-type"/> |
117 <xsl:apply-templates select="." mode="property-attributes"/> | 129 <xsl:apply-templates select="." mode="property-attributes"/> |
118 <xsl:apply-templates select="." mode="property-extension" /> | 130 <xsl:apply-templates select="." mode="property-extension" /> |
119 <xsl:apply-templates select="." mode="property-accessors"/> | 131 <xsl:apply-templates select="." mode="property-accessors"/> |
120 </cs:property> | 132 </cs:property> |
132 | 144 |
133 <xsl:template match="*" mode="property-name"> | 145 <xsl:template match="*" mode="property-name"> |
134 <xsl:apply-templates select="." mode="member-name"/> | 146 <xsl:apply-templates select="." mode="member-name"/> |
135 </xsl:template> | 147 </xsl:template> |
136 | 148 |
149 <!-- property-modifiers --> | |
150 <xsl:template match="*" mode="property-modifiers"> | |
151 <xsl:text>public</xsl:text> | |
152 </xsl:template> | |
153 | |
137 <!-- property-type --> | 154 <!-- property-type --> |
138 <xsl:template match="m:hasA[@type]/clr:association[not(clr:type)]" mode="property-type"> | 155 <xsl:template match="m:hasA[@type]/clr:association[not(clr:type)]" mode="property-type"> |
139 <xsl:apply-templates select=".." mode="property-type"/> | 156 <xsl:apply-templates select=".." mode="property-type"/> |
140 </xsl:template> | 157 </xsl:template> |
141 | 158 |
144 <xsl:apply-templates select=".." mode="property-type"/> | 161 <xsl:apply-templates select=".." mode="property-type"/> |
145 </cs:array> | 162 </cs:array> |
146 </xsl:template> | 163 </xsl:template> |
147 | 164 |
148 <xsl:template match="m:hasA[@type]/m:thisKey" mode="property-type"> | 165 <xsl:template match="m:hasA[@type]/m:thisKey" mode="property-type"> |
149 <xsl:call-template name="getKeyType"> | 166 <xsl:call-template name="getPrimaryKey"> |
150 <xsl:with-param name="type" select="../@type"/> | 167 <xsl:with-param name="type" select="../@type"/> |
151 </xsl:call-template> | 168 </xsl:call-template> |
152 </xsl:template> | 169 </xsl:template> |
153 | 170 |
154 <xsl:template match="m:hasA[@type and boolean(@optional)]/m:thisKey" mode="property-type"> | 171 <xsl:template match="m:hasA[@type and boolean(@optional)]/m:thisKey" mode="property-type"> |
155 <cs:nullable> | 172 <cs:nullable> |
156 <xsl:call-template name="getKeyType"> | 173 <xsl:call-template name="getPrimaryKey"> |
157 <xsl:with-param name="type" select="../@type"/> | 174 <xsl:with-param name="type" select="../@type"/> |
158 </xsl:call-template> | 175 </xsl:call-template> |
159 </cs:nullable> | 176 </cs:nullable> |
160 </xsl:template> | 177 </xsl:template> |
161 | 178 |
373 <xsl:with-param name="seen" select="$seen"/> | 390 <xsl:with-param name="seen" select="$seen"/> |
374 </xsl:apply-templates> | 391 </xsl:apply-templates> |
375 </xsl:for-each> | 392 </xsl:for-each> |
376 </xsl:template> | 393 </xsl:template> |
377 | 394 |
395 <!-- resolves CLR type for the given type --> | |
396 <xsl:template name="getClrType"> | |
397 <xsl:param name="type" /> | |
398 <xsl:param name="typeArgs" select="/.." /> | |
399 <!-- <t:trace msg="resolveClrType {$type}"/> --> | |
400 <xsl:for-each select="$module"> | |
401 <xsl:apply-templates select="key('type', $type)" | |
402 mode="clr-type"> | |
403 <xsl:with-param name="typeArgs" select="$typeArgs"/> | |
404 </xsl:apply-templates> | |
405 </xsl:for-each> | |
406 </xsl:template> | |
407 | |
408 <!-- CLR type construction --> | |
409 <xsl:template match="*" mode="clr-type" /> | |
410 | |
411 <xsl:template match="m:type[clr:type]" mode="clr-type"> | |
412 <xsl:param name="typeArgs" select="clr:type/*" /> | |
413 <xsl:apply-templates select="clr:type" mode="clr-type"> | |
414 <xsl:with-param name="typeArgs" select="$typeArgs" /> | |
415 </xsl:apply-templates> | |
416 </xsl:template> | |
417 | |
418 <xsl:template match="m:entity" mode="clr-type"> | |
419 <cs:type name="{@clr:name | @name[not(../@clr:name)]}" namespace="{ancestor::*[@clr:namespace]/@clr:namespace}" /> | |
420 </xsl:template> | |
421 | |
422 <xsl:template match="clr:type" mode="clr-type"> | |
423 <xsl:apply-templates mode="clr-type"/> | |
424 </xsl:template> | |
425 | |
426 <xsl:template match="clr:type[@ref]" mode="clr-type"> | |
427 <xsl:param name="typeArgs" select="*" /> | |
428 <xsl:call-template name="getClrType"> | |
429 <xsl:with-param name="type" select="@ref" /> | |
430 <xsl:with-param name="typeArgs" select="$typeArgs" /> | |
431 </xsl:call-template> | |
432 </xsl:template> | |
433 | |
434 <xsl:template match="clr:type[@cs:name or @name]" mode="clr-type"> | |
435 <xsl:param name="typeArgs" select="*" /> | |
436 <xsl:variable name="ns" | |
437 select="@cs:namespace | @namespace[not(../@cs:namespace)]" /> | |
438 <cs:type name="{@cs:name | @name[not(../@cs:name)]}"> | |
439 <xsl:if test="$ns"> | |
440 <xsl:attribute name="namespace"><xsl:value-of select="$ns" /></xsl:attribute> | |
441 </xsl:if> | |
442 <xsl:copy-of select="@struct"/> | |
443 | |
444 <xsl:apply-templates select="$typeArgs | *[not($typeArgs)]" | |
445 mode="clr-type" /> | |
446 </cs:type> | |
447 </xsl:template> | |
448 | |
449 <xsl:template match="clr:arrayOf[@type]" mode="clr-type"> | |
450 <xsl:param name="typeArgs" select="*" /> | |
451 <cs:array> | |
452 <xsl:call-template name="getClrType"> | |
453 <xsl:with-param name="type" select="@type" /> | |
454 <xsl:with-param name="typeArgs" select="$typeArgs" /> | |
455 </xsl:call-template> | |
456 </cs:array> | |
457 </xsl:template> | |
458 | |
459 <xsl:template match="clr:arrayOf[@cs:name or @name]" mode="clr-type"> | |
460 <xsl:param name="typeArgs" select="*" /> | |
461 <xsl:variable name="ns" | |
462 select="@cs:namespace | @namespace[not(../@cs:namespace)]" /> | |
463 <cs:array> | |
464 <cs:type name="{@cs:name | @name[not(../@cs:name)]}"> | |
465 <xsl:if test="$ns"> | |
466 <xsl:attribute name="namespace"><xsl:value-of | |
467 select="$ns" /></xsl:attribute> | |
468 </xsl:if> | |
469 <xsl:apply-templates select="$typeArgs | *[not($typeArgs)]" | |
470 mode="clr-type" /> | |
471 </cs:type> | |
472 </cs:array> | |
473 </xsl:template> | |
474 | |
378 | 475 |
379 </xsl:stylesheet> | 476 </xsl:stylesheet> |