Page History
...
- 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.
- 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.
- 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.
...
Example
In this example we will perform some transformations on SCCharts.
The source chart is a ABO, the "Hello World" of SCCharts.
ABO is already a CoreSCChart, so we will perform normalization and a transformation to SCG.
Creating Mapping during Transformation
The following code is a modifcation of the tranformation "Spilt Trigger and Effects" of SCCharts.In order to note every single element transformation of a model transformation, we use the TransformationMapping extension.
After each creation of new Objects for transformed model the mapping must be updated with it's origin information.
The codeblock blow show a snipped of SCChartCoreTransformation with additional mapping registration.
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
package de.cau.cs.kieler.ktm.test.transformations import com.google.inject.Inject import de.cau.cs.kieler.ktm.extensions.TransformationMapping import de.cau.cs.kieler.sccharts.Region import de.cau.cs.kieler.sccharts.Transition import de.cau.cs.kieler.sccharts.extensions.SCChartsExtension /** * @author als */ class SCChartTestTransformation { @Inject extension TransformationMapping @Inject extension SCChartsExtension @Inject extension TransformationMapping ... // NEW - Mapping access delegation def extractMapping() { extractMappingData; } ... //------------------------------------------------------------------------- //-- S P L I T T R A N S I T I O N -- //------------------------------------------------------------------------- // For every transition T that has both, a trigger and an effect do the following: // For every effect: // Create a conditional C and add it to the parent of T's source state S_src. // create a new true triggered immediate effect transition T_eff and move all effects of T to T_eff. // Set the T_eff to have T's target state. Set T to have the target C. // Add T_eff to C's outgoing transitions. def Region transformTriggerEffect(Region rootRegion) { clearMapping; //NEW - clear previous mapping information to assure a single consistent mapping // Clone the complete SCCharts region var targetRootRegion = rootRegion.mappedCopy; //NEW - mapping information (changed copy to mappedCopy) // Traverse all transitions for (targetTransition : targetRootRegion.getAllContainedTransitions) { targetTransition.transformTriggerEffect(targetRootRegion); } //check if mapping is complete (only for test proposes) val diffcompleteness = rootRegion.checkMappingCompleteness(rootRegion, targetRootRegion); //NEW if (diff.key.empty && diff.value.empty) {- DEBUG targetRootRegion; } else { null } } def void transformTriggerEffect(Transition transition, Region targetRootRegion) { // Only apply this to transition that have both, a trigger (or is a termination) and one or more effects if (((transition.trigger != null || !transition.immediate || transition.typeTermination) && !transition.effects.nullOrEmpty) || transition.effects.size > 1) { val targetState = transition.targetState val parentRegion = targetState.parentRegion val transitionOriginalTarget = transition.targetState var Transition lastTransition = transition val firstEffect = transition.effects.head for (effect : transition.effects.immutableCopy) { // Optimization: Prevent transitions without a trigger if(transition.immediate && transition.trigger == null && firstEffect == effect) { // skip } else { val effectState = parentRegion.createState(targetState.idGENERATED_PREFIX + effect.id"S") effectState.mapParents(transition.mappedParents); //NEW - mapping information effectState.setTypeConnectoruniqueName val effectTransition = createImmediateTransition.addEffect(effect) effectTransition.mapParents(transition.mappedParents); //NEW - mapping information effectTransition.setSourceState(effectState) lastTransition.setTargetState(effectState) lastTransition = effectTransition } } lastTransition.setTargetState(transitionOriginalTarget) } } } |
Create TransformationTree
...
To test the transformation and mapping we will transform th following ABO-SCChart.
...
The following code snipped performs the transformation on our ABO-example, extracts the mapping and creates will now perform each transformation stepwise and updates a transformation tree each step.
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
aboSplitTE = transformationSCCtransformation.transformTriggerEffect(abo); ModelModelWrapper aboSplitTEModel = transformationTreeExtensions.initializeTransformationTree( transformationtransformationTree.initializeTransformationTree(SCCtransformation.extractMapping(), "TriggerEffect", abo, "splitTriggerEffect", "coreSCChart", aboSplitTE, "coreSCChart-splitTriggerEffect"); aboNormalized = SCCtransformation.transformSurfaceDepth(aboSplitTE); ModelWrapper aboNormalizedModel = transformationTree.addTransformationToTree(SCCtransformation.extractMapping(), aboSplitTEModel, "SurfaceDepth", aboaboSplitTE, aboNormalized, "coreSCChartnormalizedCoreSCChart",); aboSCG = SCGtransformation.transformSCG(aboNormalized); ModelWrapper aboSCGModel = transformationTree.addTransformationToTree(SCGtransformation.extractMapping(), aboNormalizedModel, "SCC2SCG", aboSplitTE, "coreSCChart-splitTriggerEffectaboNormalized, aboSCG,"SCG"); tranformationTreetree = transformationTreeExtensionstransformationTree.root(aboSplitTEModelaboSCGModel); |
The result of transformation is the following SCChart. ABO-splitTriggerEffect.
Resulting TransformationTree has following structure.
resulting TransformationTree has following structure and representing each step and model of the transformation.
Furthermore the TransformationTree now contains the following mapping information for the whole transformation chain.
Here you can see the effect of the transformation causing the transformation to split up.
Now we can use an additional feature of KTM, the resolving of mappings between arbitary models.
The following code has starts with an instance of the initial ABO SCChart and SCG, along with the TranformationTree above.
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
@Inject
extension TransformationTreeExtensions
//Find nodes of model instances in tree
val aboSCCModelWrapper = transformationTree.findModel(aboSCC,"coreSCChart");
val aboSCGModelWrapper = transformationTree.findModel(aboSCG,"SCG");
//resolve
val mapping = resolvemapping(aboSCCModelWrapper, aboSCC, aboSCGModelWrapper, aboSCG); |
The returned mapping is a multi mapping between all object in aboSCC and their resulting objects in aboSCG.