Java Reference
In-Depth Information
This query operation returns all objects of type Topic from the elements ref-
erence of a Map instance:
query mindmap::Map::getTopics() : Sequence (mindmap::Topic) {
return self .elements-> select ( oclIsTypeOf (mindmap::Topic))
-> collect ( oclAsType (mindmap::Topic));
}
In queries, it's possible to define and assign local variables. For example, the fol-
lowing query returns a dot-delimited fully qualified name for a class based on its
package namespace:
query oocore::Class::fullyQualifiedName() : String {
var fqn : String := self .name;
var pkg : oocore::Package := self ._package;
while (not pkg.oclIsUndefined()) {
fqn := pkg.name + '.' + fqn;
pkg := pkg._package;
};
return fqn;
}
13.5 Implementing Operations
Within mapping and query operations, objects are created, initialized, passed as
parameters, returned as parameters, and more. Although much of the syntax you
will use within mapping and query bodies is OCL, QVT provides additional
features. This section covers essential OCL and QVT operations, mapping and
query invocation, object creation, and population.
13.5.1 Operations and Iterators
All the common OCL operations and iterators form the basis of QVT, with
imperative versions provided to support side effects and strict semantics.
select
The select() operation comes from OCL and allows for the filtering of col-
lections to work with a subset. The conditional argument provides for the spec-
ification of the filter and can have an optional iterator variable. Following is an
example of select in which all objects of type mindmap::Topic are returned
from the elements collection:
 
Search WWH ::




Custom Search