Java Reference
In-Depth Information
Although the two diagrams are similar, the structure of their domain models
is quite different. The subtopics in our mindmap are contained in the canvas ele-
ment ( Map::elements ) and linked using noncontainment references. In the
requirements model, Requirement and RequirementGroup elements have
children that are contained by their parents. Now let's take a look at the QVT
that enables us to transform these models. The following is an updated
toRequirementsModel() mapping in our mindmap2requirements transfor-
mation definition.
transformation mindmap2requirements( in inModel : mindmap,
out outModel : requirements);
property dependencies : Set (Relationship) = null ;
property reqCtr : Integer = 1;
property grpCtr : Integer = 1;
main () {
inModel.rootObjects()[Map]-> map toRequirementsModel();
}
mapping mindmap::Map::toRequirementsModel() : requirements::Model {
init {
this .dependencies := self .dependencies();
}
title := self .title;
groups += self .rootTopics. map toRequirementGroup()->asOrderedSet();
}
Notice that a dependency property is declared at the top of the transfor-
mation and is initialized using a dependencies() query in the main mapping's
init{} block. Relationship elements are stored within the same containment
feature of our Map as Topic elements, so we can use this query to collect all
those Relationship s of type DEPENDENCY for use in our toRequirement()
mapping. This is the dependencies() query:
query mindmap::Map::dependencies() : Set (mindmap::Relationship) {
return self.elements-> select ( oclIsTypeOf (mindmap::Relationship))
-> select (c | c. oclAsType (mindmap::Relationship).type =
mindmap::Type::DEPENDENCY)
-> collect ( oclAsType (mindmap::Relationship))->asSet();
}
Recall that we implemented the derived rootTopics reference of our Map
class using OCL in Section 3.3, “Developing the Mindmap Domain Model.” We
could use the OCL used to derive the root Topics within this QVT script, but
Search WWH ::




Custom Search