Jump to: navigation, search

Snippet: Work with Model Artifacts

Revision as of 21:33, 17 February 2008 by Erdillon.cisco.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

< To: Tigerstripe_APIs

This snippet illustrates how to work with model artifacts.

EMF-Based API

Note: the EMF-Based API is still under construction and is not fully implemented

// Start by getting the Model Manager of the project
ITigerstripeModelProject project = ...
IModelManager mMgr = project.getModelManager();
//
// For now 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 to create a new artifact
IManagedEntityArtifact nMea = MetamodelFactory.eINSTANCE.createIManagedEntityArtifact();
// Name & Package are required before a Repository can store an Artifact
nMea.setName("Mea");
nMea.setPackage("com.mycompany.testNO");
// The pojo is created in a transaction
repo.store(nMea, true);
//
// To change an attribute on the Mea once it belongs to a repository,
// A transaction is needed:
final IManagedEntityArtifact fMea = nMea;
TransactionalEditingDomain editingDomain = repo.getEditingDomain();
//
editingDomain.getCommandStack().execute(new AbstractCommand() {
      @Override
      public boolean canExecute() {
        return true;
      }
      @Override
      public void execute() {
        fMea.setName("newName");
        fMea.setAbstract(true);
        fMea.setPackage("com.moo");
      }
      @Override
      public void redo() {
      }
});

Note that as this command is executed and commits, the POJO is renamed accordingly.

Old API

Note: the Old API is soon going to be deprecated