source: mauRepo/NewmoonJSP/src/main/webapp/WEB-INF/rules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/modules/module-xproc-functions.xq @ 7841

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/NewmoonJSP/src/main/webapp/WEB-INF/rules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/modules/module-xproc-functions.xq@7841
Revision 7841, 9.0 KB checked in by mnagni, 10 years ago (diff)
Line 
1(: Library module for xmi processing functions :)
2
3module namespace mod-xp = "urn:local-module:ISO19136-V3.2-AnxE_XMI-V1.1:xmi-proc";
4
5declare namespace UML = "omg.org/UML1.3";
6
7declare function mod-xp:get-target-app-schema($doc-root as node()?)
8{
9        ($doc-root//UML:Package[UML:ModelElement.taggedValue/UML:TaggedValue/@tag eq "stereotype" and UML:ModelElement.taggedValue/UML:TaggedValue/@value = ("Application Schema", "applicationSchema") and empty(ancestor::UML:Package)])[1]
10};
11
12(:
13        #Author: Pavel Golodoniuc
14
15        Return duplicated values within sequence.
16:)
17declare function mod-xp:get-duplicates($seq as item()*) as item()*
18{
19        for $el at $i in $seq
20        order by $el
21        return if (exists($seq[position() gt $i and . eq $el]) and empty($seq[position() lt $i and . eq $el])) then $el else ()
22};
23
24declare function mod-xp:get-class-name-by-type($doc-root as node(), $type as xs:string?) as node()?
25{
26        ($doc-root//UML:Class[@xmi.id eq $type] | $doc-root/XMI/XMI.extensions/EAStub[@xmi.id eq $type])
27};
28
29(:
30        #Date:          2008-12-02
31        #Author:        Pavel Golodoniuc
32
33        Extract value part from XMI tagged value.
34        Syntax:
35                <value-part>[#NOTES#<notes-part>]
36:)
37declare function mod-xp:extract-value-from-tagval($value as xs:string?) as xs:string?
38{
39        replace(normalize-space($value), "([^#]+)(&#35;.*)?", "$1")
40};
41
42(:
43        #Date:          2008-12-02
44        #Author:        Pavel Golodoniuc
45        #Ref:           http://www.ietf.org/rfc/rfc3986.txt
46
47        Validate URI generic syntax.
48:)
49declare function mod-xp:is-uri-valid($uri as xs:string?) as xs:boolean
50{
51        matches($uri, "^(([^:/?&#35;]+):)(//([^/?&#35;]+\.[^/?&#35;]+))([^?&#35;]*)(\?([^&#35;]*))?(&#35;(.*))?$")
52};
53
54(:
55        #Date:          2008-12-02
56        #Author:        Pavel Golodoniuc
57        #Ref:           http://www.ietf.org/rfc/rfc2141.txt
58
59        Validate URN syntax.
60:)
61declare function mod-xp:is-urn-valid($urn as xs:string?) as xs:boolean
62{
63        matches($urn, "^urn:([A-Za-z0-9]([A-Za-z0-9\-]){1,31}):([A-Za-z0-9\.:=_\-]|(%[A-Fa-f0-9]{2}))+$")
64};
65
66(:
67        #Date:          2008-12-02
68        #Author:        Pavel Golodoniuc
69        #Ref:           http://books.xmlschemata.org/relaxng/ch19-77215.html
70
71        Validate that input value is castable to xsd:NCName datatype.
72:)
73declare function mod-xp:is-xsd-ncname-valid($ncname as xs:string?) as xs:boolean
74{
75        matches($ncname, "^[\i-[:]][\c-[:]]*$")
76};
77
78(:
79        #Date:          2008-12-02
80        #Author:        Pavel Golodoniuc
81
82        Validate that input value is valid inlineOrByReference tag.
83:)
84declare function mod-xp:is-inlineOrByReference-tag-valid($value as xs:string?) as xs:boolean
85{
86        $value = ("", "inline", "byReference", "inlineOrByReference")
87};
88
89(:
90        #Date:          2008-12-03
91        #Author:        Pavel Golodoniuc
92
93        Validate that input value is valid xsdDocument tag.
94:)
95declare function mod-xp:is-xsdDocument-tag-valid($value as xs:string?) as xs:boolean
96{
97        matches($value, "^[^/\\]*\.xsd?$")
98};
99
100(:
101        #Date:          2008-12-02
102        #Author:        Pavel Golodoniuc
103
104        Validate that input value is castable to xs:boolean datatype.
105:)
106declare function mod-xp:is-boolean($value as xs:string?) as xs:boolean
107{
108        matches($value, "^(true|false)$", "i")
109};
110
111(:
112        #Date:          2008-12-02
113        #Author:        Pavel Golodoniuc
114
115        Validate that input value is castable to xs:integer datatype.
116:)
117declare function mod-xp:is-integer($value as xs:string?) as xs:boolean
118{
119        matches($value, "^(\-|\+)?[0-9]+$")
120};
121(:
122        #Date:          2008-12-02
123        #Author:        Pavel Golodoniuc
124
125        Validate that input value is castable to xs:integer datatype and is positive.
126:)
127declare function mod-xp:is-integer-positive($value as xs:string?) as xs:boolean
128{
129        matches($value, "^[0-9]+$")
130};
131
132(:
133        #Date:          2008-12-02
134        #Author:        Pavel Golodoniuc
135
136        Retrieve tagged value owner element in verbal form.
137:)
138declare function mod-xp:get-tag-owner-verbal($doc-root as node()?, $tag as node()) as xs:string
139{
140        if ($tag/@modelElement) then
141        (
142                (: Linked tagged value :)
143                let $owner := $doc-root//*[@xmi.id eq $tag/@modelElement],
144                        $ret := (
145                                if (name($owner) eq "EAStub") then
146                                        concat("external ", $owner/@UMLType, " &quot;", $owner/@name, "&quot;")
147                                else if (name($owner) = ("UML:Model", "UML:Package", "UML:Class", "UML:ClassifierRole")) then
148                                        concat(local-name($owner), " &quot;", $owner/@name, "&quot;")
149                                else if (name($owner) eq "UML:Dependency") then
150                                        concat("Dependency between ", lower-case($owner//UML:TaggedValue[@tag eq "ea_sourceType"]/@value), " &quot;", $owner//UML:TaggedValue[@tag eq "ea_sourceName"]/@value, "&quot; and ", lower-case($owner//UML:TaggedValue[@tag eq "ea_targetType"]/@value), " &quot;", $owner//UML:TaggedValue[@tag eq "ea_targetName"]/@value, "&quot;")
151                                else if (name($owner) = ("UML:Association", "UML:Generalization")) then
152                                        concat(local-name($owner), " between ", lower-case($owner/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceType"]/@value), " &quot;", $owner/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceName"]/@value, "&quot; and ", lower-case($owner/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetType"]/@value), " &quot;", $owner/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetName"]/@value, "&quot;")
153                                else
154                                        concat(name($owner), " (xmi.id=&quot;", $owner/@xmi.id, "&quot;)")
155                        )
156                return if (exists($ret)) then concat("owned by ", $ret) else ""
157        )
158        else
159        (
160                (: Embedded tagged value :)
161                let
162                        $owner := mod-xp:get-tag-parent-node($tag),
163                        $ret := (
164                                if (name($owner) = ("UML:Model", "UML:Package", "UML:Class", "UML:ClassifierRole")) then
165                                        concat(local-name($owner), " &quot;", $owner/@name, "&quot;")
166                                else if (name($owner) eq "UML:Dependency") then
167                                        concat("Dependency between ", lower-case($owner//UML:TaggedValue[@tag eq "ea_sourceType"]/@value), " &quot;", $owner//UML:TaggedValue[@tag eq "ea_sourceName"]/@value, "&quot; and ", lower-case($owner//UML:TaggedValue[@tag eq "ea_targetType"]/@value), " &quot;", $owner//UML:TaggedValue[@tag eq "ea_targetName"]/@value, "&quot;")
168                                else if (name($owner) eq "UML:Attribute") then
169                                        concat("Attribute &quot;", $owner/@name, "&quot; of class &quot;", $owner/../../@name, "&quot;")
170                                else if (name($owner) = ("UML:Association", "UML:Generalization")) then
171                                        concat(local-name($owner), " between ", lower-case($owner/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceType"]/@value), " &quot;", $owner/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceName"]/@value, "&quot; and ", lower-case($owner/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetType"]/@value), " &quot;", $owner/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetName"]/@value, "&quot;")
172                                else if (name($owner) eq "UML:AssociationEnd") then
173                                        concat("one end of the Association between ", lower-case($owner/../../UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceType"]/@value), " &quot;", $owner/../../UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceName"]/@value, "&quot; and ", lower-case($owner/../../UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetType"]/@value), " &quot;", $owner/../../UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetName"]/@value, "&quot;")
174                                else if (name($owner) eq "XMI") then
175                                        "XMI model"
176                                else
177                                        concat(name($owner), " (xmi.id=&quot;", $owner/@xmi.id, "&quot;)")
178                        )
179                return if (exists($ret)) then concat("owned by ", $ret) else ""
180        )
181};
182
183(:
184        #Date:          2008-12-02
185        #Author:        Pavel Golodoniuc
186
187        Get element's nearest ancestor of the specific type.
188:)
189declare function mod-xp:get-tag-parent-node($node as node()) as node()
190{
191        let $parent := $node/parent::*
192        return
193                if (name($parent) = ("XMI", "UML:Model", "UML:Package", "UML:Class", "UML:ClassifierRole", "UML:Dependency", "UML:Attribute", "UML:Association", "UML:AssociationEnd", "UML:Generalization", "UML:Diagram")) then
194                        $parent
195                else
196                        mod-xp:get-tag-parent-node($parent)
197};
198
199(:
200        #Date:          2008-12-04
201        #Author:        Pavel Golodoniuc
202
203        Return verbal representation of an association.
204:)
205declare function mod-xp:verbose-association($assoc as node()?) as xs:string
206{
207        concat("association between ", lower-case($assoc/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceType"]/@value), " &quot;", $assoc/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceName"]/@value, "&quot; and ", lower-case($assoc/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetType"]/@value), " &quot;", $assoc/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetName"]/@value, "&quot;")
208};
209
210(:
211        #Date:          2009-01-23
212        #Author:        Pavel Golodoniuc
213
214        Return verbal representation of an generalization UML element.
215:)
216declare function mod-xp:verbose-generalization($el as node()?) as xs:string
217{
218        concat("generalization between ", lower-case($el/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceType"]/@value), " &quot;", $el/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_sourceName"]/@value, "&quot; and ", lower-case($el/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetType"]/@value), " &quot;", $el/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq "ea_targetName"]/@value, "&quot;")
219};
Note: See TracBrowser for help on using the repository browser.