Importing and filtering elements
An import relationship allows one namespace to import memberships from another namespace. The member elements from imported memberships become (unowned) members of the importing namespace in addition to being members of the imported namespace.
Element import kinds and visibility
Import kinds
The import kind is specified as a specific suffix added to the import's qualified name.
| Import kind | Suffix | Imports | Example |
|---|---|---|---|
Membership import | none | Only the specified namespace (i.e., element import). | package 'Vehicle Information' { package 'Vehicle Details' { |
Namespace import | ::* | The content of the specified namespace. | package 'Vehicle Information' { package 'Vehicle Details' { |
Recursive membership import | ::** | The specified namespace and its content, including sub-namespaces and their elements. | package 'Vehicle Information' { package 'Vehicle Details' { |
Recursive namespace import | ::*::** | The content of the specified namespace, including sub-namespaces and their elements. | package 'Vehicle Information' { package 'Vehicle Details' { |
Import visibility
The import visibility is specified as a specific keyword declared prior to the import keyword. The import visibility keywords are as follows:
- public - membership is visible outside the namespace.
- private - membership is invisible from outside the namespace.
- protected - membership is invisible outside the namespace, except in inheritance, where it behaves like public.
Element import
Importing elements
To import elements
- In the Textual Editor, place the cursor where you want to import the element(s).
- Specify the import visibility, declaring the needed keyword.
- Declare the keyword import.
- Specify the qualified name of the membership/namespace you want to import, followed by the appropriate suffix for a recursive/membership/namespace import.
- (Optional) Specify a filter for the import.
- Click the Synchronize button.
You can specify multiple import relationships for the same view.
package 'Vehicle Information' {
part vehicleSpecs {}
part vehicleRecord {
item vehicleModel;
}
}
package 'Vehicle Details' {
private import 'Vehicle Information'::**; // private recursive membership import of 'Vehicle Information', vehicleSpecs, vehicleRecord, vehicleModel
}
Reviewing imported elements
To review the elements imported for a specific element, open its Specification window and check the values of the Imported Membership property.
Importing library elements
Import is especially useful for accessing library elements instead of using a qualified name each time.
// instead of using a qualified name each time:
package 'Employee Data' {
part employeeData {
// accessing 'String' and 'Real' data types from the ScalarValues library via qualified name:
item employeeName : ScalarValues::String;
item ID : ScalarValues::Real;
}
}
// use import to access library elements:
package 'Employee Data' {
private import ScalarValues::**; // importing ScalarValues library
part employeeData {
item employeeName : String; // no need for qualified name
item ID : Real; // no need for qualified name
}
}
Element import filtering
Namespaces have the capability to filter elements upon import based on certain conditions, usually defined in terms of the metadata provided by annotations of those elements. Only elements that meet all filter conditions become imported members of the namespace.
- Filter conditions can be used only for package (element import) and view (element exposition) elements.
- Filter condition expression must be model-level evaluable. Any SysML v2 expression can be used for the filter condition specification, but it must return true/false.
- @, istype, and hastype classification operators are commonly used to check if an element has the given metadata annotation.
- Element metaclass metadatas are located in used projects at Standard Libraries > SysML > Systems. Filter conditions require a qualified name for metadata-based filtering (e.g., @SysML::Systems::PartUsage).
Separately declared filter conditions
To specify separately declared filter conditions
- In the Textual Editor, place the cursor within the body of the package after an import declaration.
- Declare the keyword filter followed by filter condition expression, including the needed operator and the qualified name of the element you want to import.
- Click the Synchronize button.
package MetadataDefinitions {
metadata def Safety {
attribute isMandatory : Boolean;
}
}
package Vehicle {
private import MetadataDefinitions::**;
part vehicle {
part interior {
part alarm;
part seatBelt [2] { @Safety{isMandatory = true;} }
part frontSeat [2];
part driverAirBag { @Safety{isMandatory = false;} }
}
}
}
package 'Vehicle Features' {
private import Vehicle::**; // imports package Vehicle
// you can use multiple filter condition declarations:
filter @ SysML::Systems::PartUsage; // imports part usage elements from the package Vehicle
filter @ MetadataDefinitions::Safety and MetadataDefinitions::Safety::isMandatory; // imports elements with Safety metadata attribute isMandatory value true from previously filtered part usage elements imported from the package Vehicle
}