Java Reference
In-Depth Information
The type returned from a resolve operation matches that provided, or a col-
lection (Sequence) of the type. If no type is specified,
OclAny
is the result type.
Technically, the specification calls for a return type of
Object
, but the current
QVTO implementation returns its subclass
OclAny
.
TIP
The conditional version of
resolve
can result in a performance advantage
over filtering the results because it avoids intermediate collection creation.
Let's consider our mindmap-to-requirements transformation to describe the
resolve
functions. As you might recall, a mindmap has a collection of Relation-
ship elements that are mapped to Requirement dependency references when the
type of Relationship is of
Type::DEPENDENCY
. To create this mapping, we first
need to obtain the Requirement object that was created from the source Topic
in the Relationship. For this, we can use the following
sourceReq
variable
assignment:
mapping
mindmap::Relationship::toDependency()
when
{
self
.type = mindmap::Type::DEPENDENCY }
{
init {
var
sourceReq : requirements::Requirement :=
self
.source.
resolve
(requirements::Requirement)->
any
(
true
);
}
...
}
This mapping is invoked from the
end
block of our main mapping, so all
Topic to Requirement mappings are completed. In this case, the
resolve
oper-
ation returns all Requirement objects that were created from the Topic object ref-
erenced in our
source
reference. We know that there is a one-to-one mapping
in this case, so we can filter the resulting
Sequence
using
any(true)
.
Having obtained the Requirement mapped from the
source
Topic in our
Relationship, we now need to find the Requirement object created from the
Topic referenced by the
target
reference and add it to our collection of
sourceReq
dependencies. We can accomplish this using another
resolve
oper-
ation. Although
resolve
returns all possible mappings, we know that only one
will be possible.
sourceReq.dependencies +=
self
.target.
resolve
(requirements::Requirement);
Search WWH ::
Custom Search