Derived features
Derived features were added in version 2.0 of the model weaver.
By definition derived features are features that are calculated over
other features. We cannot save a derived feature, only the features
that are used in the calculation.
In the model weaver V2.0 the metametamodel was changed to enable
deriving references, e.g., the user may define a derived reference that
is a set of other references. It was defined in the KM3 syntax and it
is supported by the weaver workbench. For this the developer should use
the subsets annoation in the
references. See an example of consumer/supplier below:
package derived_features {
class Supplier extends WLink {
reference orders[*] container: PurchaseOrder oppositeOf linkOrder;
-- @subsets orders
reference supplier[*] container : PurchaseOrder oppositeOf linkSupplier;
-- @subsets orders
reference consumer[*] container : PurchaseOrder oppositeOf linkConsumer;
}
class PurchaseOrder extends WLinkEnd {
reference linkOrder: Supplier oppositeOf orders;
reference linkSupplier: Supplier oppositeOf supplier;
reference linkConsumer: Supplier oppositeOf consumer;
}
}
To be able to get a derived feature, the developer can access the
Reflective API of Ecore directly: the "derived" attribute is set to true and it is added an annotation
with the name of all derived references concatenated. Or use a helper
method defined in org.eclipse.weaver.core.WeaverModelHelper:
public List getDerivedValues(EObject eObj, String featureName) throws
WeaverException;
In the example above, if one wants to get the all the derived orders
(supplier and consumer), one must call getDerivedFeatures(aObject,
"orders"). It returns a list with all suppliers and consumers.
In the user interface, derived features are indicated by "<" and
">" in the menus, for example "<orders>
supplier" and "<orders>
consumer".