EMF Identifier Generation

Aus SDQ-Wiki
Wechseln zu: Navigation, Suche

ECORE attributes for Identifiers

Scenario: You want a central Identifier class in your ECORE model to enable references through IDs instead of XPath expressions.

Solution: Introduce central class Identifier with a id string attribute as depicted in the following graphic:


Now you still need a GUID generation mechanism. Otherwise the ID will never be set. Set the ID in the constructor of your Identifier class: this.id = EcoreUtil.generateUUID(); or setId(EcoreUtil.generateUUID());. Within the PCM the Identifier class is already readily implemented: de.uka.ipd.sdq.identifier (see below).

Using a central identifier project for Unique Identifiers in XMI serializations

Scenario: You want to use Identifiers for referencing model elements in your EMF-based model. The identifier is for re-use reasons splitted into another project/package so that classes can simply inherit from the Identifier class in the central project.

Problem: Your serializations contain a _="_eofdniwrefw321" as ID instead of id="_eofdniwrefw321". When opening your serialized files, you get a "feature not found" exception for the feature "_".

Solution: Fill out the "ExtendedMetaData" for your ID attribute of the Identifier class as shown in the following picture:

ExtendedMetaData attributes in the ECORE model: You must fill our the name and the namespace attribute.

ExtendedMetaData attributes in the ECORE model: You must fill our the name and the namespace attribute.

How to use Identifier plugin of PCM Commons

PCM Commons is a project that is maintained by Palladio developers but also independent of Palladio. Therefore, you can use features of the project without introducing a dependency to Palladio artifacts. In order to use the identifier feature of PCM Commons, you can simply install it from the corresponding update site.

While UML and ECORE allow multiple inheritance, in Java code this is not allowed. Thus, when EMF creates code for meta-models, only the very first superclass is in an extends relation with the set of specified superclasses from the meta-model. For all other superclasses only the interface of the superclass is implemented (implements).

As the Identifier (de.uka.ipd.sdq.identifier) implementation is "hacking" the constructor, it is required to have it as the very first superclass:

  • Identifier must be the first superclass in the inheritance hierarchy of the meta-model. Edit the UML XMI representation to ensure Identifier being the very first entry in the XML representation.
  • Tick "respect order of superclasses" when importing a ECORE/UML model with EMF
  • To get the right reference to the Identifier plugin when loading your metamodel into your genmodel, you might have to check out the identifier plugin and have it open in your workspace (as some existing models may refer to ../../de.uka.ipd.sdq.identifier instead of a plugin).

Further Information for Developers

Keywords: EMF, Identifier, ID, generate