Model weaver ID generation mechanism (since 2.0)
The user may choose between specific ID generation mechanisms. It was
developed using the EMF object adapters.
The developer must create an extension of an Item Provider for an object that
inherits the abstract class WElementRef
(see the core weaving metamodel). It must create a metamodel
extension with two new classes: one that inherits WModelRef, redefining the
reference ownedElementRef. It will reference another class that
inherits WElementRef, where
the adapter will be linked in the plugin.xml
file. In the moment of
object creation this new adapter is added in the object adapters list.
The item provider must implement org.eclipse.gmt.weaver.providers.IItentifierAdapter
as well. The interface defines two methods, getID() and setID(Object obj).
These methods are called in the moment a new WElementRef child is created, and
passes the selected object as parameter. The developer may implement
this interfaces as he wants, definting its own ID mechanism.
In the model weaver, the default extension implementes a standard
adapter that sets an XMI ID for every created object. It is linked with
the ElementRefXMI element. If the user chooses another WElementRef, such as ElementRef, the current object URI
based on XPointer is used as
identification.
Interface:
public interface IIdentifierAdapter extends Adapter
{
/**
* sets the id of the current object
calculating from the obj
* @param obj the object to do the calculations
(is is commonly a String)
*/
public void setID(Object obj);
/**
* gets the id of the current object
* @return the object ID
*/
public Object getID();
}