/[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 677 - (show annotations)
Wed Jul 9 21:49:27 2008 UTC (12 years, 4 months ago) by bourges.laurent
File MIME type: application/xml
File size: 42385 byte(s)
- fixed toString [ ... ]
- add XmlRootElement for all entities
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, so call EntityManager.persist(parent) first !
449 *
450 * @param pContainer the parent container CAN NOT BE NULL, so call EntityManager.persist(parent) first !
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 public 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 * The Parent Container CAN NOT BE NULL, so call EntityManager.persist(parent) first !
487 * TODO decide on whether the Id must have been set.
488 * Should (it?) be possible to deal with classes outside of JPA context?
489 * @param pContainer the parent container CAN NOT BE NULL, so call EntityManager.persist(parent) first !
490 *
491 * @throws IllegalStateException if pContainer == null or pContainer.getId() is undefined !
492 */
493 protected void setContainer(final <xsl:value-of select="$type"/> pContainer) {
494 // TODO : its primary key can be null ? : call em.persist(container) first !
495 if (pContainer == null) /* || pContainer.getId() == null) */
496 {
497 throw new IllegalStateException("The parent container can not be null !");
498 }
499 setContainerField(pContainer);
500 pContainer.add<xsl:value-of select="$collection"/>(this);
501 }
502 </xsl:if>
503
504 <xsl:if test="$hasExtends = 0">
505 <xsl:if test="name() = 'objectType'">
506 /**
507 * Returns Jpa version for optimistic locking
508 * @return jpa version number
509 */
510 protected int getJpaVersion() {
511 return this.jpaVersion;
512 }
513 <xsl:if test="$hasChild = 1">
514 /**
515 * Returns Class type (discriminator value) in inheritance hierarchy
516 * @return class type
517 */
518 protected String getClassType() {
519 return this.classType;
520 }
521 </xsl:if>
522 </xsl:if>
523 </xsl:if>
524
525 <xsl:apply-templates select="." mode="hashcode_equals"/>
526
527 /**
528 * Returns the property value given the property name.<br/>
529 * Can be any property (internal, attribute, reference, collection) and all type must be supported (dataType,
530 * objectType, enumeration)
531 *
532 * @param propertyName name of the property (like in UML model)
533 *
534 * @return property value or null if unknown or not defined
535 */
536 @Override
537 public Object getProperty(final String propertyName) {
538 // first : checks if propertyName is null or empty :
539 if (propertyName == null) {
540 return null;
541 }
542 // second : search in parent classes (maybe null) :
543 Object res = super.getProperty(propertyName);
544
545 <xsl:if test="container">
546 if (PROPERTY_CONTAINER.equals(propertyName)) {
547 return getContainer();
548 }
549 </xsl:if>
550
551 <!-- TODO collection support ? -->
552 <xsl:apply-templates select="attribute|reference|collection" mode="getProperty" />
553
554 return res;
555 }
556
557 /**
558 * Sets the property value to the given property name. <br/>
559 * Can be any property (internal, attribute, reference, collection) and all type must be supported (dataType,
560 * objectType, enumeration)
561 *
562 * @param propertyName name of the property (like in UML model)
563 *
564 * @param value to be set
565 *
566 * @return true if property has been set
567 */
568 @Override
569 public boolean setProperty(final String propertyName, final Object value) {
570 // first : checks if propertyName is null or empty :
571 if (propertyName == null) {
572 return false;
573 }
574 // second : search in parent classes (maybe null) :
575 boolean res = super.setProperty(propertyName, value);
576
577 if (!res) {
578 <xsl:if test="container">
579 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="container/@xmiidref"/></xsl:call-template></xsl:variable>
580 <xsl:variable name="collection">
581 <xsl:call-template name="upperFirst">
582 <xsl:with-param name="val" select="container/@relation"/>
583 </xsl:call-template>
584 </xsl:variable>
585 if (PROPERTY_CONTAINER.equals(propertyName)) {
586 setContainerField((<xsl:value-of select="$type"/>) value);
587 return true;
588 }
589 </xsl:if>
590
591 <!-- TODO collection support ? -->
592 <xsl:apply-templates select="attribute|reference" mode="setProperty" />
593 }
594 return res;
595 }
596
597 /**
598 * Puts the string representation in the given string buffer : &lt;br&gt;
599 * "Type =[class name @ hashcode] : { field name = field value , ...}"
600 *
601 * @param sb given string buffer to fill
602 * @param isDeep true means to call deepToString(sb, true, ids) for all attributes / references / collections which are
603 * MetadataElement implementations
604 * @param ids identity map to avoid cyclic loops
605 *
606 * @return stringbuffer the given string buffer filled with the string representation
607 */
608 <xsl:if test="$hasExtends = 1">
609 @Override
610 </xsl:if>
611 protected StringBuilder deepToString(final StringBuilder sb, final boolean isDeep, final Map&lt;MetadataElement, Object&gt; ids) {
612 <xsl:if test="$hasExtends = 1">
613 super.deepToString(sb, isDeep, ids);
614 </xsl:if>
615
616 sb.append("\n[ <xsl:value-of select="$className"/>");
617 sb.append("={");
618
619 <xsl:if test="container">
620 sb.append("container=");
621 if (getContainer() != null) {
622 // short toString :
623 MetadataElement.deepToString(sb, false, ids, getContainer());
624 }
625 sb.append(" | ");
626 </xsl:if>
627
628 <xsl:apply-templates select="attribute|reference|collection" mode="tostring" />
629
630 return sb.append("} ]");
631 }
632
633 }
634 </xsl:template>
635
636
637
638
639 <xsl:template name="enumeration">
640 <xsl:param name="dir"/>
641 <xsl:param name="path"/>
642
643 <xsl:variable name="file" select="concat('src/', $dir, '/', name, '.java')"/>
644
645 <!-- open file for this class -->
646 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
647
648 <xsl:result-document href="{$file}">
649
650 package <xsl:value-of select="$path"/>;
651
652 <!-- imports -->
653 import javax.persistence.*;
654 import javax.xml.bind.annotation.*;
655
656 /**
657 * UML Enumeration <xsl:value-of select="name"/> :
658 *
659 * <xsl:apply-templates select="." mode="desc" />
660 *
661 * @author generated by UML2 Generator tool (UML->XMI->XSLT->java code)
662 */
663 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
664 public enum <xsl:value-of select="name"/>&bl;{
665
666 <xsl:apply-templates select="literal" />
667
668 /** string representation */
669 private final String value;
670
671 /**
672 * Creates a new <xsl:value-of select="name"/> Enumeration Literal
673 *
674 * @param v string representation
675 */
676 <xsl:value-of select="name"/>(final String v) {
677 value = v;
678 }
679
680 /**
681 * Returns string representation
682 * @return string representation
683 */
684 public final String value() {
685 return this.value;
686 }
687
688 /**
689 * Returns <xsl:value-of select="name"/> Enumeration Literal corresponding to the given string representation
690 *
691 * @param v string representation
692 *
693 * @return value <xsl:value-of select="name"/> Enumeration Literal
694 *
695 * @throws IllegalArgumentException if string representation not found
696 */
697 public final static <xsl:value-of select="name"/> fromValue(final String v) {
698 for (<xsl:value-of select="name"/> c : <xsl:value-of select="name"/>.values()) {
699 if (c.value.equals(v)) {
700 return c;
701 }
702 }
703 throw new IllegalArgumentException("<xsl:value-of select="name"/>.fromValue : unknown value : " + v);
704 }
705
706 }
707 </xsl:result-document>
708 </xsl:template>
709
710
711
712
713
714
715
716
717 <xsl:template match="attribute" mode="declare">
718 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
719 /**
720 * Attribute <xsl:value-of select="name"/> :
721 * <xsl:apply-templates select="." mode="desc" />
722 * (
723 * Multiplicity : <xsl:value-of select="multiplicity"/>
724 <xsl:if test="constraints/maxLength">
725 * , MaxLength : <xsl:value-of select="constraints/maxLength"/>
726 </xsl:if>
727 * )
728 */
729 <xsl:apply-templates select="." mode="JPAAnnotation"/>
730 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
731 private <xsl:value-of select="$type"/>&bl;<xsl:value-of select="name"/>;
732 </xsl:template>
733
734
735
736
737 <xsl:template match="attribute" mode="getset">
738 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
739 <xsl:variable name="name">
740 <xsl:call-template name="upperFirst">
741 <xsl:with-param name="val" select="name"/>
742 </xsl:call-template>
743 </xsl:variable>
744 /**
745 * Returns <xsl:value-of select="name"/> Attribute
746 * @return <xsl:value-of select="name"/> Attribute
747 */
748 public <xsl:value-of select="$type"/>&bl;get<xsl:value-of select="$name"/>() {
749 return this.<xsl:value-of select="name"/>;
750 }
751 /**
752 * Defines <xsl:value-of select="name"/> Attribute
753 * @param p<xsl:value-of select="$name"/> value to set
754 */
755 public void set<xsl:value-of select="$name"/>(final <xsl:value-of select="$type"/> p<xsl:value-of select="$name"/>) {
756 this.<xsl:value-of select="name"/> = p<xsl:value-of select="$name"/>;
757 }
758 </xsl:template>
759
760
761
762
763 <xsl:template match="attribute" mode="setProperty">
764 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
765 <xsl:variable name="name">
766 <xsl:call-template name="upperFirst">
767 <xsl:with-param name="val" select="name"/>
768 </xsl:call-template>
769 </xsl:variable>
770 if ("<xsl:value-of select="name"/>".equals(propertyName)) {
771 set<xsl:value-of select="$name"/>((<xsl:value-of select="$type"/>)value);
772 return true;
773 }
774 </xsl:template>
775
776
777
778
779 <xsl:template match="collection" mode="declare">
780 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
781 /**
782 * Collection <xsl:value-of select="name"/> :
783 * <xsl:apply-templates select="." mode="desc" />
784 * (
785 * Multiplicity : <xsl:value-of select="multiplicity"/>
786 * )
787 */
788 <xsl:apply-templates select="." mode="JPAAnnotation"/>
789 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
790 private List&lt;<xsl:value-of select="$type"/>&gt;&bl;<xsl:value-of select="name"/> = null;
791 </xsl:template>
792
793
794
795
796 <xsl:template match="collection" mode="getset">
797 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
798 <xsl:variable name="name">
799 <xsl:call-template name="upperFirst">
800 <xsl:with-param name="val" select="name"/>
801 </xsl:call-template>
802 </xsl:variable>
803 /**
804 * Returns <xsl:value-of select="name"/> Collection
805 * @return <xsl:value-of select="name"/> Collection
806 */
807 public List&lt;<xsl:value-of select="$type"/>&gt;&bl;get<xsl:value-of select="$name"/>() {
808 return this.<xsl:value-of select="name"/>;
809 }
810 /**
811 * Defines <xsl:value-of select="name"/> Collection
812 * @param p<xsl:value-of select="$name"/> collection to set
813 */
814 public void set<xsl:value-of select="$name"/>(final List&lt;<xsl:value-of select="$type"/>&gt; p<xsl:value-of select="$name"/>) {
815 this.<xsl:value-of select="name"/> = p<xsl:value-of select="$name"/>;
816 }
817 /**
818 * Add a <xsl:value-of select="$type"/> to the collection
819 * @param p<xsl:value-of select="$type"/>&bl;<xsl:value-of select="$type"/> to add
820 */
821 public void add<xsl:value-of select="$name"/>(final <xsl:value-of select="$type"/> p<xsl:value-of select="$type"/>) {
822 if(this.<xsl:value-of select="name"/> == null)
823 this.<xsl:value-of select="name"/> = new ArrayList&lt;<xsl:value-of select="$type"/>&gt;();
824 this.<xsl:value-of select="name"/>.add(p<xsl:value-of select="$type"/>);
825 }
826 </xsl:template>
827
828
829
830
831 <xsl:template match="reference" mode="declare">
832 <xsl:if test="not(subsets)">
833 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
834 /**
835 * Reference <xsl:value-of select="name"/> :
836 * <xsl:apply-templates select="." mode="desc" />
837 * (
838 * Multiplicity : <xsl:value-of select="multiplicity"/>
839 * )
840 */
841 <xsl:apply-templates select="." mode="JPAAnnotation"/>
842 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
843 private <xsl:value-of select="$type"/>&bl;<xsl:value-of select="name"/> = null;
844 /**
845 * "lazy" version of the <xsl:value-of select="name"/> reference.
846 * Used by XML (un)marshallers to resolve possibly inderectly referenced resource <xsl:value-of select="$type"/>.
847 */
848 <xsl:apply-templates select="." mode="JPAAnnotation_reference"/>
849 <xsl:apply-templates select="." mode="JAXBAnnotation_reference"/>
850 protected Reference&bl;p_<xsl:value-of select="name"/> = null;
851 </xsl:if>
852 </xsl:template>
853
854
855
856
857 <xsl:template match="reference" mode="getset">
858 <xsl:variable name="ctype" select="key('element',datatype/@xmiidref)"/>
859
860 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
861 <xsl:variable name="name">
862 <xsl:call-template name="upperFirst">
863 <xsl:with-param name="val" select="name"/>
864 </xsl:call-template>
865 </xsl:variable>
866 /**
867 * Returns <xsl:value-of select="name"/> Reference<br/>
868 * If the <xsl:value-of select="name"/> variable is null but its "lazy" version
869 * p_<xsl:value-of select="name"/> is not, that lazy reference will be resolved to the actual object.
870 * @return <xsl:value-of select="name"/> Reference
871 */
872 public <xsl:value-of select="$type"/>&bl;get<xsl:value-of select="$name"/>() {
873 <xsl:choose>
874 <xsl:when test="subsets">
875 return (<xsl:value-of select="$type"/>)super.get<xsl:value-of select="$name"/>();
876 </xsl:when>
877 <xsl:otherwise>
878 if(<xsl:value-of select="name"/> == null
879 &amp;&amp; this.p_<xsl:value-of select="name"/> != null)
880 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);
881 return this.<xsl:value-of select="name"/>;
882 </xsl:otherwise>
883 </xsl:choose>
884 }
885 /**
886 * Defines <xsl:value-of select="name"/> Reference
887 * @param p<xsl:value-of select="$name"/> reference to set
888 */
889 public void set<xsl:value-of select="$name"/>(final <xsl:value-of select="$type"/> p<xsl:value-of select="$name"/>) {
890 <xsl:choose>
891 <xsl:when test="subsets">
892 super.set<xsl:value-of select="$name"/>(p<xsl:value-of select="$name"/>);
893 </xsl:when>
894 <xsl:otherwise>
895 this.<xsl:value-of select="name"/> = p<xsl:value-of select="$name"/>;
896 </xsl:otherwise>
897 </xsl:choose>
898 }
899 </xsl:template>
900
901
902
903
904 <xsl:template match="reference" mode="setProperty">
905 <xsl:variable name="ctype" select="key('element',datatype/@xmiidref)"/>
906
907 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
908 <xsl:variable name="name">
909 <xsl:call-template name="upperFirst">
910 <xsl:with-param name="val" select="name"/>
911 </xsl:call-template>
912 </xsl:variable>
913
914 if ("<xsl:value-of select="name"/>".equals(propertyName)) {
915 set<xsl:value-of select="$name"/>((<xsl:value-of select="$type"/>)value);
916 return true;
917 }
918 if ("<xsl:value-of select="name"/>Ref".equals(propertyName)) {
919 // sets JAXB Reference Field
920 this.p_<xsl:value-of select="name"/> = newReference((MetadataObject)value);
921 return true;
922 }
923 </xsl:template>
924
925
926
927
928 <xsl:template match="literal" >
929 /**
930 * Value <xsl:value-of select="value"/> :
931 *
932 * <xsl:apply-templates select="." mode="desc" />
933 */
934 <xsl:variable name="up">
935 <xsl:call-template name="constant">
936 <xsl:with-param name="text" select="value"/>
937 </xsl:call-template>
938 </xsl:variable>
939
940 <xsl:apply-templates select="." mode="JAXBAnnotation"/>
941 <xsl:value-of select="$up"/>("<xsl:value-of select="value"/>")
942 <xsl:choose>
943 <xsl:when test="position() != last()"><xsl:text>,</xsl:text></xsl:when>
944 <xsl:otherwise><xsl:text>;</xsl:text></xsl:otherwise>
945 </xsl:choose>
946 &cr;
947 </xsl:template>
948
949
950
951
952 <xsl:template match="attribute|reference|collection" mode="tostring">
953 <xsl:variable name="name">
954 <xsl:call-template name="upperFirst">
955 <xsl:with-param name="val" select="name"/>
956 </xsl:call-template>
957 </xsl:variable>
958 sb.append("<xsl:value-of select="name"/>=");
959 if (get<xsl:value-of select="$name"/>() != null) {
960 MetadataElement.deepToString(sb, isDeep, ids, get<xsl:value-of select="$name"/>());
961 }
962 <xsl:if test="position() != last()">sb.append(", ");</xsl:if>
963 </xsl:template>
964
965
966
967
968 <xsl:template match="attribute|reference|collection" mode="getProperty">
969 <xsl:variable name="name">
970 <xsl:call-template name="upperFirst">
971 <xsl:with-param name="val" select="name"/>
972 </xsl:call-template>
973 </xsl:variable>
974 if ("<xsl:value-of select="name"/>".equals(propertyName)) {
975 return get<xsl:value-of select="$name"/>();
976 }
977 </xsl:template>
978
979
980
981
982 <xsl:template match="*" mode="desc">
983 <xsl:choose>
984 <xsl:when test="count(description) > 0"><xsl:value-of select="description" disable-output-escaping="yes"/></xsl:when>
985 <xsl:otherwise>TODO : Missing description : please, update your UML model asap.</xsl:otherwise>
986 </xsl:choose>
987 </xsl:template>
988
989
990
991
992 <!-- specific documents -->
993
994 <!-- ModelVersion.java -->
995 <xsl:template match="model" mode="modelVersion">
996 <xsl:variable name="file" select="concat('src/', $root_package_dir,'/','ModelVersion.java')"/>
997 <!-- open file for this class -->
998 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
999 <xsl:result-document href="{$file}">
1000 package <xsl:value-of select="$root_package"/>;
1001
1002 /**
1003 * Version class for <xsl:value-of select="name"/> :
1004 *
1005 * <xsl:apply-templates select="." mode="desc" />
1006 *
1007 * @author generated by UML2 Generator tool (UML->XMI->XSLT->java code)
1008 */
1009 public final class ModelVersion {
1010
1011 /** last modification date of the UML model */
1012 public final static long LAST_MODIFICATION_DATE = <xsl:value-of select="$lastModified"/>l;
1013
1014 private ModelVersion() {
1015 // forbidden constructor
1016 }
1017
1018 }
1019 </xsl:result-document>
1020 </xsl:template>
1021
1022
1023
1024
1025 <!-- package.html -->
1026 <xsl:template match="package" mode="packageDesc">
1027 <xsl:param name="dir"/>
1028 <xsl:variable name="file" select="concat('src/',$dir,'/package.html')"/>
1029 <!-- open file for this class -->
1030 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
1031 <xsl:result-document href="{$file}" format="packageInfo">
1032 <html>
1033 <head>
1034 <title>Package Information</title>
1035 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1036 </head>
1037 <body>&cr;
1038 <xsl:apply-templates select="." mode="desc" />
1039 </body>
1040 </html>
1041 </xsl:result-document>
1042 </xsl:template>
1043
1044
1045
1046
1047
1048
1049
1050
1051 <xsl:template name="QualifiedJavaType">
1052 <xsl:param name="type"/>
1053 <!-- <xsl:param name="xmiid"/>
1054 <xsl:variable name="type" select="key('element',$xmiid)"/>
1055 <xsl:message>QualifiedJavaType: XMIID = <xsl:value-of select="$xmiid"/></xsl:message>
1056 -->
1057 <xsl:choose>
1058 <xsl:when test="name($type) = 'primitiveType'">
1059 <xsl:choose>
1060 <xsl:when test="$type/name = 'boolean'">Boolean</xsl:when>
1061 <xsl:when test="$type/name = 'short'">Short</xsl:when>
1062 <xsl:when test="$type/name = 'integer'">Integer</xsl:when>
1063 <xsl:when test="$type/name = 'long'">Long</xsl:when>
1064 <xsl:when test="$type/name = 'float'">Float</xsl:when>
1065 <xsl:when test="$type/name = 'double'">Double</xsl:when>
1066 <xsl:when test="$type/name = 'datetime'">Date</xsl:when>
1067 <xsl:when test="$type/name = 'string'">java.lang.String</xsl:when>
1068 <xsl:otherwise>java.lang.String</xsl:otherwise>
1069 </xsl:choose>
1070 </xsl:when>
1071 <xsl:otherwise>
1072 <xsl:variable name="val">
1073 <xsl:call-template name="upperFirst">
1074 <xsl:with-param name="val" select="$type/name"/>
1075 </xsl:call-template>
1076 </xsl:variable>
1077 <xsl:variable name="path">
1078 <xsl:call-template name="package-path">
1079 <xsl:with-param name="packageid"><xsl:value-of select="$type/../@xmiid"/></xsl:with-param>
1080 <xsl:with-param name="delimiter">.</xsl:with-param>
1081 </xsl:call-template>
1082 </xsl:variable>
1083 <xsl:if test="$root_package"><xsl:value-of select="concat($root_package,'.')"/></xsl:if><xsl:value-of select="$path"/>.<xsl:value-of select="$val"/>
1084 </xsl:otherwise>
1085 </xsl:choose>
1086 </xsl:template>
1087
1088
1089
1090
1091 </xsl:stylesheet>

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