Table of Contents

Addressing model elements

NMF uses identifiers to assign URIs to model elements automatically. Identifiers are attributes and assigned at a class level. If a class does not have an identifier set, an identifier is inherited from the base types. If a class inherits multiple identifiers, NMF uses the first identifier found in a depth-first search.

Caution

Never have more than one identifier for a class.

Identifiers can have either local or global scope. A local scope means that the identifier is unique within a container. A global scope means the identifier is unique across the entire model. A typical example of a local identifier is a name. Within a class, the name of an element must be unique, but an attribute or reference with the same name is allowed in a different class. A typical example of a global identifier is a Universally/Globally Unique Identifier (UUID or GUID).

NMF assigns URIs to model elements in the following order:

  1. If an element has a globally unique identifier, this identifier is used as a fragment. For example, the relative URI of a model element with global identifier foo is #foo.
  2. If an element has a local identifier, this identifier is used as a segment. For example, the relative URI of a model element with local identifier bar in a container element with relative URI #foo is #foo/bar.
  3. If an element has no identifier but is contained in a single-valued or ordered feature, the name of the feature prefixed with @ is used as a segment. In case of a collection-valued feature, the index is appended, separated by a dot. For example, the relative URI of a model element contained in the feature bar of a model element with relative URI #foo is #foo/@bar. If this feature was a collection and the element was at index 3, the relative URI would be #foo/@bar.3.
  4. If a model element is the single root element of a model and the flag PromoteSingleRootElement is active, its relative URI is null. Relative URIs to this element are the segments prefixed with #//.
  5. All other root elements of a model get a relative URI with their index, prefixed with a slash. The second root element has a relative URI #//1.

An absolute URI is the concatenation of the Model URI of the containing model and the relative URI which is a fragment to it.

NMF has a switch PreferIdentifiers as a static property of ModelElement that controls whether URIs generated by NMF prefer an identifier if available, or resort to index-based URIs. If a model element does not fall into any of the above categories, it does not have a relative or absolute URI. In that case, the serializer will generate an XMI ID for it.