Chapter 8: Metamodel

In script languages with no native support for the various metamodel packages used in the tool, such as Java Script, there is a separate root object to get access to all metaclasses. This singleton object provides access to all known packages which themselves provide access to all contained metaclasses. The metaobjects can be used for example as designator for the finder methods.

// sample for using Metamodel
var tops = finder.findByType(Metaclass.FTA.Event, true);

// ... instead of using plain strings
var tops = finder.findByType("Event", true);

It can also be used nicely in conjunction with the Java Script instanceof operator.

// make sure a safety goal is selected
if (selection && selection.length && selection[0] instanceof Metamodel.safetygoals.SafetyGoal) {
	alert("You selected a goal");
}

This script is working fine if the selected object is a safety goal because the prototype of the object is exactly the EClass of SafetyGoal. This also works for abstract base classes:

// make sure any Failure is selected 
if (selection && selection.length && selection[0] instanceof Metamodel.safetyModel.Failure) {
	alert("You selected a failure");
} 

Failure is an abstract base class for Hazard, Malfunction etc. So the prototype of such an object is not exactly the EClass of Failure but a sub-class of it (on metamodel level). In these cases the instanceof operator will check the complete inheritance hierarchy.

Note that the objects contained in "Metamodel" are EMF Metaclasses and not Java interfaces. So Metamodel.safetygoals.SafetyGoal is of type EClass and not the SafetyGoal Java interface. Consult the Metamodel Guide about all available packages and meta-classes.