Skip to main content
Jump to: navigation, search

Snippet: Create Model Artifacts

< To: Tigerstripe_APIs
This snippet illustrates how to create model artifacts through the Tigerstripe M-API.

Because this API is undergoing major re-factoring to leverage EMF, we are providing here 2 versions:

  • with the new EMF-based API.
  • with the soon to be deprecated API

Both examples assume that a Tigerstripe Model project is available.

EMF-based API

The EMF-based API leverages EMF and EMF Transactions to create/edit artifacts. It not only provides a better API but also is better integrated with the multi-threaded environment of Eclipse.

NOTE: the implementation of this new version of the M-API is not complete yet

// Let's assume we have a project
ITigerstripeModelProject project = ...
// Get the model Manager for the project
IModelManager mMgr = project.getModelManager();
// At this stage the default repository is hardcoded to be a PojoModelRepository
// This should be configurable in the future.
IModelRepository repo = mMgr.getDefaultRepository();
// Use the EMF-generated factory
IManagedEntityArtifact nMea = MetamodelFactory.eINSTANCE.createIManagedEntityArtifact();
// Set the Name&Package as the required attributes before the repository can store the Artifact
// Then store it, true);
// At this stage a Pojo src/com/mycompany/testNO/ was created on disk.

To further modify the Mea object, a transaction will be required (See Snippet: Work with Model Artifacts).


The old API uses the IArtifactManagerSession object on the project both as a factory to create artifacts as well as to query and look up artifacts in the project.

The old API could only persist Artifacts in POJOs.

// ... assuming a project is there
ITigerstripeModelProject project = ...
// First get the session
IArtifactManagerSession session = project.getArtifactManagerSession();
// Then use it as a factory to make an empty Managed Entity
// Note that default values are populated by the "makeArtifact"
IManagedEntityArtifact mea = (IManagedEntityArtifact) session
// The minimum required attributes before a doSave(..) are Name and Package
mea.doSave(new NullProgressMonitor());
// This API doesn't rely on Eclipse's view of the filesystem (IResources)
// THIS IS MANDATORY so Eclipse picks up the newly created POJO.
IProject iProject = (IProject) project.getAdapter(IProject.class);
   new NullProgressMonitor());

At this stage a Pojo in src/com/mycompany/testON/ has been created on disk and should appear in the Tigerstripe Explorer.

Back to the top