2
|
1 <?xml version="1.0" encoding="UTF-8"?>
|
|
2 <xsl:stylesheet version="1.0"
|
|
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://implab.org/schemas/data-model.v1.xsd"
|
|
4 xmlns:clr="http://implab.org/schemas/data-model/dotnet.v1.xsd"
|
|
5 xmlns:cs="http://implab.org/schemas/code-dom/csharp.v1.xsd" xmlns:sql="http://implab.org/schemas/data-model/sql.v1.xsd"
|
|
6 xmlns:t="http://implab.org/schemas/temp" xmlns:exsl="http://exslt.org/common"
|
|
7 exclude-result-prefixes="clr m xsl exsl sql">
|
|
8
|
|
9 <xsl:import href="preprocess.xsl" />
|
|
10 <xsl:include href="text-tools.xsl"/>
|
|
11
|
|
12 <xsl:output method="xml" indent="yes" />
|
|
13
|
|
14 <xsl:key name="type" match="m:package/m:*" use="@name" />
|
|
15
|
|
16 <xsl:template match="/">
|
|
17 <cs:document>
|
|
18 <xsl:apply-templates select="$module" mode="document" />
|
|
19 </cs:document>
|
|
20 </xsl:template>
|
|
21
|
|
22 <!-- code generation -->
|
|
23
|
|
24 <!-- disable default template -->
|
|
25 <xsl:template match="*|text()" mode="document" />
|
|
26
|
|
27 <xsl:template match="t:module" mode="document">
|
|
28 <xsl:apply-templates mode="document" />
|
|
29 </xsl:template>
|
|
30
|
3
|
31
|
2
|
32
|
|
33 <!-- member resolution traits -->
|
|
34
|
|
35 <!-- Resolves members using given criteria
|
|
36 @param type
|
|
37 the name of the type whose members are inspected
|
|
38 @param memberName
|
|
39 the name of the member to lookup
|
|
40 @param scope
|
|
41 the scope where to look (members, properties, keys, relations)
|
|
42
|
|
43 This template recursively inspects the given type down to it's inheritance
|
|
44 hierarchy and outputs members matching criteria.
|
|
45 -->
|
|
46 <xsl:template name="getMembers">
|
|
47 <xsl:param name="type"/>
|
|
48 <xsl:param name="memberName" select="''"/>
|
|
49 <xsl:param name="scope" select="'members'"/>
|
|
50 <!-- prevents cyclic references -->
|
|
51 <xsl:param name="seen" select="/.."/>
|
|
52 <xsl:for-each select="$module">
|
|
53 <xsl:apply-templates select="key('type', $type)"
|
|
54 mode="lookup-members">
|
|
55 <xsl:with-param name="memberName" select="$memberName"/>
|
|
56 <xsl:with-param name="scope" select="$scope"/>
|
|
57 <xsl:with-param name="seen" select="$seen"/>
|
|
58 </xsl:apply-templates>
|
|
59 </xsl:for-each>
|
|
60 </xsl:template>
|
|
61
|
|
62 <xsl:template match="*" mode="lookup-members"/>
|
|
63
|
|
64 <xsl:template match="m:entity" mode="lookup-members">
|
|
65 <xsl:param name="memberName" select="''"/>
|
|
66 <xsl:param name="scope" select="'members'"/>
|
|
67 <xsl:param name="seen"/>
|
|
68
|
|
69 <xsl:variable name="self" select="."/>
|
|
70
|
|
71 <xsl:if test="not($seen[generate-id() = generate-id($self)])">
|
|
72 <xsl:variable name="scopeMembers">
|
|
73 <xsl:call-template name="selectScopeMembers">
|
|
74 <xsl:with-param name="scope" select="$scope"/>
|
|
75 </xsl:call-template>
|
|
76 </xsl:variable>
|
|
77
|
|
78 <xsl:variable name="members" select="exsl:node-set($scopeMembers)/*[not($memberName) or @name='$memberName']"/>
|
|
79
|
|
80 <xsl:choose>
|
|
81 <xsl:when test="$members">
|
|
82 <xsl:copy-of select="$members"/>
|
|
83 </xsl:when>
|
|
84 <xsl:when test="m:extends">
|
|
85 <xsl:call-template name="getMembers">
|
|
86 <xsl:with-param name="type" select="m:extends/@type"/>
|
|
87 <xsl:with-param name="memberName" select="$memberName"/>
|
|
88 <xsl:with-param name="scope" select="$scope"/>
|
|
89 <xsl:with-param name="seen" select="$seen | $self"/>
|
|
90 </xsl:call-template>
|
|
91 </xsl:when>
|
|
92 <xsl:otherwise>
|
|
93 <xsl:call-template name="warn">
|
|
94 <xsl:with-param name="msg">
|
|
95 <t:trace msg="failed to resolve {$member}"/>
|
|
96 <t:trace msg="inspected classes">
|
|
97 <xsl:for-each select="$seen | $self">
|
|
98 <t:trace msg="{name()} {@name}"/>
|
|
99 </xsl:for-each>
|
|
100 </t:trace>
|
|
101 </xsl:with-param>
|
|
102 </xsl:call-template>
|
|
103 </xsl:otherwise>
|
|
104 </xsl:choose>
|
|
105 </xsl:if>
|
|
106 </xsl:template>
|
|
107
|
|
108 <!-- this template implements scope filtering -->
|
|
109 <xsl:template name="selectScopeMembers">
|
|
110 <xsl:param name="scope" select="'members'"/>
|
|
111 <xsl:choose>
|
|
112 <xsl:when test="$scope='members'">
|
|
113 <xsl:apply-templates mode="filter-members"/>
|
|
114 </xsl:when>
|
|
115 <xsl:when test="$scope='keys'">
|
|
116 <xsl:apply-template mode="filter-keys"/>
|
|
117 </xsl:when>
|
|
118 <xsl:when test="$scope='properties'">
|
|
119 <xsl:apply-templates mode="fiflter-properties"/>
|
|
120 </xsl:when>
|
|
121 <xsl:when test="$scope='relations'">
|
|
122 <xsl:apply-templates mode="fiflter-relations"/>
|
|
123 </xsl:when>
|
|
124 </xsl:choose>
|
|
125 </xsl:template>
|
|
126
|
|
127 <!-- filter-members -->
|
|
128 <xsl:template match="*|text()" mode="filter-members"/>
|
|
129 <xsl:template match="*[@name]" mode="filter-members">
|
|
130 <xsl:copy>
|
|
131 <xsl:copy-of select="@*" />
|
|
132 <xsl:attribute name="declaringType"><xsl:value-of select="../@name" /></xsl:attribute>
|
|
133 <xsl:copy-of select="*" />
|
|
134 </xsl:copy>
|
|
135 </xsl:template>
|
|
136
|
|
137 <!-- filter-keys -->
|
|
138 <xsl:template match="*|text()" mode="filter-keys"/>
|
|
139 <xsl:template match="m:primaryKey" mode="filter-keys">
|
|
140 <xsl:apply-templates select="." mode="filter-members"/>
|
|
141 </xsl:template>
|
|
142
|
|
143 <!-- filter-properties -->
|
|
144 <xsl:template match="*|text()" mode="filter-properties"/>
|
|
145 <xsl:template match="m:property" mode="filter-properties">
|
|
146 <xsl:apply-templates select="." mode="filter-members"/>
|
|
147 </xsl:template>
|
|
148
|
|
149 <!-- filter-relations -->
|
|
150 <xsl:template match="*|text()" mode="filter-relations"/>
|
|
151 <xsl:template match="m:hasA | m:hasMany" mode="filter-relations">
|
|
152 <xsl:apply-templates select="." mode="filter-members"/>
|
|
153 </xsl:template>
|
|
154
|
|
155
|
|
156
|
|
157 <!-- Resolves primaryKey information for the given type name.
|
|
158 @returns m:primaryKey node copy with additional attribute
|
|
159 @declaringType which points to the type where this primaryKey
|
|
160 was defined.
|
|
161 -->
|
|
162 <xsl:template name="getPrimaryKey">
|
|
163 <xsl:param name="type" />
|
|
164 <xsl:call-template name="getMembers">
|
|
165 <xsl:with-param name="type" select="$type"/>
|
|
166 <xsl:with-param name="scope" select="keys"/>
|
|
167 </xsl:call-template>
|
|
168 </xsl:template>
|
|
169
|
3
|
170 <xsl:template match="*|text()" mode="process-member"/>
|
2
|
171
|
3
|
172 <xsl:template match="m:hasA" mode="process-member">
|
|
173 <xsl:apply-templates mode="process-member"/>
|
2
|
174 </xsl:template>
|
|
175
|
3
|
176 <xsl:template match="m:hasA[@type]/m:thisKey" mode="process-member">
|
|
177 <xsl:variable name="foreignPrimaryKey">
|
|
178 <xsl:call-template name="getPrimaryKey">
|
|
179 <xsl:with-param name="type" select="../@type"/>
|
|
180 </xsl:call-template>
|
|
181 </xsl:variable>
|
|
182 <m:property type="{exsl:node-set($foreignPrimaryKey)[1]/@type}">
|
|
183 <xsl:copy-of select="@*"/>
|
|
184 </m:property>
|
2
|
185 </xsl:template>
|
|
186
|
3
|
187 <xsl:template match="m:primaryKey" mode="process-member">
|
|
188 <m:property>
|
|
189 <xsl:copy-of select="@*"/>
|
|
190 <xsl:copy-of select="*"/>
|
|
191 </m:property>
|
2
|
192 </xsl:template>
|
|
193
|
|
194
|
|
195 </xsl:stylesheet>
|