Java Reference
In-Depth Information
resolveone
When we're interested in only the first suitable result when using resolve, we can
use the resolveone alternative. If no suitable results are found, a null is
returned.
Returning to our example, although resolve worked in the last case, we
can improve it a bit by specifying that we want only the first result. So combin-
ing the two fragments and replacing resolve with resolveone , we have the
following equivalent version:
mapping mindmap::Relationship::toDependency()
when { self .type = mindmap::Type::DEPENDENCY }
{
init {
var sourceReq : requirements::Requirement :=
self .source. resolveone (requirements::Requirement);
sourceReq.dependencies +=
self .target. resolveone (requirements::Requirement);
}
}
resolveIn and resolveoneIn
If we want to further restrict the possible results to objects created by a specific
mapping, we can use the resolveIn and resolveoneIn variants. These take
an additional argument to represent the qualified identifier of the mapping. If
multiple mappings have the same name with different signatures, an ambiguity
error is reported.
In the case of our mindmap-to-requirements mapping, we have only one
mapping that produces Requirement objects from Topic objects, but if there are
more in the future, we can restrict those resolved by specifying the current map-
ping as follows:
var sourceReq : requirements::Requirement :=
self .source. resolveoneIn (mindmap::Topic::toRequirement,
requirements::Requirement);
sourceReq.dependencies +=
self .target. resolveoneIn (mindmap::Topic::toRequirement,
requirements::Requirement);
inv
Sometimes we're interested in the inverse resolution, or finding the source object
that was used in a mapping to create or update an object. By prefixing the resolve
Search WWH ::




Custom Search