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

Contents of /trunk/projects/theory/snapdm/res/jaxb.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/octet-stream
File size: 4590 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 <!--
10 This XSLT is used by intermediate2java.xsl to generate JAXB annotations and JAXB specific java code.
11
12 Java 1.5+ is required by JAXB 2.1.
13 -->
14
15 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
16 xmlns:exsl="http://exslt.org/common"
17 extension-element-prefixes="exsl">
18
19 <xsl:import href="common.xsl"/>
20 <xsl:import href="common-xsd.xsl"/>
21
22 <xsl:param name="targetnamespace_root"/>
23
24 <xsl:key name="element" match="*//*" use="@xmiid"/>
25
26
27
28
29 <xsl:template match="objectType|dataType" mode="JAXBAnnotation">
30 <xsl:variable name="namespace">
31 <xsl:call-template name="namespace-for-package">
32 <xsl:with-param name="packageid" select="..[name()='package']/@xmiid"/>
33 </xsl:call-template>
34 </xsl:variable>
35 <xsl:variable name="isContained">
36 <xsl:apply-templates select="." mode="testrootelements">
37 <xsl:with-param name="count" select="'0'"/>
38 </xsl:apply-templates>
39 </xsl:variable>
40 @XmlAccessorType( XmlAccessType.NONE )
41 @XmlType( name = "<xsl:value-of select="name"/>", namespace = "<xsl:value-of select="$namespace"/>")
42 <xsl:choose>
43 <xsl:when test="number($isContained) = 0 and not(@abstract = 'true')">
44 @XmlRootElement( name = "a<xsl:value-of select="name"/>", namespace = "<xsl:value-of select="concat($targetnamespace_root,'/',/model/name)"/>")
45 </xsl:when>
46 <xsl:otherwise>
47 <!-- always produce a JAXB annotation to be able to marshall fragments -->
48 @XmlRootElement( name = "<xsl:value-of select="name"/>", namespace = "<xsl:value-of select="concat($targetnamespace_root,'/',/model/name)"/>")
49 </xsl:otherwise>
50 </xsl:choose>
51 </xsl:template>
52
53
54
55
56 <xsl:template match="enumeration" mode="JAXBAnnotation">
57 <xsl:variable name="namespace">
58 <xsl:call-template name="namespace-for-package">
59 <xsl:with-param name="packageid" select="..[name()='package']/@xmiid"/>
60 </xsl:call-template>
61 </xsl:variable>
62 @XmlType( name = "<xsl:value-of select="name"/>", namespace = "<xsl:value-of select="$namespace"/>")
63 @XmlEnum
64 </xsl:template>
65
66
67
68
69 <!-- temlate attribute : adds JAXB annotations for primitive types, data types & enumerations -->
70 <xsl:template match="attribute" mode="JAXBAnnotation">
71 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
72 @XmlElement( name = "<xsl:value-of select="name"/>", required = <xsl:apply-templates select="." mode="required"/>, type = <xsl:value-of select="$type"/>.class)
73 </xsl:template>
74
75
76
77
78 <!-- reference can not be resolved directly by JAXB -->
79 <xsl:template match="reference" mode="JAXBAnnotation">
80 @XmlTransient
81 </xsl:template>
82
83
84
85
86 <xsl:template match="reference" mode="JAXBAnnotation_reference">
87 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
88 @XmlElement( name = "<xsl:value-of select="name"/>", required = <xsl:apply-templates select="." mode="required"/>, type = Reference.class)
89 </xsl:template>
90
91
92
93
94 <xsl:template match="collection" mode="JAXBAnnotation">
95 <xsl:variable name="type"><xsl:call-template name="JavaType"><xsl:with-param name="xmiid" select="datatype/@xmiidref"/></xsl:call-template></xsl:variable>
96 @XmlElement( name = "<xsl:value-of select="name"/>", required = <xsl:apply-templates select="." mode="required"/>, type = <xsl:value-of select="$type"/>.class)
97 </xsl:template>
98
99
100
101
102 <xsl:template match="literal" mode="JAXBAnnotation">
103 @XmlEnumValue("<xsl:value-of select="value"/>")
104 </xsl:template>
105
106
107
108
109 <xsl:template match="attribute|reference|collection" mode="required">
110 <xsl:choose>
111 <xsl:when test="starts-with(multiplicity, '0')">false</xsl:when>
112 <xsl:otherwise>true</xsl:otherwise>
113 </xsl:choose>
114 </xsl:template>
115
116
117
118
119 <xsl:template match="package" mode="jaxb.index">
120 <xsl:param name="dir"/>
121 <xsl:variable name="file" select="concat('src/', $dir, '/jaxb.index')"/>
122 <!-- open file for this class -->
123 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
124
125 <xsl:result-document href="{$file}">
126 <xsl:for-each select="objectType">
127 <xsl:value-of select="name"/>&cr;
128 </xsl:for-each>
129 </xsl:result-document>
130 </xsl:template>
131
132
133 </xsl:stylesheet>

Properties

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

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