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

Contents of /trunk/projects/theory/snapdm/res/xml2jpa_schema.xsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 124 - (show annotations)
Mon Mar 31 17:00:27 2008 UTC (12 years, 7 months ago) by gerard.lemson
File MIME type: application/xml
File size: 17752 byte(s)


1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE stylesheet [
4 <!ENTITY cr "<xsl:text>
5 </xsl:text>">
6 <!ENTITY bl "<xsl:text> </xsl:text>">
7 ]>
8
9 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
10
11 <xsl:output method="text" encoding="UTF-8" indent="yes" />
12
13 <!-- next could be parameters -->
14 <xsl:variable name="lastModified"
15 select="format-dateTime(current-dateTime(),'[Y0001][M01][D01][H01][m01][s01]')"/>
16 <xsl:param name="root_package"/> <!-- select="'org.ivoa.'" -->
17 <xsl:param name="model_package"/>
18
19 <xsl:variable name="root_package_dir" select="replace($root_package,'[.]','/')"/>
20
21 <xsl:template match="/">
22 <xsl:message>Root package = <xsl:value-of select="$root_package"/></xsl:message>
23 <xsl:message>Root package dir= <xsl:value-of select="$root_package_dir"/></xsl:message>
24 <xsl:message>Model package = <xsl:value-of select="$model_package"/></xsl:message>
25 <xsl:apply-templates select="model"/>
26 </xsl:template>
27
28
29
30
31 <xsl:template match="model">
32 <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
33 <xsl:for-each select="package">
34 <xsl:call-template name="package">
35 <xsl:with-param name="dir" select="$root_package_dir"/>
36 <xsl:with-param name="path" select="$root_package"/>
37 </xsl:call-template>
38 </xsl:for-each>
39 </xsl:template>
40
41
42
43
44 <xsl:template name="package">
45 <xsl:param name="dir"/>
46 <xsl:param name="path"/>
47
48 <xsl:variable name="newdir">
49 <xsl:choose>
50 <xsl:when test="$dir">
51 <xsl:value-of select="concat($dir,'/',name)"/>
52 </xsl:when>
53 <xsl:otherwise>
54 <xsl:value-of select="name"/>
55 </xsl:otherwise>
56 </xsl:choose>
57 </xsl:variable>
58
59 <xsl:variable name="newpath">
60 <xsl:choose>
61 <xsl:when test="$path">
62 <xsl:value-of select="concat($path,'.',name)"/>
63 </xsl:when>
64 <xsl:otherwise>
65 <xsl:value-of select="name"/>
66 </xsl:otherwise>
67 </xsl:choose>
68 </xsl:variable>
69
70 <xsl:message>package = <xsl:value-of select="$newpath"></xsl:value-of></xsl:message>
71
72 <xsl:for-each select="objectType">
73 <xsl:call-template name="objectType">
74 <xsl:with-param name="dir" select="$newdir"/>
75 <xsl:with-param name="path" select="$newpath"/>
76 </xsl:call-template>
77 </xsl:for-each>
78
79 <xsl:for-each select="dataType">
80 <xsl:call-template name="dataType">
81 <xsl:with-param name="dir" select="$newdir"/>
82 <xsl:with-param name="path" select="$newpath"/>
83 </xsl:call-template>
84 </xsl:for-each>
85
86 <xsl:for-each select="enumeration">
87 <xsl:call-template name="enumeration">
88 <xsl:with-param name="dir" select="$newdir"/>
89 <xsl:with-param name="path" select="$newpath"/>
90 </xsl:call-template>
91 </xsl:for-each>
92
93 <xsl:for-each select="package">
94 <xsl:call-template name="package">
95 <xsl:with-param name="dir" select="$newdir"/>
96 <xsl:with-param name="path" select="$newpath"/>
97 </xsl:call-template>
98 </xsl:for-each>
99 </xsl:template>
100
101
102
103
104 <xsl:template name="objectType">
105 <xsl:param name="dir"/>
106 <xsl:param name="path"/>
107
108 <xsl:variable name="setMod">
109 <xsl:choose>
110 <xsl:when test="count(@setMod) = 1"><xsl:value-of select="@setMod"/></xsl:when>
111 <xsl:otherwise>public</xsl:otherwise>
112 </xsl:choose>
113 </xsl:variable>
114
115 <xsl:variable name="extMod">
116 <xsl:choose>
117 <xsl:when test="count(extends) = 1">1</xsl:when>
118 <xsl:otherwise>0</xsl:otherwise>
119 </xsl:choose>
120 </xsl:variable>
121
122 <xsl:variable name="isList">
123 <xsl:choose>
124 <xsl:when test="count(collection) > 0">1</xsl:when>
125 <xsl:otherwise>0</xsl:otherwise>
126 </xsl:choose>
127 </xsl:variable>
128
129 <xsl:variable name="file" select="concat($dir,'/',name,'.java')"/>
130 <!-- open file for this class -->
131 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
132 <xsl:result-document href="{$file}">
133 package <xsl:value-of select="$path"/>;
134
135 <!-- imports -->
136 <xsl:if test="$extMod = 0">
137 import <xsl:value-of select="$model_package"/>.*;
138 </xsl:if>
139 <xsl:if test="$isList = 1">
140 import java.util.List;
141 import java.util.ArrayList;
142 </xsl:if>
143
144 /**
145 * Class description :
146 *
147 <xsl:choose>
148 <xsl:when test="count(description) > 0">
149 <xsl:value-of select="description" disable-output-escaping="yes"/>
150 </xsl:when>
151 <xsl:otherwise>TODO : Missing description : please, update your UML model asap.</xsl:otherwise>
152 </xsl:choose>
153 *
154 * @author generated by GenTool (UML->XMI->XSLT->java code)
155 */
156 public class <xsl:value-of select="name"/><xsl:text> </xsl:text>
157 <xsl:choose>
158 <xsl:when test="$extMod = 1">extends <xsl:apply-templates select="extends/datatype" mode="JavaType"/></xsl:when>
159 <xsl:otherwise>extends MetadataObject</xsl:otherwise>
160 </xsl:choose>
161 <xsl:text> {</xsl:text>
162
163 // GENERATED CODE - BEGIN ------------------------------------------------------
164
165 /** serial uid = last modification date of the UML model */
166 private static final long serialVersionUID = <xsl:value-of select="$lastModified"/>L;
167
168 // MEMBERS ---------------------------------------------------------------------
169
170 <xsl:apply-templates select="attribute" mode="declare" />
171 <xsl:apply-templates select="collection" mode="declare" />
172 <xsl:apply-templates select="reference" mode="declare" />
173
174 // CONSTRUCTOR -----------------------------------------------------------------
175
176 /**
177 * Public Constructor
178 */
179 public <xsl:value-of select="name"/>() {
180 // nothing to do
181 }
182
183 // FIELDS ----------------------------------------------------------------------
184
185 <xsl:apply-templates select="attribute" mode="getset" />
186 <xsl:apply-templates select="collection" mode="getset" />
187 <xsl:apply-templates select="reference" mode="getset" />
188
189 // TO STRING -------------------------------------------------------------------
190
191 <xsl:if test="$extMod = 0">
192 public final String toString() {
193 // always gives an initial size to buffer (1 ko) :
194 return toString(new StringBuilder(1024)).toString();
195 }
196 </xsl:if>
197
198 public StringBuilder toString(final StringBuilder sb) {
199
200 sb.append("<xsl:value-of select="name"/> =[");
201
202 sb.append(getClass().getName()).append("@").append(Integer.toHexString(System.identityHashCode(this)));
203
204 <xsl:if test="$extMod = 1">
205 sb.append(super.toString(sb));
206 </xsl:if>
207
208 sb.append("] : {");
209 <!--
210 <xsl:apply-templates select="attribute" mode="tostring" />
211 <xsl:apply-templates select="collection" mode="tostring" />
212 <xsl:apply-templates select="reference" mode="tostring" />
213 -->
214 return sb.append(" }");
215 }
216
217 // GENERATED CODE - END --------------------------------------------------------
218
219
220 // END OF FILE -----------------------------------------------------------------
221
222 }
223 </xsl:result-document>
224 </xsl:template>
225
226
227
228
229 <xsl:template match="extends">
230 <xsl:choose>
231 <xsl:when test="@base">
232 </xsl:when>
233 </xsl:choose>
234 </xsl:template>
235
236 <xsl:template name="dataType">
237 <xsl:param name="dir"/>
238 <xsl:param name="path"/>
239
240 <xsl:variable name="setMod">
241 <xsl:choose>
242 <xsl:when test="count(@setMod) = 1"><xsl:value-of select="@setMod"/></xsl:when>
243 <xsl:otherwise>public</xsl:otherwise>
244 </xsl:choose>
245 </xsl:variable>
246
247 <xsl:variable name="extMod">
248 <xsl:choose>
249 <xsl:when test="count(extends) = 1">1</xsl:when>
250 <xsl:otherwise>0</xsl:otherwise>
251 </xsl:choose>
252 </xsl:variable>
253
254 <xsl:variable name="file" select="concat($dir,'/',name,'.java')"/>
255 <!-- open file for this class -->
256 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
257 <xsl:result-document href="{$file}">
258 package <xsl:value-of select="$path"/>;
259
260 <!-- imports -->
261 <xsl:if test="$extMod = 0">
262 import <xsl:value-of select="$model_package"/>.*;
263 </xsl:if>
264
265 /**
266 * DataType description :
267 *
268 <xsl:choose>
269 <xsl:when test="count(description) > 0">
270 <xsl:value-of select="description" disable-output-escaping="yes"/>
271 </xsl:when>
272 <xsl:otherwise>TODO : Missing description : please, update your UML model asap.</xsl:otherwise>
273 </xsl:choose>
274 *
275 * @author generated by GenTool (UML->XMI->XSLT->java code)
276 */
277 public class <xsl:value-of select="name"/><xsl:text> </xsl:text>
278 <xsl:choose>
279 <xsl:when test="$extMod = 1">extends <xsl:apply-templates select="extends/datatype" mode="JavaType"/></xsl:when>
280 <xsl:otherwise>extends MetadataDataType</xsl:otherwise>
281 </xsl:choose>
282 <xsl:text> {</xsl:text>
283
284 // GENERATED CODE - BEGIN ------------------------------------------------------
285
286 /** serial uid = last modification date of the UML model */
287 private static final long serialVersionUID = <xsl:value-of select="$lastModified"/>L;
288
289 // MEMBERS ---------------------------------------------------------------------
290
291 <xsl:apply-templates select="attribute" mode="declare" />
292
293 // CONSTRUCTOR -----------------------------------------------------------------
294
295 /**
296 * Public Constructor
297 */
298 public <xsl:value-of select="name"/>() {
299 // nothing to do
300 }
301
302 // FIELDS ----------------------------------------------------------------------
303
304 <xsl:apply-templates select="attribute" mode="getset" />
305
306 // TO STRING -------------------------------------------------------------------
307
308 <xsl:if test="$extMod = 0">
309 public final String toString() {
310 // always gives an initial size to buffer (1 ko) :
311 return toString(new StringBuilder(1024)).toString();
312 }
313 </xsl:if>
314
315 public StringBuilder toString(final StringBuilder sb) {
316
317 sb.append("<xsl:value-of select="name"/> =[");
318
319 sb.append(getClass().getName()).append("@").append(Integer.toHexString(System.identityHashCode(this)));
320
321 <xsl:if test="$extMod = 1">
322 sb.append(super.toString(sb));
323 </xsl:if>
324
325 sb.append("] : {");
326 <!--
327 <xsl:apply-templates select="attribute" mode="tostring" />
328 -->
329 return sb.append(" }");
330 }
331
332 // GENERATED CODE - END --------------------------------------------------------
333
334
335 // END OF FILE -----------------------------------------------------------------
336
337 }
338 </xsl:result-document>
339 </xsl:template>
340
341 <xsl:template name="enumeration">
342 <xsl:param name="dir"/>
343 <xsl:param name="path"/>
344
345 <xsl:variable name="file" select="concat($dir,'/',name,'.java')"/>
346 <!-- open file for this class -->
347 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
348 <xsl:result-document href="{$file}">
349 package <xsl:value-of select="$path"/>;
350
351 /**
352 * Enum description :
353 *
354 <xsl:choose>
355 <xsl:when test="count(description) > 0">
356 <xsl:value-of select="description" disable-output-escaping="yes"/>
357 </xsl:when>
358 <xsl:otherwise>TODO : Missing description : please, update your UML model asap.</xsl:otherwise>
359 </xsl:choose>
360 *
361 * @author generated by GenTool (UML->XMI->XSLT->java code)
362 */
363 public enum <xsl:value-of select="name"/>
364 &bl;{
365
366 // GENERATED CODE - BEGIN ------------------------------------------------------
367
368 <xsl:apply-templates select="enumliterals" />
369
370 // GENERATED CODE - END --------------------------------------------------------
371
372 // END OF FILE -----------------------------------------------------------------
373
374 }
375 </xsl:result-document>
376 </xsl:template>
377
378
379
380 <xsl:template match="datatype" mode="JavaType">
381 <xsl:choose>
382 <xsl:when test="@type">
383 <xsl:choose>
384 <xsl:when test="@type = 'boolean'">Boolean</xsl:when>
385 <xsl:when test="@type = 'p_boolean'">boolean</xsl:when>
386 <xsl:when test="@type = 'integer'">Integer</xsl:when>
387 <xsl:when test="@type = 'p_integer'">int</xsl:when>
388 <xsl:when test="@type = 'long'">Long</xsl:when>
389 <xsl:when test="@type = 'p_long'">long</xsl:when>
390 <xsl:when test="@type = 'date'">long</xsl:when>
391 <xsl:when test="@type = 'real'">Float</xsl:when>
392 <xsl:when test="@type = 'p_real'">float</xsl:when>
393 <xsl:when test="@type = 'double'">Double</xsl:when>
394 <xsl:when test="@type = 'p_double'">double</xsl:when>
395 <xsl:otherwise>String</xsl:otherwise>
396 </xsl:choose>
397 </xsl:when>
398 <xsl:otherwise>
399 <xsl:variable name="val">
400 <xsl:call-template name="upperCase">
401 <xsl:with-param name="val" select="@class"/>
402 </xsl:call-template>
403 </xsl:variable>
404 <xsl:if test="$root_package"><xsl:value-of select="concat($root_package,'.')"/></xsl:if><xsl:value-of select="@package"/>.<xsl:value-of select="$val"/>
405 </xsl:otherwise>
406 </xsl:choose>
407 </xsl:template>
408
409 <xsl:template name="upperCase">
410 <xsl:param name="val"/>
411 <xsl:variable name="prem" select="substring($val,1,1)"/>
412 <xsl:variable name="first" select="translate($prem,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
413 <xsl:variable name="end" select="substring($val,2,string-length($val)-1)"/>
414 <xsl:value-of select="concat($first,$end)"/>
415 </xsl:template>
416
417 <xsl:template name="lowerCase">
418 <xsl:param name="val"/>
419 <xsl:variable name="prem" select="substring($val,1,1)"/>
420 <xsl:variable name="first" select="translate($prem,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
421 <xsl:variable name="end" select="substring($val,2,string-length($val)-1)"/>
422 <xsl:value-of select="@package"/>.<xsl:value-of select="concat($first,$end)"/>
423 </xsl:template>
424
425
426 <xsl:template match="datatype" mode="DefaultValue">
427 <xsl:choose>
428 <xsl:when test="@type">
429 <xsl:choose>
430 <xsl:when test="@type = 'boolean'">null</xsl:when>
431 <xsl:when test="@type = 'p_boolean'">false</xsl:when>
432 <xsl:when test="@type = 'integer'">null</xsl:when>
433 <xsl:when test="@type = 'p_integer'">0</xsl:when>
434 <xsl:when test="@type = 'long'">null</xsl:when>
435 <xsl:when test="@type = 'p_long'">0</xsl:when>
436 <xsl:when test="@type = 'date'">0</xsl:when>
437 <xsl:when test="@type = 'real'">null</xsl:when>
438 <xsl:when test="@type = 'p_real'">0</xsl:when>
439 <xsl:when test="@type = 'double'">null</xsl:when>
440 <xsl:when test="@type = 'p_double'">0</xsl:when>
441 <xsl:otherwise>null</xsl:otherwise>
442 </xsl:choose>
443 </xsl:when>
444 <xsl:otherwise>null</xsl:otherwise>
445 </xsl:choose>
446 </xsl:template>
447
448 <xsl:template match="attribute" mode="declare">
449 <xsl:variable name="type">
450 <xsl:apply-templates select="datatype" mode="JavaType"/>
451 </xsl:variable>
452 <xsl:variable name="defaultValue">
453 <xsl:apply-templates select="datatype" mode="DefaultValue"/>
454 </xsl:variable>
455 private <xsl:value-of select="$type"/>&bl;<xsl:value-of select="name"/> = <xsl:value-of select="$defaultValue"/>;
456 </xsl:template>
457
458 <xsl:template match="attribute" mode="getset">
459 <xsl:variable name="type">
460 <xsl:apply-templates select="datatype" mode="JavaType"/>
461 </xsl:variable>
462 <xsl:variable name="name">
463 <xsl:call-template name="upperCase">
464 <xsl:with-param name="val" select="name"/>
465 </xsl:call-template>
466 </xsl:variable>
467 public <xsl:value-of select="$type"/>&bl;get<xsl:value-of select="$name"/>() {
468 return this.<xsl:value-of select="name"/>;
469 }
470 public void set<xsl:value-of select="$name"/>(<xsl:value-of select="$type"/> _val) {
471 this.<xsl:value-of select="name"/> = _val;
472 }
473 </xsl:template>
474 <xsl:template match="collection" mode="declare">
475 <xsl:variable name="type">
476 <xsl:apply-templates select="datatype" mode="JavaType"/>
477 </xsl:variable>
478 private List&lt;<xsl:value-of select="$type"/>&gt;&bl;<xsl:value-of select="name"/> = null;
479 </xsl:template>
480
481 <xsl:template match="collection" mode="getset">
482 <xsl:variable name="type">
483 <xsl:apply-templates select="datatype" mode="JavaType"/>
484 </xsl:variable>
485 <xsl:variable name="name">
486 <xsl:call-template name="upperCase">
487 <xsl:with-param name="val" select="name"/>
488 </xsl:call-template>
489 </xsl:variable>
490 public List&lt;<xsl:value-of select="$type"/>&gt;&bl;get<xsl:value-of select="$name"/>() {
491 return this.<xsl:value-of select="name"/>;
492 }
493 public void set<xsl:value-of select="$name"/>(List&lt;<xsl:value-of select="$type"/>&gt; _val) {
494 this.<xsl:value-of select="name"/> = _val;
495 }
496 </xsl:template>
497
498 <xsl:template match="reference" mode="declare">
499 <xsl:variable name="type">
500 <xsl:apply-templates select="datatype" mode="JavaType"/>
501 </xsl:variable>
502 private <xsl:value-of select="$type"/>&bl;<xsl:value-of select="name"/> = null;
503 </xsl:template>
504
505 <xsl:template match="reference" mode="getset">
506 <xsl:variable name="type">
507 <xsl:apply-templates select="datatype" mode="JavaType"/>
508 </xsl:variable>
509 <xsl:variable name="name">
510 <xsl:call-template name="upperCase">
511 <xsl:with-param name="val" select="name"/>
512 </xsl:call-template>
513 </xsl:variable>
514 public <xsl:value-of select="$type"/>&bl;get<xsl:value-of select="$name"/>() {
515 return this.<xsl:value-of select="name"/>;
516 }
517 public void set<xsl:value-of select="$name"/>(<xsl:value-of select="$type"/> _val) {
518 this.<xsl:value-of select="name"/> = _val;
519 }
520 </xsl:template>
521
522 <xsl:template match="enumliterals" >
523 <xsl:variable name="type">
524 <xsl:apply-templates select="datatype" mode="JavaType"/>
525 </xsl:variable>
526 <xsl:variable name="defaultValue">
527 <xsl:apply-templates select="datatype" mode="DefaultValue"/>
528 </xsl:variable>
529 private <xsl:value-of select="$type"/>&bl;<xsl:value-of select="name"/> = <xsl:value-of select="$defaultValue"/>;
530 </xsl:template>
531
532
533 </xsl:stylesheet>

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