-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruleset_su.txt
135 lines (134 loc) · 5.74 KB
/
ruleset_su.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?xml version="1.0" encoding="UTF-8"?>
<!--
Generated via
MagicDraw Template for Schematron without Schema-awareness (SchematronMD)
-->
#macro(runClass $class $parentClass)
## BEGIN BUSINESS LOGIC **
#set($relationList = $report.getRelationship($class))
## GET RELATIONSHIPS FROM BASE CLASSES, IF ANY **
##set($void = $array.addCollection($relationList, $report.getBaseClassAssociations($class)))
#set($xPathExprs = $array.createArray())
#set($forwardLookups = $array.createArray())
#set($childClasses = $array.createArray())
#foreach($rel in $relationList)
#set($clientClass = $report.getClientElement($rel))
#set($supplierClass = $report.getSupplierElement($rel))
#if($rel.humanType == 'Generalization')
## GET CHILD CLASSES FOR CLASS **
#if($rel.general == $class)
## CALL NOW, WILL ENSURE CHILDREN OUTPUT BEFORE PARENT
##runClass($rel.specific, $class)
#set($void = $childClasses.add($rel.specific))
#end
#end
## ONLY WANT ASSOCIATIONS **
#if($rel.humanType == 'Association')
## RESET FOR NEXT IERATION **
#set($clientRoleName = "")
#set($clientIsNav = false)
#set($supplierIsNav = false)
#set($clientAggregation = false)
#set($plural = false)
#set($selfRef = false)
## RUN BOTH SIDES, GATHERING THE DATA WE NEED **
#foreach($relEnd in $rel.memberEnd)
## START CLIENT SIDE CHECKS **
## IF CLIENT REL END ISN'T OWNED, IT ISN'T NAVIGABLE AND WE DON'T CARE ANYWAY **
#if($relEnd.owner == $clientClass)
#set($clientRoleName = $relEnd.name)
#if($relEnd.aggregation == "composite")#set($clientAggregation = true)#end
## CHECK IF WE NEED TO PLURALIZE ROLE NAME SUFFIXES **
#if($relEnd.upperValue.value == -1 || $relEnd.upperValue.value > 1)#set($plural = true)#end
#end
## END CLIENT SIDE **
## CHECK IF RELATIONSHIP IS SELF REFERENTIAL **
#if($supplierClass == $clientClass)#set($selfRef = true)#end
## CHECK IF WE HAVE A NAVIGABLE END FROM OTHER SIDE **
#if($clientClass != $class || $selfRef)#set($clientIsNav = true)#end
#if($supplierClass != $class || $selfRef)#set($supplierIsNav = true)#end
#end
## END RELS **
#if($plural)#set($suffix = "Ids")#else#set($suffix = "Id")#end
#set($refId = $clientRoleName + $suffix)
## LOGIC FOR REVERSE LOOKUP **
###if(!$clientAggregation && $clientIsNav)
###set($tempArray = $array.createArray())
###set($void = $tempArray.add("local-name() = '$refId' and .. instance of element(*, cdf:$clientClass.name)"))
###set($void = $tempArray.add($clientClass.name))
###set($void = $xPathExprs.add($tempArray))
###end
## LOGIC FOR FORWARD LOOKUP **
#if(!$clientAggregation && $supplierIsNav)
#set($tempArray = $array.createArray())
#set($void = $tempArray.add($refId))
#set($void = $tempArray.add($supplierClass.name))
#set($void = $tempArray.add($plural))
#set($void = $forwardLookups.add($tempArray))
#end
#end
#end
## ONLY OUTPUT WHEN WE HAVE AT LEAST ONE EXPR **
#if(!$xPathExprs.isEmpty() || !$forwardLookups.isEmpty())
<sch:rule mp:class="$class.name" #if($parentClass)mp:baseClass="$parentClass.name"#end>
###if(!$xPathExprs.isEmpty())
## <sch:assert test="count(idref(current()/@ObjectId)[#foreach($expr in $xPathExprs)($list.get($expr,0))#if(!$foreach.last) or #end#end]) > 0">$class.name (<xsl:value-of select="current()/@ObjectId" />) must have reference from #foreach($expr in $xPathExprs)$list.get($expr,1)#if(!$foreach.last), #end#end</sch:assert>
###end
#foreach($forwardLookup in $forwardLookups)
<sch:assert mp:source="$list.get($forwardLookup,0)" mp:sourceIsPlural="$list.get($forwardLookup,2)" mp:targetClass="$list.get($forwardLookup,1)">$list.get($forwardLookup, 0) (<sch:value-of select="cdf:$list.get($forwardLookup, 0)" />) must point to an element of type $list.get($forwardLookup, 1)</sch:assert>
#end
</sch:rule>
#end
#end
## END MACROS
#set($packages = $array.createArray())
#set($void = $array.addCollection($packages, $Package))
#set($void = $array.addCollection($packages, $SmartPackage))
#foreach ($package in $sorter.sort($packages, "qualifiedName"))
#set($majorVersion = $report.getStereotypePropertyString($package, "XML Schema", "major_version"))
#set($schemaFilename = $report.getStereotypePropertyString($package, "XML Schema", "schema_filename").replace("<MAJOR_VERSION>",$majorVersion))
#set($targetNamespace = $report.getStereotypePropertyString($package, "XML Schema", "targetNamespace").replace("<MAJOR_VERSION>",$majorVersion))
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2" xmlns:mp="http://mapping"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<sch:ns uri="$targetNamespace" prefix="cdf"/>
<sch:ns uri="http://www.w3.org/2001/XMLSchema-instance" prefix="xsi"/>
#set($qualifiedName = $package.qualifiedName)
#set ($classList = $map.createHashMap())
#foreach ($element in $report.getOwnedElementsIncludingAdditional($package, true))
#if ($element.elementType == "class")
## CHECK IF THERE IS A PARENT, FOR SORTING **
#set($relationList = $report.getRelationship($element))
#set ($hasParent = false)
#foreach($rel in $relationList)
#if($rel.humanType == 'Generalization')
#if($rel.general != $element)
#set ($hasParent = true)
#end
#end
#end
#if($hasParent)
## TODO CHILDREN ARE BROKEN, NEED TO SEE WHAT IS GOING ON, SUPRRESSING FOR NOW
#set ($void = $classList.put("0$element.name", $element))
#else
#set ($void = $classList.put($element.name, $element))
#end
#end
#end
#end
<sch:pattern>
#foreach ($class in $classList)
#if($report.isEmpty($class.generalization))
#runClass($class)
#end
#end
</sch:pattern>
##CREATE TWO PATTERN, ONE THAT RUNS SPECIFIC RULES, ONE THAT RUNS GENERAL RULES, THIS WILL BREAK FOR DEEP HIERARCHIES!!
<sch:pattern>
#foreach ($class in $classList)
#if(!$report.isEmpty($class.generalization))
## WE DON'T HAVE MULTIPLE INHERITANCE SO THIS ISN'T AN ISSUE
#runClass($class $class.generalization.get(0).general)
#end
#end
</sch:pattern>
</sch:schema>