Target domain registration

This section explains how to register your own domain to be used as mapping targets.

The UML metamodel

To use an Ecore model as a target domain, all objects of the target domain must implement the ITarget interface in addition to the EMF EObject interface. The DevOps Modeling Platform provides a custom implementation for UML to be used as the target model, as shown below.

<factory
    NS_PREFIX="uml"
    class="com.ibm.xtools.umlviz.core.internal.model.VizUMLFactoryImpl"
    package_uri="http://www.eclipse.org/uml2/3.0.0/UML">
</factory>

The MMI factory for UML elements is registered in com.ibm.xtools.umlviz.core. It is based on the UML 2 metamodel, which is defined by the http://www.eclipse.org/uml2/3.0.0/UML URI. String ids are formed by the standard string representation of the EClass prefixed by uml.. For example, the UML2 Class's string representation is uml.Class.

Creating a factory for the target model's elements

Individual MMI domain providers are free to implement their own target domain in addition to the UML one. The first step is to implement a factory for creating custom ITarget EObjects. This factory should implement the interface of the non-MMI factory. The createEClassType() methods should be overridden to create and return a new instance of an object of the specified EClass type that also implements the ITarget interface. The class of the factory is registered as shown in the class attribute above.

Choosing a namespace prefix

Next, a namespace prefix that doesn't collide with other namespaces must be chosen for the factory. Every EClass has a string representation obtained using EClass.getName(). The namespace prefix will become the prefix for the EClass's string representation. For example, if the string representation of an EClass is Operation, and the namespace prefix is uml, then the EClass is uniquely identified by uml.Operation. In MMICoreUtil, the getEClass() method will return the EClass given the string representation including the namespace prefix. Conversely, the getStringID() method returns the string representation with the namespace prefix for the given EClass. The namespace prefix corresponds to the NS_PREFIX attribute in the XML example above.

Package URI

The URI of the Ecore model describing a domain must be specified as the value of the package_uri attribute.

Creating model elements using a factory

Model elements are typically instantiated using the factory for creating the custom ITarget EObjects. However, client code may not have knowledge of the class containing the factory. In these cases, the create() utility in MMICoreUtil creates the ITarget objects from the registered factories. If only a string representation of the EClass is available, using the MMICoreUtil.getEClass() method to obtain the EClass required by the create() method should do it.

Implementing ITarget objects

As long as the object implements the ITarget interface, it can be used as a target model element. Here are some useful tips on creating a target model.

Leverage TargetImpl

Using TargetImpl as a delegate will help. Creating the TargetImpl in a constructor is shown below.

TargetImpl delegate = null;

protected MyObjectImpl() {
    super();
    delegate = new TargetImpl(this);
}

Delegating to the instance of the TargetImpl will avoid implementing the specifics of methods such as synchronizeFeature(), enableSynchronization(), setClean(), setDirty(), isActivated(), getStructuredReference(), getTargetSynchronizer(), activate(), and deactivate(). For example, the setClean() method could delegate to the instance of the TargetImpl as shown below.

public void setClean(EStructuralFeature arg0) {
    if (delegate != null)
        delegate.setClean(arg0);
    }
}

Synchronizing the getters

Requested feature should always be synchronized before it is returned using the synchronizeFeature() method. The implementation of synchronizeFeature() should delegate to the instance of the TargetImpl as well.

public Object getFeature() {
    synchronizeFeature(EXTLibraryPackage.eINSTANCE.getFeature(), null);
    return super.getFeature();
}

Create the correct model elements

If a given ITarget has create methods, it must create objects that implement the ITarget interface. The easiest way to do this is by using a custom factory for ITargets. In case there already exists an EMF-generated factory for a given domain, it is important not to use it since it will not create ITarget elements.

public YourModelElement createYourModelElement() {
    //use factory that creates ITarget objects
    return (YourModelElement) YourFactory.createOwnedElement(...);
}

Legal notices