/[volute]/trunk/projects/theory/snapdm/res/deprecated20080331/xml2jpa.xsl
ViewVC logotype

Contents of /trunk/projects/theory/snapdm/res/deprecated20080331/xml2jpa.xsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations)
Mon Mar 31 19:41:40 2008 UTC (12 years, 7 months ago) by gerard.lemson
File MIME type: application/octet-stream
File size: 13219 byte(s)
Clean up after Laurent and I decided to concentrate on the pure XSLT way of generating code. This does require Saxon to be able to use the xsl:result-document syntax to output multiple files.
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:uml="http://schema.omg.org/spec/UML/2.0"
5 xmlns:xmi="http://schema.omg.org/spec/XMI/2.1">
6
7 <xsl:output method="text" encoding="UTF-8" indent="yes" />
8 <xsl:strip-space elements="*" />
9
10 <xsl:param name="lastModified"/>
11
12 <xsl:variable name="setMod">
13 <xsl:choose>
14 <xsl:when test="count(//bean/@setMod) = 1"><xsl:value-of select="bean/@setMod"/></xsl:when>
15 <xsl:otherwise>public</xsl:otherwise>
16 </xsl:choose>
17 </xsl:variable>
18
19 <xsl:variable name="extMod">
20 <xsl:choose>
21 <xsl:when test="count(//bean/extends) = 1">1</xsl:when>
22 <xsl:otherwise>0</xsl:otherwise>
23 </xsl:choose>
24 </xsl:variable>
25
26 <xsl:variable name="isList">
27 <xsl:choose>
28 <xsl:when test="count(//bean/field[@type = 'list']) > 0">1</xsl:when>
29 <xsl:otherwise>0</xsl:otherwise>
30 </xsl:choose>
31 </xsl:variable>
32
33
34
35 <xsl:template match="bean">
36 package model.experiment<!--<xsl:value-of select="@package"/>-->;
37
38 <!-- imports -->
39 <xsl:if test="$extMod = 0">
40 import java.io.Serializable;
41 </xsl:if>
42 <xsl:if test="$isList = 1">
43 import java.util.List;
44 import java.util.ArrayList;
45 </xsl:if>
46 <xsl:apply-templates select="field[@package != '']" mode="import" />
47
48 /**
49 * Class description :
50 *
51 <xsl:choose>
52 <xsl:when test="count(description) > 0">
53 <xsl:value-of select="description" disable-output-escaping="true"/>
54 </xsl:when>
55 <xsl:otherwise>TODO : Missing description : please, update your UML model asap.</xsl:otherwise>
56 </xsl:choose>
57 *
58 * @author generated by GenTool (UML->XMI->XSLT->java code)
59 */
60 public class <xsl:value-of select="@name"/><xsl:text> </xsl:text>
61 <xsl:choose>
62 <xsl:when test="$extMod = 1">extends <xsl:value-of select="extends/@class"/></xsl:when>
63 <xsl:otherwise>implements Serializable</xsl:otherwise>
64 </xsl:choose>
65 <xsl:text> {</xsl:text>
66
67 // GENERATED CODE - BEGIN ------------------------------------------------------
68
69 /** serial uid = last modification date of the UML model */
70 private static final long serialVersionUID = <xsl:value-of select="$lastModified"/>L;
71
72 // MEMBERS ---------------------------------------------------------------------
73
74 <xsl:apply-templates select="field" mode="declare" />
75
76 // CONSTRUCTOR -----------------------------------------------------------------
77
78 /**
79 * Public Constructor
80 */
81 public <xsl:value-of select="@name"/>() {
82 // nothing to do
83 }
84
85 // FIELDS ----------------------------------------------------------------------
86
87 <xsl:apply-templates select="field" mode="getset" />
88
89 // TO STRING -------------------------------------------------------------------
90
91 <xsl:if test="$extMod = 0">
92 public final String toString() {
93 // always gives an initial size to buffer (1 ko) :
94 return toString(new StringBuilder(1024)).toString();
95 }
96 </xsl:if>
97
98 public StringBuilder toString(final StringBuilder sb) {
99
100 sb.append("<xsl:value-of select="@name"/> =[");
101
102 sb.append(getClass().getName()).append("@").append(Integer.toHexString(System.identityHashCode(this)));
103
104 <xsl:if test="$extMod = 1">
105 sb.append(super.toString(sb));
106 </xsl:if>
107
108 sb.append("] : {");
109
110 <xsl:apply-templates select="field" mode="tostring" />
111
112 return sb.append(" }");
113 }
114
115 // GENERATED CODE - END --------------------------------------------------------
116
117
118 // END OF FILE -----------------------------------------------------------------
119
120 }
121 </xsl:template>
122
123
124
125 <xsl:template match="field" mode="JavaCase">
126 <xsl:variable name="val" select="@name"/>
127 <xsl:variable name="prem" select="substring($val,1,1)"/>
128 <xsl:variable name="first" select="translate($prem,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
129 <xsl:variable name="end" select="substring($val,2,string-length($val)-1)"/>
130 <xsl:value-of select="concat($first,$end)"/>
131 </xsl:template>
132
133
134
135 <xsl:template match="field" mode="import">
136 import <xsl:value-of select="@package"/>.<xsl:value-of select="@class"/>;
137 </xsl:template>
138
139
140
141 <xsl:template match="field" mode="declare">
142 <xsl:variable name="java"><xsl:apply-templates select="." mode="JavaCase" /></xsl:variable>
143 <xsl:choose>
144 <xsl:when test="@type = 'list'">
145 /** LIST <xsl:value-of select="@name"/> */
146 protected List <xsl:value-of select="@name"/> = null;
147 </xsl:when>
148 <xsl:when test="count(@class) = 1">
149 /** <xsl:value-of select="@class"/><xsl:value-of select="' '"/><xsl:value-of select="@name"/> */
150 protected <xsl:value-of select="@class"/><xsl:value-of select="' '"/><xsl:value-of select="@name"/> = null;
151 </xsl:when>
152 <xsl:when test="@type = 'boolean'">
153 /** BOOLEAN <xsl:value-of select="@name"/> */
154 protected Boolean <xsl:value-of select="@name"/> = null;
155 </xsl:when>
156 <xsl:when test="@type = 'p_boolean'">
157 /** boolean <xsl:value-of select="@name"/> */
158 protected boolean <xsl:value-of select="@name"/> = false;
159 </xsl:when>
160 <xsl:when test="@type = 'integer'">
161 /** INT <xsl:value-of select="@name"/> */
162 protected Integer <xsl:value-of select="@name"/> = null;
163 </xsl:when>
164 <xsl:when test="@type = 'p_integer'">
165 /** int <xsl:value-of select="@name"/> */
166 protected int <xsl:value-of select="@name"/> = 0;
167 </xsl:when>
168 <xsl:when test="@type = 'long'">
169 /** LONG <xsl:value-of select="@name"/> */
170 protected Long <xsl:value-of select="@name"/> = null;
171 </xsl:when>
172 <xsl:when test="@type = 'p_long'">
173 /** long <xsl:value-of select="@name"/> */
174 protected long <xsl:value-of select="@name"/> = 0l;
175 </xsl:when>
176 <xsl:when test="@type = 'date'">
177 /** date <xsl:value-of select="@name"/> */
178 protected long <xsl:value-of select="@name"/> = 0l;
179 </xsl:when>
180 <xsl:when test="@type = 'real'">
181 /** FLOAT <xsl:value-of select="@name"/> */
182 protected Float <xsl:value-of select="@name"/> = null;
183 </xsl:when>
184 <xsl:when test="@type = 'p_real'">
185 /** float <xsl:value-of select="@name"/> */
186 protected float <xsl:value-of select="@name"/> = 0d;
187 </xsl:when>
188 <xsl:when test="@type = 'double'">
189 /** DOUBLE <xsl:value-of select="@name"/> */
190 protected Double <xsl:value-of select="@name"/> = null;
191 </xsl:when>
192 <xsl:when test="@type = 'p_double'">
193 /** double <xsl:value-of select="@name"/> */
194 protected double <xsl:value-of select="@name"/> = 0d;
195 </xsl:when>
196 <xsl:otherwise>
197 /** TEXT <xsl:value-of select="@name"/> */
198 protected String <xsl:value-of select="@name"/> = null;
199 </xsl:otherwise>
200 </xsl:choose>
201 </xsl:template>
202
203
204
205 <xsl:template match="field" mode="tostring">
206 <xsl:variable name="java"><xsl:apply-templates select="." mode="JavaCase" /></xsl:variable>
207 sb.append("<xsl:value-of select="@name"/> = ");
208 <xsl:choose>
209 <xsl:when test="@type = 'int'">
210 if(this.<xsl:value-of select="@name"/> != null) {
211 sb.append(get<xsl:value-of select="$java"/>().intValue());
212 }
213 </xsl:when>
214 <xsl:when test="@type = 'long'">
215 if(this.<xsl:value-of select="@name"/> != null) {
216 sb.append(get<xsl:value-of select="$java"/>().longValue());
217 }
218 </xsl:when>
219 <xsl:when test="@type = 'double'">
220 if(this.<xsl:value-of select="@name"/> != null) {
221 sb.append(get<xsl:value-of select="$java"/>().doubleValue());
222 }
223 </xsl:when>
224 <xsl:when test="count(@type) = 0">
225 if (get<xsl:value-of select="$java"/>() != null) {
226 sb.append(get<xsl:value-of select="$java"/>());
227 }
228 </xsl:when>
229 <xsl:otherwise>
230 sb.append(get<xsl:value-of select="$java"/>());
231 </xsl:otherwise>
232 </xsl:choose>
233 <xsl:if test="position() != last()">sb.append(", ");</xsl:if>
234 </xsl:template>
235
236
237
238 <xsl:template match="field" mode="getset">
239 <xsl:variable name="java"><xsl:apply-templates select="." mode="JavaCase" /></xsl:variable>
240
241 <xsl:choose>
242 <xsl:when test="@type = 'list'">
243 public final List get<xsl:value-of select="$java"/>() {
244 if (this.<xsl:value-of select="@name"/> == null) {
245 this.<xsl:value-of select="@name"/> = new ArrayList();
246 }
247 return this.<xsl:value-of select="@name"/>;
248 }
249
250 </xsl:when>
251 <xsl:when test="count(@class) = 1">
252 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final <xsl:value-of select="@class"/> p<xsl:value-of select="$java"/>) {
253 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
254 }
255
256 <!-- final : TODO : manage overriden fields -->
257 public <xsl:value-of select="@class"/> get<xsl:value-of select="$java"/>() {
258 return this.<xsl:value-of select="@name"/>;
259 }
260
261 </xsl:when>
262 <xsl:when test="@type = 'boolean'">
263 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final Boolean p<xsl:value-of select="$java"/>) {
264 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
265 }
266
267 public final Boolean get<xsl:value-of select="$java"/>() {
268 return this.<xsl:value-of select="@name"/>;
269 }
270
271 </xsl:when>
272 <xsl:when test="@type = 'p_boolean'">
273 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final boolean p<xsl:value-of select="$java"/>) {
274 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
275 }
276
277 public final boolean get<xsl:value-of select="$java"/>() {
278 return this.<xsl:value-of select="@name"/>;
279 }
280
281 </xsl:when>
282 <xsl:when test="@type = 'integer'">
283 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final Integer p<xsl:value-of select="$java"/>) {
284 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
285 }
286
287 public final Integer get<xsl:value-of select="$java"/>() {
288 return this.<xsl:value-of select="@name"/>;
289 }
290
291 </xsl:when>
292 <xsl:when test="@type = 'p_integer'">
293 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final int p<xsl:value-of select="$java"/>) {
294 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
295 }
296
297 public final int get<xsl:value-of select="$java"/>() {
298 return this.<xsl:value-of select="@name"/>;
299 }
300
301 </xsl:when>
302 <xsl:when test="@type = 'long'">
303 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final Long p<xsl:value-of select="$java"/>) {
304 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
305 }
306
307 public final Long get<xsl:value-of select="$java"/>() {
308 return this.<xsl:value-of select="@name"/>;
309 }
310
311 </xsl:when>
312 <xsl:when test="@type = 'p_long'">
313 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final long p<xsl:value-of select="$java"/>) {
314 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
315 }
316
317 public final long get<xsl:value-of select="$java"/>() {
318 return this.<xsl:value-of select="@name"/>;
319 }
320
321 </xsl:when>
322 <xsl:when test="@type = 'date'">
323 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final long p<xsl:value-of select="$java"/>) {
324 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
325 }
326
327 public final long get<xsl:value-of select="$java"/>() {
328 return this.<xsl:value-of select="@name"/>;
329 }
330
331 </xsl:when>
332 <xsl:when test="@type = 'real'">
333 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final Float p<xsl:value-of select="$java"/>) {
334 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
335 }
336
337 public final Float get<xsl:value-of select="$java"/>() {
338 return this.<xsl:value-of select="@name"/>;
339 }
340
341 </xsl:when>
342 <xsl:when test="@type = 'p_real'">
343 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final float p<xsl:value-of select="$java"/>) {
344 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
345 }
346
347 public final float get<xsl:value-of select="$java"/>() {
348 return this.<xsl:value-of select="@name"/>;
349 }
350
351 </xsl:when>
352 <xsl:when test="@type = 'double'">
353 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final Double p<xsl:value-of select="$java"/>) {
354 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
355 }
356
357 public final Double get<xsl:value-of select="$java"/>() {
358 return this.<xsl:value-of select="@name"/>;
359 }
360
361 </xsl:when>
362 <xsl:when test="@type = 'p_double'">
363 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final double p<xsl:value-of select="$java"/>) {
364 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
365 }
366
367 public final double get<xsl:value-of select="$java"/>() {
368 return this.<xsl:value-of select="@name"/>;
369 }
370
371 </xsl:when>
372 <xsl:otherwise>
373 <xsl:value-of select="$setMod"/> final void set<xsl:value-of select="$java"/>(final String p<xsl:value-of select="$java"/>) {
374 this.<xsl:value-of select="@name"/> = p<xsl:value-of select="$java"/>;
375 }
376
377 public final String get<xsl:value-of select="$java"/>() {
378 return this.<xsl:value-of select="@name"/>;
379 }
380
381 </xsl:otherwise>
382 </xsl:choose>
383 </xsl:template>
384
385
386 </xsl:stylesheet>

Properties

Name Value
svn:executable *
svn:mime-type application/octet-stream

msdemlei@ari.uni-heidelberg.de
ViewVC Help
Powered by ViewVC 1.1.26