Previous UML Classes Table of Contents UML Packages Next


7.3.15 ElementImport

Kernel


   An element import identifies an element in another package, and allows the element to be referenced using its name without a qualifier.

*Generalizations

   

    DirectedRelationship (from Kernel ) on page 62

   Description

   An element import is defined as a directed relationship between an importing namespace and a packageable element. The name of the packageable element or its alias is to be added to the namespace of the importing namespace. It is also possible to control whether the imported element can be further imported.

   Attributes

Issue 9191 - add default value

   Associations

   Constraints

   [1] The visibility of an ElementImport is either public or private.

   self.visibility = #public or self.visibility = #private

   [2] An importedElement has either public visibility or no visibility at all.

   self.importedElement.visibility.notEmpty() implies self.importedElement.visibility = #public

   Additional Operations

   [1] The query getName() returns the name under which the imported PackageableElement will be known in the importing namespace.

   ElementImport ::getName(): String;

   getName =

   if self.alias->notEmpty() then

   self.alias

   else

   self.importedElement.name

   endif

   Semantics

   An element import adds the name of a packageable element from a package to the importing namespace. It works by reference, which means that it is not possible to add features to the element import itself, but it is possible to modify the referenced element in the namespace from which it was imported. An element import is used to selectively import individual elements without relying on a package import.

   In case of a name clash with an outer name (an element that is defined in an enclosing namespace is available using its unqualified name in enclosed namespaces) in the importing namespace, the outer name is hidden by an element import, and the unqualified name refers to the imported element. The outer name can be accessed using its qualified name.

Issue 8079 -Clarify meaning of import when there are name clashes.

   If more than one element with the same name would be imported to a namespace as a consequence of element imports or package imports, the elements are not added to the importing namespace and the names of those elements must be qualified in order to be used in that namespace. If the name of an imported element is the same as the name of an element owned by the importing namespace, that element is not added to the importing namespace and the name of that element must be qualified in order to be used.

   An imported element can be further imported by other namespaces using either element or package imports.

   The visibility of the ElementImport may be either the same or more restricted than that of the imported element.

   Notation

   An element import is shown using a dashed arrow with an open arrowhead from the importing namespace to the imported element. The keyword «import» is shown near the dashed arrow if the visibility is public, otherwise the keyword «access» is shown to indicate private visibility.

   If an element import has an alias, this is used in lieu of the name of the imported element. The aliased name may be shown after or below the keyword «import».

   Presentation options

   If the imported element is a package, the keyword may optionally be preceded by element, i.e., «element import».

   As an alternative to the dashed arrow, it is possible to show an element import by having a text that uniquely identifies the imported element within curly brackets either below or after the name of the namespace. The textual syntax is then:

   ‘{element import’ <qualified-name> ‘}’ | ‘{element access ’ <qualified-name> ‘}’

   Optionally, the aliased name may be shown as well:

   ‘{element import ’ <qualified-name> ‘ as ’ <alias> ‘}’ | ‘{element access ’ <qualified-name> ‘as’ <alias> ‘}’

   Examples

    The element import that is shown in Figure 7.39 allows elements in the package Program to refer to the type Time in Types without qualification. However, they still need to refer explicitly to Types::Integer, since this element is not imported. The Type string can be used in the Program package but cannot be further imported from that package.

Figure 7.39 - Example of element import

   In Figure 7.40 , the element import is combined with aliasing, meaning that the type Types::Real will be referred to as Double in the package Shapes.

Figure 7.40 - Example of element import with aliasing