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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 690 - (show annotations)
Thu Jul 10 15:27:40 2008 UTC (12 years, 4 months ago) by bourges.laurent
File MIME type: application/xml
File size: 42459 byte(s)
added rank support for collections
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 <!--
12 This XSLT script transforms a data model from our intermediate representation to
13 Java classes compliant with JPA 1.0 & JAXB 2.1 specifications.
14
15 Java 1.5+ is required by these two libraries.
16 -->
17
18
19 <xsl:import href="common.xsl"/>
20 <xsl:import href="jpa.xsl"/>
21 <xsl:import href="jaxb.xsl"/>
22
23
24 <xsl:output method="text" encoding="UTF-8" indent="yes" />
25 <xsl:output name="packageInfo" method="html" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
26
27 <xsl:strip-space elements="*" />
28
29 <xsl:key name="element" match="*//*" use="@xmiid"/>
30
31 <xsl:param name="lastModified"/>
32 <xsl:param name="lastModifiedText"/>
33
34
35 <xsl:param name="root_package"/> <!-- select="'org.ivoa.'" -->
36 <xsl:param name="model_package"/>
37 <xsl:param name="targetnamespace_root"/>
38
39 <!-- next could be parameters -->
40 <xsl:variable name="root_package_dir" select="replace($root_package,'[.]','/')"/>
41
42
43 <!--
44 Use '{NOTE/TODO} [JPA_COMPLIANCE] :' to indicate a violated rule and explain why.
45
46
47 JPA 1.0 specification extract for Entity definition :
48
49
50 "2.1 Requirements on the Entity Class
51
52 The entity class must be annotated with the Entity annotation or denoted in the XMLdescriptor as an entity.
53
54 The entity class must have a no-arg constructor. The entity class may have other constructors as well.
55 The no-arg constructor must be public or protected.
56
57 The entity class must be a top-level class. An enum or interface should not be designated as an entity.
58
59 The entity class must not be final. No methods or persistent instance variables of the entity class may be final.
60
61 Entities support inheritance, polymorphic associations, and polymorphic queries.
62
63 Both abstract and concrete classes can be entities. Entities may extend non-entity classes as well as entity classes,
64 and non-entity classes may extend entity classes.
65
66 The persistent state of an entity is accessed by the persistence provider runtime either via JavaBeans
67 style property accessors or via instance variables. A single access type (field or property access) applies
68 to an entity hierarchy. When annotations are used, the placement of the mapping annotations on either
69 the persistent fields or persistent properties of the entity class specifies the access type as being either
70 field- or property-based access respectively.
71
72 - If the entity has field-based access, the persistence provider runtime accesses instance variables
73 directly. All non-transient instance variables that are not annotated with the Transient
74 annotation are persistent. When field-based access is used, the object/relational mapping annotations
75 for the entity class annotate the instance variables.
76
77 - If the entity has property-based access, the persistence provider runtime accesses persistent
78 state via the property accessor methods. All properties not annotated with the Transient
79 annotation are persistent. The property accessor methods must be public or protected. When
80 property-based access is used, the object/relational mapping annotations for the entity class
81 annotate the getter property accessors.
82
83 - Mapping annotations cannot be applied to fields or properties that are transient or Transient.
84
85 - The behavior is unspecified if mapping annotations are applied to both persistent fields and
86 properties or if the XML descriptor specifies use of different access types within a class hierarchy.
87
88 NOTE [JPA_COMPLIANCE] : FIELD-BASES ACCESS is the strategy chosen for persistent attributes.
89
90 It is required that the entity class follow the method signature conventions for JavaBeans read/write
91 properties (as defined by the JavaBeans Introspector class) for persistent properties when persistent
92 properties are used.
93
94 In this case, for every persistent property property of type T of the entity, there is a getter method, get-
95 Property, and setter method setProperty. For boolean properties, isProperty is an alternative name for
96 the getter method.
97
98 For single-valued persistent properties, these method signatures are:
99 - T getProperty()
100 - void setProperty(T t)
101
102 Collection-valued persistent fields and properties must be defined in terms of one of the following collection-
103 valued interfaces regardless of whether the entity class otherwise adheres to the JavaBeans
104 method conventions noted above and whether field or property-based access is used:
105 java.util.Collection, java.util.Set, java.util.List[4], java.util.Map.[5]
106
107 [4] Portable applications should not expect the order of lists to be maintained across persistence contexts unless the OrderBy construct
108 is used and the modifications to the list observe the specified ordering. The order is not otherwise persistent.
109
110 [5] The implementation type may be used by the application to initialize fields or properties before the entity is made persistent; subsequent
111 access must be through the interface type once the entity becomes managed (or detached).
112
113 For collection-valued persistent properties, type T must be one of these collection interface types in the
114 method signatures above. Generic variants of these collection types may also be used (for example,
115 Set<Order>).
116
117 In addition to returning and setting the persistent state of the instance, the property accessor methods
118 may contain other business logic as well, for example, to perform validation. The persistence provider
119 runtime executes this logic when property-based access is used.
120
121 Caution should be exercised in adding business logic to the accessor methods when property-
122 based access is used. The order in which the persistence provider runtime calls these
123 methods when loading or storing persistent state is not defined. Logic contained in such methods
124 therefore cannot rely upon a specific invocation order.
125
126 If property-based access is used and lazy fetching is specified, portable applications should not directly
127 access the entity state underlying the property methods of managed instances until after it has been
128 fetched by the persistence provider.[6]
129
130 [6] Lazy fetching is a hint to the persistence provider and can be specified by means of the Basic, OneToOne, OneToMany, Many-
131 ToOne, and ManyToMany annotations and their XML equivalents. See chapter 9.
132
133 Runtime exceptions thrown by property accessor methods cause the current transaction to be rolled
134 back. Exceptions thrown by such methods when used by the persistence runtime to load or store persistent
135 state cause the persistence runtime to rollback the current transaction and to throw a PersistenceException
136 that wraps the application exception.
137
138 Entity subclasses may override the property accessor methods. However, portable applications must not
139 override the object/relational mapping metadata that applies to the persistent fields or properties of
140 entity superclasses.
141
142 The persistent fields or properties of an entity may be of the following types: Java primitive types;
143 java.lang.String; other Java serializable types (including wrappers of the primitive types,
144 java.math.BigInteger, java.math.BigDecimal, java.util.Date,
145 java.util.Calendar[7], java.sql.Date, java.sql.Time, java.sql.Timestamp,
146 user-defined serializable types, byte[], Byte[], char[], and Character[]); enums; entity
147 types and/or collections of entity types; and embeddable classes (see section 2.1.5).
148
149 Object/relational mapping metadata may be specified to customize the object-relational mapping, and
150 the loading and storing of the entity state and relationships. See Chapter 9.
151
152 -->
153
154
155
156
157 <!-- main pattern : processes for root node model -->
158 <xsl:template match="/">
159 <xsl:message>Root package = <xsl:value-of select="$root_package"/></xsl:message>
160 <xsl:message>Root package dir= <xsl:value-of select="$root_package_dir"/></xsl:message>
161 <xsl:message>Model package = <xsl:value-of select="$model_package"/></xsl:message>
162 <xsl:apply-templates select="model"/>
163 </xsl:template>
164
165
166
167
168 <!-- model pattern : generates gen-log and processes nodes package and generates the ModelVersion class and persistence.xml -->
169 <xsl:template match="model">
170 <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
171 -- Generating Java code for model <xsl:value-of select="name"/>.
172 -- last modification date of the UML model <xsl:value-of select="$lastModifiedText"/>
173
174 <xsl:for-each select="package">
175 <xsl:call-template name="package">
176 <xsl:with-param name="dir" select="$root_package_dir"/>
177 <xsl:with-param name="path" select="$root_package"/>
178 </xsl:call-template>
179 </xsl:for-each>
180
181 <xsl:apply-templates select="." mode="modelVersion" />
182
183 <xsl:apply-templates select="." mode="jpaConfig" />
184
185 </xsl:template>
186
187
188
189
190 <xsl:template name="package">
191 <xsl:param name="dir"/>
192 <xsl:param name="path"/>
193
194 <xsl:variable name="newdir">
195 <xsl:choose>
196 <xsl:when test="$dir">
197 <xsl:value-of select="concat($dir,'/',name)"/>
198 </xsl:when>
199 <xsl:otherwise>
200 <xsl:value-of select="name"/>
201 </xsl:otherwise>
202 </xsl:choose>
203 </xsl:variable>
204
205 <xsl:variable name="newpath">
206 <xsl:choose>
207 <xsl:when test="$path">
208 <xsl:value-of select="concat($path,'.',name)"/>
209 </xsl:when>
210 <xsl:otherwise>
211 <xsl:value-of select="name"/>
212 </xsl:otherwise>
213 </xsl:choose>
214 </xsl:variable>
215
216 <xsl:message>package = <xsl:value-of select="$newpath"></xsl:value-of></xsl:message>
217
218 <xsl:apply-templates select="." mode="packageDesc">
219 <xsl:with-param name="dir" select="$newdir"/>
220 </xsl:apply-templates>
221
222 <xsl:apply-templates select="." mode="jaxb.index">
223 <xsl:with-param name="dir" select="$newdir"/>
224 </xsl:apply-templates>
225
226 <xsl:for-each select="objectType">
227 <xsl:call-template name="objectType">
228 <xsl:with-param name="dir" select="$newdir"/>
229 <xsl:with-param name="path" select="$newpath"/>
230 </xsl:call-template>
231 </xsl:for-each>
232
233 <xsl:for-each select="dataType">
234 <xsl:call-template name="dataType">
235 <xsl:with-param name="dir" select="$newdir"/>
236 <xsl:with-param name="path" select="$newpath"/>
237 </xsl:call-template>
238 </xsl:for-each>
239
240 <xsl:for-each select="enumeration">
241 <xsl:call-template name="enumeration">
242 <xsl:with-param name="dir" select="$newdir"/>
243 <xsl:with-param name="path" select="$newpath"/>
244 </xsl:call-template>
245 </xsl:for-each>
246
247 <xsl:for-each select="package">
248 <xsl:call-template name="package">
249 <xsl:with-param name="dir" select="$newdir"/>
250 <xsl:with-param name="path" select="$newpath"/>
251 </xsl:call-template>
252 </xsl:for-each>
253 </xsl:template>
254
255
256
257
258 <xsl:template name="objectType">
259 <xsl:param name="dir"/>
260 <xsl:param name="path"/>
261
262 <xsl:variable name="className" select="name" />
263 <xsl:variable name="xmiid" select="@xmiid" />
264
265 <xsl:variable name="hasChild">
266 <xsl:choose>
267 <xsl:when test="count(//objectType[extends/@xmiidref = $xmiid]) > 0">1</xsl:when>
268 <xsl:otherwise>0</xsl:otherwise>
269 </xsl:choose>
270 </xsl:variable>
271
272 <xsl:variable name="hasExtends">
273 <xsl:choose>
274 <xsl:when test="count(extends) = 1">1</xsl:when>
275 <xsl:otherwise>0</xsl:otherwise>
276 </xsl:choose>
277 </xsl:variable>
278
279 <xsl:variable name="hasList">
280 <xsl:choose>
281 <xsl:when test="count(collection) > 0">1</xsl:when>
282 <xsl:otherwise>0</xsl:otherwise>
283 </xsl:choose>
284 </xsl:variable>
285
286 <xsl:variable name="file" select="concat('src/', $dir, '/', name, '.java')"/>
287
288 <!-- open file for this class -->
289 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
290
291 <xsl:result-document href="{$file}">
292
293 <xsl:apply-templates select="." mode="class">
294 <xsl:with-param name="path" select="$path"/>
295 <xsl:with-param name="className" select="$className"/>
296 <xsl:with-param name="hasChild" select="$hasChild"/>
297 <xsl:with-param name="hasExtends" select="$hasExtends"/>
298 <xsl:with-param name="hasList" select="$hasList"/>
299 </xsl:apply-templates>
300
301 </xsl:result-document>
302 </xsl:template>
303
304
305
306
307 <xsl:template match="objectType|dataType" mode="typeimports">
308 <xsl:variable name="thispackageid" select="./../@xmiid"/>
309 <xsl:for-each select="key('element',distinct-values(extends/@xmiidref|container/@xmiidref|attribute/datatype/@xmiidref|reference/datatype/@xmiidref|collection/datatype/@xmiidref))" >
310 <xsl:if test="./../@xmiid != $thispackageid and name(.) != 'primitiveType'">
311 <xsl:variable name="qualifiedtype">
312 <xsl:call-template name="QualifiedJavaType"><xsl:with-param name="type" select="."/></xsl:call-template>
313 </xsl:variable>
314 import <xsl:value-of select="$qualifiedtype"/>;
315 </xsl:if>
316 </xsl:for-each>
317 </xsl:template>
318
319
320
321
322 <xsl:template name="dataType">
323 <xsl:param name="dir"/>
324 <xsl:param name="path"/>
325
326 <xsl:variable name="className" select="name" />
327
328 <xsl:variable name="xmiid" select="@xmiid" />
329 <xsl:variable name="hasChild">
330 <xsl:choose>
331 <xsl:when test="count(//extends[@xmiidref = $xmiid]) > 0">1</xsl:when>
332 <xsl:otherwise>0</xsl:otherwise>
333 </xsl:choose>
334 </xsl:variable>
335
336 <xsl:variable name="hasExtends">
337 <xsl:choose>
338 <xsl:when test="count(extends) = 1">1</xsl:when>
339 <xsl:otherwise>0</xsl:otherwise>
340 </xsl:choose>
341 </xsl:variable>
342
343 <xsl:variable name="file" select="concat('src/', $dir, '/', name, '.java')"/>
344
345 <!-- open file for this class -->
346 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
347
348 <xsl:result-document href="{$file}">
349
350 <xsl:apply-templates select="." mode="class">
351 <xsl:with-param name="path" select="$path"/>
352 <xsl:with-param name="className" select="$className"/>
353 <xsl:with-param name="hasChild" select="$hasChild"/>
354 <xsl:with-param name="hasExtends" select="$hasExtends"/>
355 <xsl:with-param name="hasList" select="0"/>
356 </xsl:apply-templates>
357
358 </xsl:result-document>
359 </xsl:template>
360
361
362
363
364
365 <!-- template class creates a java class (JPA compliant) for UML object & data types -->
366 <xsl:template match="objectType|dataType" mode="class">
367 <xsl:param name="path"/>
368 <xsl:param name="className"/>
369 <xsl:param name="hasChild"/>
370 <xsl:param name="hasExtends"/>
371 <xsl:param name="hasList"/>
372
373 <xsl:variable name="kind">
374 <xsl:choose>
375 <xsl:when test="name() = 'dataType'">DataType</xsl:when>
376 <xsl:when test="name() = 'objectType'">Object</xsl:when>
377 </xsl:choose>
378 </xsl:variable>
379
380 package <xsl:value-of select="$path"/>;
381
382 <!-- imports -->
383 import java.util.Date;
384 <xsl:if test="$hasList = 1">
385 import java.util.List;
386 import java.util.ArrayList;
387 </xsl:if>
388 import java.util.Map;
389
390 import javax.persistence.*;
391 import javax.xml.bind.annotation.*;
392
393 import static <xsl:value-of select="$root_package"/>.ModelVersion.LAST_MODIFICATION_DATE;
394
395 import <xsl:value-of select="$model_package"/>.MetadataElement;
396 <xsl:if test="reference[not(extends)]">
397 import <xsl:value-of select="$model_package"/>.Reference;
398 </xsl:if>
399
400 <xsl:if test="$hasExtends = 0 or ($kind='Object' and reference)">
401 import <xsl:value-of select="$model_package"/>.Metadata<xsl:value-of select="$kind"/>;
402 </xsl:if>
403
404 <xsl:apply-templates select="." mode="typeimports"/>
405
406 /**
407 * UML <xsl:value-of select="$kind"/>&bl;<xsl:value-of select="name"/> :
408 *
409 * <xsl:apply-templates select="." mode="desc" />
410 *
411 * @author generated by UML2 Generator tool (UML->XMI->XSLT->java code)
412 */
413
414 <xsl:apply-templates select="." mode="JPAAnnotation"/>
415 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
416
417 public&bl;<xsl:if test="@abstract='true'">abstract</xsl:if>&bl;class <xsl:value-of select="$className"/>&bl;
418 <xsl:choose>
419 <xsl:when test="$hasExtends = 1">extends <xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="extends/@xmiidref"/></xsl:call-template></xsl:when>
420 <xsl:otherwise>extends Metadata<xsl:value-of select="$kind"/></xsl:otherwise>
421 </xsl:choose>
422 &bl;{
423
424 /** serial uid = last modification date of the UML model */
425 private static final long serialVersionUID = LAST_MODIFICATION_DATE;
426
427 <xsl:apply-templates select="." mode="JPASpecials">
428 <xsl:with-param name="hasChild" select="$hasChild"/>
429 <xsl:with-param name="hasExtends" select="$hasExtends"/>
430 </xsl:apply-templates>
431
432 <xsl:apply-templates select="attribute" mode="declare" />
433 <xsl:apply-templates select="collection" mode="declare" />
434 <xsl:apply-templates select="reference" mode="declare" />
435
436 /**
437 * Creates a new <xsl:value-of select="$className"/>
438 */
439 public <xsl:value-of select="$className"/>() {
440 super();
441 }
442
443 <xsl:if test="container">
444 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="container/@xmiidref"/></xsl:call-template></xsl:variable>
445 /**
446 * Creates a new <xsl:value-of select="$className"/> for the given Container Entity. &lt;br&gt;
447 *
448 * The Parent Container CAN NOT BE NULL
449 *
450 * @param pContainer the parent container CAN NOT BE NULL
451 */
452 public <xsl:value-of select="$className"/>(final <xsl:value-of select="$type"/> pContainer) {
453 super();
454 this.setContainer(pContainer);
455 }
456 </xsl:if>
457
458 <xsl:apply-templates select="attribute|reference|collection" mode="getset"/>
459
460 <xsl:if test="container">
461 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="container/@xmiidref"/></xsl:call-template></xsl:variable>
462 <xsl:variable name="collection">
463 <xsl:call-template name="upperFirst">
464 <xsl:with-param name="val" select="container/@relation"/>
465 </xsl:call-template>
466 </xsl:variable>
467 /**
468 * Returns the Container Entity == 'Parent'
469 * @return the parent container Entity
470 */
471 public <xsl:value-of select="$type"/> getContainer() {
472 return this.container;
473 }
474
475 /**
476 * Sets the Container Entity == 'Parent' ONLY
477 * @param pContainer the parent container
478 */
479 private void setContainerField(final <xsl:value-of select="$type"/> pContainer) {
480 this.container = pContainer;
481 }
482
483 /**
484 * Sets the Container Entity == 'Parent' and adds this to the appropriate collection on the container.
485 *
486 * @param pContainer the parent container CAN NOT BE NULL
487 *
488 * @throws IllegalStateException if pContainer is null !
489 */
490 protected void setContainer(final <xsl:value-of select="$type"/> pContainer) {
491 if (pContainer == null) {
492 throw new IllegalStateException("The parent container can not be null !");
493 }
494 setContainerField(pContainer);
495 pContainer.add<xsl:value-of select="$collection"/>(this);
496 }
497
498 /**
499 * Returns the Rank in the collection
500 * @return rank
501 */
502 public int getRank() {
503 return this.rank;
504 }
505
506 /**
507 * Sets the Rank
508 * @param pRank rank in the parent collection
509 */
510 protected void setRank(final int pRank) {
511 this.rank = pRank;
512 }
513 </xsl:if>
514
515 <xsl:if test="$hasExtends = 0">
516 <xsl:if test="name() = 'objectType'">
517 /**
518 * Returns Jpa version for optimistic locking
519 * @return jpa version number
520 */
521 protected int getJpaVersion() {
522 return this.jpaVersion;
523 }
524 <xsl:if test="$hasChild = 1">
525 /**
526 * Returns Class type (discriminator value) in inheritance hierarchy
527 * @return class type
528 */
529 protected String getClassType() {
530 return this.classType;
531 }
532 </xsl:if>
533 </xsl:if>
534 </xsl:if>
535
536 <xsl:apply-templates select="." mode="hashcode_equals"/>
537
538 /**
539 * Returns the property value given the property name.<br/>
540 * Can be any property (internal, attribute, reference, collection) and all type must be supported (dataType,
541 * objectType, enumeration)
542 *
543 * @param propertyName name of the property (like in UML model)
544 *
545 * @return property value or null if unknown or not defined
546 */
547 @Override
548 public Object getProperty(final String propertyName) {
549 // first : checks if propertyName is null or empty :
550 if (propertyName == null) {
551 return null;
552 }
553 // second : search in parent classes (maybe null) :
554 Object res = super.getProperty(propertyName);
555
556 <xsl:if test="container">
557 if (PROPERTY_CONTAINER.equals(propertyName)) {
558 return getContainer();
559 }
560 if (PROPERTY_RANK.equals(propertyName)) {
561 return Integer.valueOf(getRank());
562 }
563 </xsl:if>
564
565 <!-- TODO collection support ? -->
566 <xsl:apply-templates select="attribute|reference|collection" mode="getProperty" />
567
568 return res;
569 }
570
571 /**
572 * Sets the property value to the given property name. <br/>
573 * Can be any property (internal, attribute, reference, collection) and all type must be supported (dataType,
574 * objectType, enumeration)
575 *
576 * @param propertyName name of the property (like in UML model)
577 *
578 * @param value to be set
579 *
580 * @return true if property has been set
581 */
582 @Override
583 public boolean setProperty(final String propertyName, final Object value) {
584 // first : checks if propertyName is null or empty :
585 if (propertyName == null) {
586 return false;
587 }
588 // second : search in parent classes (maybe null) :
589 boolean res = super.setProperty(propertyName, value);
590
591 if (!res) {
592 <xsl:if test="container">
593 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="container/@xmiidref"/></xsl:call-template></xsl:variable>
594 <xsl:variable name="collection">
595 <xsl:call-template name="upperFirst">
596 <xsl:with-param name="val" select="container/@relation"/>
597 </xsl:call-template>
598 </xsl:variable>
599 if (PROPERTY_CONTAINER.equals(propertyName)) {
600 setContainerField((<xsl:value-of select="$type"/>) value);
601 return true;
602 }
603 if (PROPERTY_RANK.equals(propertyName)) {
604 setRank(((Integer)value).intValue());
605 return true;
606 }
607 </xsl:if>
608
609 <!-- TODO collection support ? -->
610 <xsl:apply-templates select="attribute|reference" mode="setProperty" />
611 }
612 return res;
613 }
614
615 /**
616 * Puts the string representation in the given string buffer : &lt;br&gt;
617 * "Type =[class name @ hashcode] : { field name = field value , ...}"
618 *
619 * @param sb given string buffer to fill
620 * @param isDeep true means to call deepToString(sb, true, ids) for all attributes / references / collections which are
621 * MetadataElement implementations
622 * @param ids identity map to avoid cyclic loops
623 *
624 * @return stringbuffer the given string buffer filled with the string representation
625 */
626 <xsl:if test="$hasExtends = 1">
627 @Override
628 </xsl:if>
629 protected StringBuilder deepToString(final StringBuilder sb, final boolean isDeep, final Map&lt;MetadataElement, Object&gt; ids) {
630 <xsl:if test="$hasExtends = 1">
631 super.deepToString(sb, isDeep, ids);
632 </xsl:if>
633
634 sb.append("\n[ <xsl:value-of select="$className"/>");
635 sb.append("={");
636
637 <xsl:if test="container">
638 sb.append("container=");
639 if (getContainer() != null) {
640 // short toString :
641 MetadataElement.deepToString(sb, false, ids, getContainer());
642 }
643 sb.append(" | ");
644 </xsl:if>
645
646 <xsl:apply-templates select="attribute|reference|collection" mode="tostring" />
647
648 return sb.append("} ]");
649 }
650
651 }
652 </xsl:template>
653
654
655
656
657 <xsl:template name="enumeration">
658 <xsl:param name="dir"/>
659 <xsl:param name="path"/>
660
661 <xsl:variable name="file" select="concat('src/', $dir, '/', name, '.java')"/>
662
663 <!-- open file for this class -->
664 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
665
666 <xsl:result-document href="{$file}">
667
668 package <xsl:value-of select="$path"/>;
669
670 <!-- imports -->
671 import javax.persistence.*;
672 import javax.xml.bind.annotation.*;
673
674 /**
675 * UML Enumeration <xsl:value-of select="name"/> :
676 *
677 * <xsl:apply-templates select="." mode="desc" />
678 *
679 * @author generated by UML2 Generator tool (UML->XMI->XSLT->java code)
680 */
681 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
682 public enum <xsl:value-of select="name"/>&bl;{
683
684 <xsl:apply-templates select="literal" />
685
686 /** string representation */
687 private final String value;
688
689 /**
690 * Creates a new <xsl:value-of select="name"/> Enumeration Literal
691 *
692 * @param v string representation
693 */
694 <xsl:value-of select="name"/>(final String v) {
695 value = v;
696 }
697
698 /**
699 * Returns string representation
700 * @return string representation
701 */
702 public final String value() {
703 return this.value;
704 }
705
706 /**
707 * Returns <xsl:value-of select="name"/> Enumeration Literal corresponding to the given string representation
708 *
709 * @param v string representation
710 *
711 * @return value <xsl:value-of select="name"/> Enumeration Literal
712 *
713 * @throws IllegalArgumentException if string representation not found
714 */
715 public final static <xsl:value-of select="name"/> fromValue(final String v) {
716 for (<xsl:value-of select="name"/> c : <xsl:value-of select="name"/>.values()) {
717 if (c.value.equals(v)) {
718 return c;
719 }
720 }
721 throw new IllegalArgumentException("<xsl:value-of select="name"/>.fromValue : unknown value : " + v);
722 }
723
724 }
725 </xsl:result-document>
726 </xsl:template>
727
728
729
730
731
732
733
734
735 <xsl:template match="attribute" mode="declare">
736 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
737 /**
738 * Attribute <xsl:value-of select="name"/> :
739 * <xsl:apply-templates select="." mode="desc" />
740 * (
741 * Multiplicity : <xsl:value-of select="multiplicity"/>
742 <xsl:if test="constraints/maxLength">
743 * , MaxLength : <xsl:value-of select="constraints/maxLength"/>
744 </xsl:if>
745 * )
746 */
747 <xsl:apply-templates select="." mode="JPAAnnotation"/>
748 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
749 private <xsl:value-of select="$type"/>&bl;<xsl:value-of select="name"/>;
750 </xsl:template>
751
752
753
754
755 <xsl:template match="attribute" mode="getset">
756 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
757 <xsl:variable name="name">
758 <xsl:call-template name="upperFirst">
759 <xsl:with-param name="val" select="name"/>
760 </xsl:call-template>
761 </xsl:variable>
762 /**
763 * Returns <xsl:value-of select="name"/> Attribute
764 * @return <xsl:value-of select="name"/> Attribute
765 */
766 public <xsl:value-of select="$type"/>&bl;get<xsl:value-of select="$name"/>() {
767 return this.<xsl:value-of select="name"/>;
768 }
769 /**
770 * Defines <xsl:value-of select="name"/> Attribute
771 * @param p<xsl:value-of select="$name"/> value to set
772 */
773 public void set<xsl:value-of select="$name"/>(final <xsl:value-of select="$type"/> p<xsl:value-of select="$name"/>) {
774 this.<xsl:value-of select="name"/> = p<xsl:value-of select="$name"/>;
775 }
776 </xsl:template>
777
778
779
780
781 <xsl:template match="attribute" mode="setProperty">
782 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
783 <xsl:variable name="name">
784 <xsl:call-template name="upperFirst">
785 <xsl:with-param name="val" select="name"/>
786 </xsl:call-template>
787 </xsl:variable>
788 if ("<xsl:value-of select="name"/>".equals(propertyName)) {
789 set<xsl:value-of select="$name"/>((<xsl:value-of select="$type"/>)value);
790 return true;
791 }
792 </xsl:template>
793
794
795
796
797 <xsl:template match="collection" mode="declare">
798 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
799 /**
800 * Collection <xsl:value-of select="name"/> :
801 * <xsl:apply-templates select="." mode="desc" />
802 * (
803 * Multiplicity : <xsl:value-of select="multiplicity"/>
804 * )
805 */
806 <xsl:apply-templates select="." mode="JPAAnnotation"/>
807 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
808 private List&lt;<xsl:value-of select="$type"/>&gt;&bl;<xsl:value-of select="name"/> = null;
809 </xsl:template>
810
811
812
813
814 <xsl:template match="collection" mode="getset">
815 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
816 <xsl:variable name="name">
817 <xsl:call-template name="upperFirst">
818 <xsl:with-param name="val" select="name"/>
819 </xsl:call-template>
820 </xsl:variable>
821 /**
822 * Returns <xsl:value-of select="name"/> Collection
823 * @return <xsl:value-of select="name"/> Collection
824 */
825 public List&lt;<xsl:value-of select="$type"/>&gt;&bl;get<xsl:value-of select="$name"/>() {
826 return this.<xsl:value-of select="name"/>;
827 }
828 /**
829 * Defines <xsl:value-of select="name"/> Collection
830 * @param p<xsl:value-of select="$name"/> collection to set
831 */
832 public void set<xsl:value-of select="$name"/>(final List&lt;<xsl:value-of select="$type"/>&gt; p<xsl:value-of select="$name"/>) {
833 this.<xsl:value-of select="name"/> = p<xsl:value-of select="$name"/>;
834 }
835 /**
836 * Add a <xsl:value-of select="$type"/> to the collection
837 * @param p<xsl:value-of select="$type"/>&bl;<xsl:value-of select="$type"/> to add
838 */
839 public void add<xsl:value-of select="$name"/>(final <xsl:value-of select="$type"/> p<xsl:value-of select="$type"/>) {
840 if(this.<xsl:value-of select="name"/> == null)
841 this.<xsl:value-of select="name"/> = new ArrayList&lt;<xsl:value-of select="$type"/>&gt;();
842 this.<xsl:value-of select="name"/>.add(p<xsl:value-of select="$type"/>);
843 }
844 </xsl:template>
845
846
847
848
849 <xsl:template match="reference" mode="declare">
850 <xsl:if test="not(subsets)">
851 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
852 /**
853 * Reference <xsl:value-of select="name"/> :
854 * <xsl:apply-templates select="." mode="desc" />
855 * (
856 * Multiplicity : <xsl:value-of select="multiplicity"/>
857 * )
858 */
859 <xsl:apply-templates select="." mode="JPAAnnotation"/>
860 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
861 private <xsl:value-of select="$type"/>&bl;<xsl:value-of select="name"/> = null;
862 /**
863 * "lazy" version of the <xsl:value-of select="name"/> reference.
864 * Used by XML (un)marshallers to resolve possibly inderectly referenced resource <xsl:value-of select="$type"/>.
865 */
866 <xsl:apply-templates select="." mode="JPAAnnotation_reference"/>
867 <xsl:apply-templates select="." mode="JAXBAnnotation_reference"/>
868 protected Reference&bl;p_<xsl:value-of select="name"/> = null;
869 </xsl:if>
870 </xsl:template>
871
872
873
874
875 <xsl:template match="reference" mode="getset">
876 <xsl:variable name="ctype" select="key('element',datatype/@xmiidref)"/>
877
878 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
879 <xsl:variable name="name">
880 <xsl:call-template name="upperFirst">
881 <xsl:with-param name="val" select="name"/>
882 </xsl:call-template>
883 </xsl:variable>
884 /**
885 * Returns <xsl:value-of select="name"/> Reference<br/>
886 * If the <xsl:value-of select="name"/> variable is null but its "lazy" version
887 * p_<xsl:value-of select="name"/> is not, that lazy reference will be resolved to the actual object.
888 * @return <xsl:value-of select="name"/> Reference
889 */
890 public <xsl:value-of select="$type"/>&bl;get<xsl:value-of select="$name"/>() {
891 <xsl:choose>
892 <xsl:when test="subsets">
893 return (<xsl:value-of select="$type"/>)super.get<xsl:value-of select="$name"/>();
894 </xsl:when>
895 <xsl:otherwise>
896 if(<xsl:value-of select="name"/> == null
897 &amp;&amp; this.p_<xsl:value-of select="name"/> != null)
898 this.<xsl:value-of select="name"/> = (<xsl:value-of select="$type"/>)resolve(this.p_<xsl:value-of select="name"/>, <xsl:value-of select="$type"/>.class);
899 return this.<xsl:value-of select="name"/>;
900 </xsl:otherwise>
901 </xsl:choose>
902 }
903 /**
904 * Defines <xsl:value-of select="name"/> Reference
905 * @param p<xsl:value-of select="$name"/> reference to set
906 */
907 public void set<xsl:value-of select="$name"/>(final <xsl:value-of select="$type"/> p<xsl:value-of select="$name"/>) {
908 <xsl:choose>
909 <xsl:when test="subsets">
910 super.set<xsl:value-of select="$name"/>(p<xsl:value-of select="$name"/>);
911 </xsl:when>
912 <xsl:otherwise>
913 this.<xsl:value-of select="name"/> = p<xsl:value-of select="$name"/>;
914 </xsl:otherwise>
915 </xsl:choose>
916 }
917 </xsl:template>
918
919
920
921
922 <xsl:template match="reference" mode="setProperty">
923 <xsl:variable name="ctype" select="key('element',datatype/@xmiidref)"/>
924
925 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
926 <xsl:variable name="name">
927 <xsl:call-template name="upperFirst">
928 <xsl:with-param name="val" select="name"/>
929 </xsl:call-template>
930 </xsl:variable>
931
932 if ("<xsl:value-of select="name"/>".equals(propertyName)) {
933 set<xsl:value-of select="$name"/>((<xsl:value-of select="$type"/>)value);
934 return true;
935 }
936 if ("<xsl:value-of select="name"/>Ref".equals(propertyName)) {
937 // sets JAXB Reference Field
938 this.p_<xsl:value-of select="name"/> = newReference((MetadataObject)value);
939 return true;
940 }
941 </xsl:template>
942
943
944
945
946 <xsl:template match="literal" >
947 /**
948 * Value <xsl:value-of select="value"/> :
949 *
950 * <xsl:apply-templates select="." mode="desc" />
951 */
952 <xsl:variable name="up">
953 <xsl:call-template name="constant">
954 <xsl:with-param name="text" select="value"/>
955 </xsl:call-template>
956 </xsl:variable>
957
958 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
959 <xsl:value-of select="$up"/>("<xsl:value-of select="value"/>")
960 <xsl:choose>
961 <xsl:when test="position() != last()"><xsl:text>,</xsl:text></xsl:when>
962 <xsl:otherwise><xsl:text>;</xsl:text></xsl:otherwise>
963 </xsl:choose>
964 &cr;
965 </xsl:template>
966
967
968
969
970 <xsl:template match="attribute|reference|collection" mode="tostring">
971 <xsl:variable name="name">
972 <xsl:call-template name="upperFirst">
973 <xsl:with-param name="val" select="name"/>
974 </xsl:call-template>
975 </xsl:variable>
976 sb.append("<xsl:value-of select="name"/>=");
977 if (get<xsl:value-of select="$name"/>() != null) {
978 MetadataElement.deepToString(sb, isDeep, ids, get<xsl:value-of select="$name"/>());
979 }
980 <xsl:if test="position() != last()">sb.append(", ");</xsl:if>
981 </xsl:template>
982
983
984
985
986 <xsl:template match="attribute|reference|collection" mode="getProperty">
987 <xsl:variable name="name">
988 <xsl:call-template name="upperFirst">
989 <xsl:with-param name="val" select="name"/>
990 </xsl:call-template>
991 </xsl:variable>
992 if ("<xsl:value-of select="name"/>".equals(propertyName)) {
993 return get<xsl:value-of select="$name"/>();
994 }
995 </xsl:template>
996
997
998
999
1000 <xsl:template match="*" mode="desc">
1001 <xsl:choose>
1002 <xsl:when test="count(description) > 0"><xsl:value-of select="description" disable-output-escaping="yes"/></xsl:when>
1003 <xsl:otherwise>TODO : Missing description : please, update your UML model asap.</xsl:otherwise>
1004 </xsl:choose>
1005 </xsl:template>
1006
1007
1008
1009
1010 <!-- specific documents -->
1011
1012 <!-- ModelVersion.java -->
1013 <xsl:template match="model" mode="modelVersion">
1014 <xsl:variable name="file" select="concat('src/', $root_package_dir,'/','ModelVersion.java')"/>
1015 <!-- open file for this class -->
1016 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
1017 <xsl:result-document href="{$file}">
1018 package <xsl:value-of select="$root_package"/>;
1019
1020 /**
1021 * Version class for <xsl:value-of select="name"/> :
1022 *
1023 * <xsl:apply-templates select="." mode="desc" />
1024 *
1025 * @author generated by UML2 Generator tool (UML->XMI->XSLT->java code)
1026 */
1027 public final class ModelVersion {
1028
1029 /** last modification date of the UML model */
1030 public final static long LAST_MODIFICATION_DATE = <xsl:value-of select="$lastModified"/>l;
1031
1032 private ModelVersion() {
1033 // forbidden constructor
1034 }
1035
1036 }
1037 </xsl:result-document>
1038 </xsl:template>
1039
1040
1041
1042
1043 <!-- package.html -->
1044 <xsl:template match="package" mode="packageDesc">
1045 <xsl:param name="dir"/>
1046 <xsl:variable name="file" select="concat('src/',$dir,'/package.html')"/>
1047 <!-- open file for this class -->
1048 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
1049 <xsl:result-document href="{$file}" format="packageInfo">
1050 <html>
1051 <head>
1052 <title>Package Information</title>
1053 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1054 </head>
1055 <body>&cr;
1056 <xsl:apply-templates select="." mode="desc" />
1057 </body>
1058 </html>
1059 </xsl:result-document>
1060 </xsl:template>
1061
1062
1063
1064
1065
1066
1067
1068
1069 <xsl:template name="QualifiedJavaType">
1070 <xsl:param name="type"/>
1071 <!-- <xsl:param name="xmiid"/>
1072 <xsl:variable name="type" select="key('element',$xmiid)"/>
1073 <xsl:message>QualifiedJavaType: XMIID = <xsl:value-of select="$xmiid"/></xsl:message>
1074 -->
1075 <xsl:choose>
1076 <xsl:when test="name($type) = 'primitiveType'">
1077 <xsl:choose>
1078 <xsl:when test="$type/name = 'boolean'">Boolean</xsl:when>
1079 <xsl:when test="$type/name = 'short'">Short</xsl:when>
1080 <xsl:when test="$type/name = 'integer'">Integer</xsl:when>
1081 <xsl:when test="$type/name = 'long'">Long</xsl:when>
1082 <xsl:when test="$type/name = 'float'">Float</xsl:when>
1083 <xsl:when test="$type/name = 'double'">Double</xsl:when>
1084 <xsl:when test="$type/name = 'datetime'">Date</xsl:when>
1085 <xsl:when test="$type/name = 'string'">java.lang.String</xsl:when>
1086 <xsl:otherwise>java.lang.String</xsl:otherwise>
1087 </xsl:choose>
1088 </xsl:when>
1089 <xsl:otherwise>
1090 <xsl:variable name="val">
1091 <xsl:call-template name="upperFirst">
1092 <xsl:with-param name="val" select="$type/name"/>
1093 </xsl:call-template>
1094 </xsl:variable>
1095 <xsl:variable name="path">
1096 <xsl:call-template name="package-path">
1097 <xsl:with-param name="packageid"><xsl:value-of select="$type/../@xmiid"/></xsl:with-param>
1098 <xsl:with-param name="delimiter">.</xsl:with-param>
1099 </xsl:call-template>
1100 </xsl:variable>
1101 <xsl:if test="$root_package"><xsl:value-of select="concat($root_package,'.')"/></xsl:if><xsl:value-of select="$path"/>.<xsl:value-of select="$val"/>
1102 </xsl:otherwise>
1103 </xsl:choose>
1104 </xsl:template>
1105
1106
1107
1108
1109 </xsl:stylesheet>

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