Hide last authors
Alexander Schulz-Rosengarten 5.1 1 = KTM - KIELER Transformation Mapping =
2
Alexander Schulz-Rosengarten 6.1 3
4
Alexander Schulz-Rosengarten 7.1 5 === Topics ===
Alexander Schulz-Rosengarten 6.1 6
7
Alexander Schulz-Rosengarten 7.1 8
Alexander Schulz-Rosengarten 6.1 9 {{toc maxLevel="2" minLevel="2"/}}
10
11 This subproject provides a tracing mechanism for arbitary model-elements across multiple model transformations, based on EMF.
12
Alexander Schulz-Rosengarten 8.1 13 The main propose of KTM is to allow bidirectional information transfer between abstract models and their resultant transformed models.
Alexander Schulz-Rosengarten 6.1 14
15 ----
16
17 == Transformation Tree Model ==
18
19
20
21 To offer a mapping between model-elements during multiple transformations KTM introduces a model called TransformationTree to represent these relations.
22
23 It is based on an EMF-Metamodel.
24
Alexander Schulz-Rosengarten 7.1 25 [[image:attach:als-ktmt-metamodel.png]]
Alexander Schulz-Rosengarten 6.1 26
27 The structure of the model can be separated into two parts.
28
Alexander Schulz-Rosengarten 11.1 29 **First part** (upper half) is a tree of transformations. Each ModelWrapper-class is a representation of a model which is transformed. So ModelWrapper are nodes and ModelTransformations are edges. Thus the ModelWrapper representing the initial-source-model of all transformation is also the root of a TransformationTree-model.
Alexander Schulz-Rosengarten 6.1 30
Alexander Schulz-Rosengarten 11.1 31 **Second part** (lower half) is object-mapping. Instances of models contain EObjects as their elements, which are represented by EObjectWrapper-class in this metamodel. The EObjectWrapper of two models are connected with EObjectTransformations-class to express their origination relationship in corresponding model transformation.
Alexander Schulz-Rosengarten 6.1 32
33
34
35 An abstract example of an instance of this model:
36
Alexander Schulz-Rosengarten 7.1 37 [[image:attach:abstract_example_tree.png]]
Alexander Schulz-Rosengarten 6.1 38
39 ----
40
41 == Extensions ==
42
43 Two classes are provided by this project to extend functionality of the core model.
44
Alexander Schulz-Rosengarten 7.1 45 === TransformationMapping ([[JavaDoc>>attach:TransformationMapping.html]]) ===
Alexander Schulz-Rosengarten 6.1 46
Alexander Schulz-Rosengarten 8.1 47 The main propose of this class is generation of a object-mapping during transformation process.
Alexander Schulz-Rosengarten 6.1 48
Alexander Schulz-Rosengarten 8.1 49 Therefor it provides different functions for incremental registering of single parent-child-relations between EObjects.
Alexander Schulz-Rosengarten 6.1 50
51 Furthermore, the extension allows to extract the mapping and check completeness of mapped elements against content of transformed models.
52
Alexander Schulz-Rosengarten 7.1 53 === TransformationTreeExtensions ([[JavaDoc>>attach:TransformationTreeExtensions.html]]) ===
Alexander Schulz-Rosengarten 6.1 54
Alexander Schulz-Rosengarten 7.1 55 This class provides all functionalities to easily traverse and search in a TransformationTree.
Alexander Schulz-Rosengarten 6.1 56
57 Furthermore, it allows to modify trees by creating, deleting or appending new transformations and transformed models.
58
Alexander Schulz-Rosengarten 8.1 59 Additionally this extension provides functionality to extract a concrete mapping between two arbitary model intances from a TransformationTree.
60
Alexander Schulz-Rosengarten 6.1 61 ----
62
63 == Implementation Details ==
64
Alexander Schulz-Rosengarten 11.1 65 * All references to EObjects in EObjectWrapper are references to a copy of the original EObject. This allows to represent immutable mapping. To reidentify corresponding EObjects TransformationTreeExtensions provides search functions which will check for structural matching models.
66 * Models in TransformationTrees may be transient. This indicates that all references to EObjects in all Elements of the transient model are removed. Thus these models can't be source of a new appended transformation and can not be associated with it's original model. The main propose of this feature is to improve scalability of TransformationTrees by removing unnecessary references to internal model, but preserve traversing functionality of the object-mapping.
Alexander Schulz-Rosengarten 9.1 67 * Mappings can be incomplete causing resulting transfromation tree to be incomplete. A incomplete tree does not represent every object in a model with a corresponding Element. This may break some paths of element transformations, but allows to omit model-immanent objects like annotations from mapping. TranformationMapping extension provies a function to check completeness of mapping against its models.
Alexander Schulz-Rosengarten 6.1 68
Alexander Schulz-Rosengarten 7.1 69 ----
Alexander Schulz-Rosengarten 6.1 70
71 == Example ==
72
Alexander Schulz-Rosengarten 12.1 73 In this example we will perform some transformations on SCCharts.
74
75 The source chart is a ABO, the "Hello World" of SCCharts.
76
77 ABO is already a CoreSCChart, so we will perform normalization and a transformation to SCG.
78
Alexander Schulz-Rosengarten 10.1 79 === Creating Mapping during Transformation ===
80
Alexander Schulz-Rosengarten 12.1 81 In order to note every single element transformation of a model transformation, we use the TransformationMapping extension.
Alexander Schulz-Rosengarten 10.1 82
Alexander Schulz-Rosengarten 12.1 83 After each creation of new Objects for transformed model the mapping must be updated with it's origin information.
84
85 The codeblock blow show a snipped of SCChartCoreTransformation with additional mapping registration.
86
87
88
89 {{code title="transformTriggerEffect CodeSnipped" theme="Eclipse" linenumbers="true" language="java" firstline="1" collapse="true"}}
90 ...
91  @Inject
Alexander Schulz-Rosengarten 10.1 92 extension TransformationMapping
Alexander Schulz-Rosengarten 12.1 93
94 ...
95
Alexander Schulz-Rosengarten 11.1 96 // NEW - Mapping access delegation
Alexander Schulz-Rosengarten 10.1 97 def extractMapping() {
98 extractMappingData;
99 }
Alexander Schulz-Rosengarten 12.1 100
101 ...
102
Alexander Schulz-Rosengarten 10.1 103 //-------------------------------------------------------------------------
104 //-- S P L I T T R A N S I T I O N --
105 //-------------------------------------------------------------------------
106 // For every transition T that has both, a trigger and an effect do the following:
107 // For every effect:
108 // Create a conditional C and add it to the parent of T's source state S_src.
109 // create a new true triggered immediate effect transition T_eff and move all effects of T to T_eff.
110 // Set the T_eff to have T's target state. Set T to have the target C.
111 // Add T_eff to C's outgoing transitions.
112 def Region transformTriggerEffect(Region rootRegion) {
Alexander Schulz-Rosengarten 11.1 113 clearMapping; //NEW - clear previous mapping information to assure a single consistent mapping
Alexander Schulz-Rosengarten 10.1 114 // Clone the complete SCCharts region
115 var targetRootRegion = rootRegion.mappedCopy; //NEW - mapping information (changed copy to mappedCopy)
116 // Traverse all transitions
117 for (targetTransition : targetRootRegion.getAllContainedTransitions) {
118 targetTransition.transformTriggerEffect(targetRootRegion);
119 }
Alexander Schulz-Rosengarten 12.1 120 val completeness = checkMappingCompleteness(rootRegion, targetRootRegion); //NEW - DEBUG
121 targetRootRegion;
Alexander Schulz-Rosengarten 10.1 122 }
123 def void transformTriggerEffect(Transition transition, Region targetRootRegion) {
Alexander Schulz-Rosengarten 12.1 124 // Only apply this to transition that have both, a trigger (or is a termination) and one or more effects
125 if (((transition.trigger != null || !transition.immediate || transition.typeTermination) && !transition.effects.nullOrEmpty) ||
Alexander Schulz-Rosengarten 11.1 126 transition.effects.size > 1) {
Alexander Schulz-Rosengarten 10.1 127 val targetState = transition.targetState
128 val parentRegion = targetState.parentRegion
129 val transitionOriginalTarget = transition.targetState
130 var Transition lastTransition = transition
Alexander Schulz-Rosengarten 12.1 131 val firstEffect = transition.effects.head
Alexander Schulz-Rosengarten 10.1 132 for (effect : transition.effects.immutableCopy) {
Alexander Schulz-Rosengarten 12.1 133 // Optimization: Prevent transitions without a trigger
134 if(transition.immediate && transition.trigger == null && firstEffect == effect) {
135 // skip
136 } else {
137 val effectState = parentRegion.createState(GENERATED_PREFIX + "S")
138 effectState.mapParents(transition.mappedParents); //NEW - mapping information
139 effectState.uniqueName
140 val effectTransition = createImmediateTransition.addEffect(effect)
141 effectTransition.mapParents(transition.mappedParents); //NEW - mapping information
142
143 effectTransition.setSourceState(effectState)
144 lastTransition.setTargetState(effectState)
145 lastTransition = effectTransition
146 }
Alexander Schulz-Rosengarten 10.1 147 }
148 lastTransition.setTargetState(transitionOriginalTarget)
149 }
150 }
151 {{/code}}
152
Alexander Schulz-Rosengarten 12.1 153 === Create TransformationTree ===
Alexander Schulz-Rosengarten 10.1 154
Alexander Schulz-Rosengarten 12.1 155 The following code will now perform each transformation stepwise and updates a transformation tree each step.
Alexander Schulz-Rosengarten 10.1 156
Alexander Schulz-Rosengarten 12.1 157
Alexander Schulz-Rosengarten 10.1 158
159 {{code title="Transform and create TranformationTree" theme="Eclipse" linenumbers="true" language="java" firstline="1" collapse="true"}}
Alexander Schulz-Rosengarten 12.1 160 aboSplitTE = SCCtransformation.transformTriggerEffect(abo);
Alexander Schulz-Rosengarten 10.1 161
Alexander Schulz-Rosengarten 12.1 162 ModelWrapper aboSplitTEModel =
163 transformationTree.initializeTransformationTree(SCCtransformation.extractMapping(), "TriggerEffect", abo, "coreSCChart", aboSplitTE, "coreSCChart-splitTriggerEffect");
Alexander Schulz-Rosengarten 10.1 164
Alexander Schulz-Rosengarten 12.1 165 aboNormalized = SCCtransformation.transformSurfaceDepth(aboSplitTE);
166
167 ModelWrapper aboNormalizedModel =
168 transformationTree.addTransformationToTree(SCCtransformation.extractMapping(), aboSplitTEModel, "SurfaceDepth", aboSplitTE, aboNormalized, "normalizedCoreSCChart");
169
170 aboSCG = SCGtransformation.transformSCG(aboNormalized);
171
172 ModelWrapper aboSCGModel =
173 transformationTree.addTransformationToTree(SCGtransformation.extractMapping(), aboNormalizedModel, "SCC2SCG", aboNormalized, aboSCG,"SCG");
174
175 tree = transformationTree.root(aboSCGModel);
Alexander Schulz-Rosengarten 10.1 176 {{/code}}
177
Alexander Schulz-Rosengarten 12.1 178
Alexander Schulz-Rosengarten 10.1 179
Alexander Schulz-Rosengarten 12.1 180 The resulting TransformationTree has following structure and representing each step and model of the transformation.
Alexander Schulz-Rosengarten 10.1 181
Alexander Schulz-Rosengarten 12.1 182
Alexander Schulz-Rosengarten 10.1 183
Alexander Schulz-Rosengarten 12.1 184 |=(% colspan="4" style="text-align: center;" %)(% colspan="4" style="text-align: center;" %)
185 (((
Alexander Schulz-Rosengarten 10.1 186 [[image:attach:example_tree.jpeg]]
Alexander Schulz-Rosengarten 12.1 187 )))
188 |(% colspan="1" style="text-align: center;" %)(% colspan="1" style="text-align: center;" %)
189 (((
190 [[image:attach:example_abo.jpeg]]
191 )))|(% colspan="1" style="text-align: center;" %)(% colspan="1" style="text-align: center;" %)
192 (((
193 [[image:attach:example_abo_splitTE.jpeg]]
194 )))|(% colspan="1" style="text-align: center;" %)(% colspan="1" style="text-align: center;" %)
195 (((
196 [[image:attach:example_abo_norm.jpeg]]
197 )))|(% colspan="1" style="text-align: center;" %)(% colspan="1" style="text-align: center;" %)
198 (((
199 [[image:attach:example_abo_scg.jpeg]]
200 )))
Alexander Schulz-Rosengarten 10.1 201
Alexander Schulz-Rosengarten 12.1 202
Alexander Schulz-Rosengarten 10.1 203
Alexander Schulz-Rosengarten 12.1 204 Furthermore the TransformationTree now contains mapping information for the whole transformation chain.
Alexander Schulz-Rosengarten 10.1 205
Alexander Schulz-Rosengarten 12.1 206 Now we can use an additional feature of KTM, the resolving of mappings between arbitary models.
Alexander Schulz-Rosengarten 11.1 207
Alexander Schulz-Rosengarten 12.1 208 The following code has starts with an instance of the initial ABO SCChart and SCG, along with the TranformationTree above.
209
210
211
212 {{code title="resolveMapping" theme="Eclipse" linenumbers="true" language="java" firstline="1" collapse="true"}}
213 @Inject
214 extension TransformationTreeExtensions
215
216 //Find nodes of model instances in tree
217 val aboSCCModelWrapper = transformationTree.findModel(aboSCC,"coreSCChart");
218 val aboSCGModelWrapper = transformationTree.findModel(aboSCG,"SCG");
219
220 //resolve
221 val mapping = resolvemapping(aboSCCModelWrapper, aboSCC, aboSCGModelWrapper, aboSCG);
222 {{/code}}
223
224
225
226 The returned mapping is a multi mapping between all object in aboSCC and their resulting objects in aboSCG.
Alexander Schulz-Rosengarten 13.1 227
Alexander Schulz-Rosengarten 14.1 228 This mapping can now displayed in models or used for various information propagation between elements of the models.
Alexander Schulz-Rosengarten 13.1 229
230 [[image:attach:example_abo_resolved.jpeg]]
231
232
233
Alexander Schulz-Rosengarten 14.1 234 Also a more detailed view is available, showing all EObjects relation.
Alexander Schulz-Rosengarten 13.1 235
236
237
238 [[image:attach:example_abo_resolved_elements.jpeg]]
239
240