Skip to content
Timur Sağlam edited this page Jan 27, 2017 · 14 revisions

The Saving Strategies

The project supports four different saving strategies to save an Ecore metamodel to an Ecore file. All of them implement the abstract class AbstractSavingStrategy, which allows adding additional Interfaces. The four basic saving strategies are:

  • Saving into the same project where the metamodel was extracted from: SameProjectSavingStrategy
  • Saving into a newly created project named similarly to the source project: NewProjectSavingStrategy
  • Saving into a specific output project: OutputProjectSavingStrategy
  • Saving to a specific user given path: CustomPathSavingStrategy

All classes for the saving process are stored in the package eme.generator.saving.

Adding Saving Strategies

When adding a new saving strategies, two steps must be followed: The creation of a custom strategy class that inherits from AbstractSavingStrategy, and a small addition to the class EcoreMetamodelGenerator to enable choosing the newly created strategy.

  1. Creating a Custom Strategy Class: To create a new saving strategy, a subclass of the class AbstractSavingStrategy has to be created. In the constructor of the new saving strategy, the super constructor call should specify whether the strategy saves in an eclipse project. If that is the case, the saving process in the class AbstractSavingStrategy also refreshes the project folder to make the model file visible in the eclipse IDE. The new strategy should implement three methods: beforeSaving(), getFileName() and getFilePath(). beforeSaving() gets called before the saving process itself. It takes the name of the project where the metamodel was extracted as argument and allows to prepare the saving itself (e.g. create a new project). getFileName() and getFilePath() get called during the saving itself and specify where the new strategy wants to save the model (e.g. a path to an eclipse project) and what the model file should be called.

  2. Activation of the strategy: To use the strategy with the project, one has to enable choosing the newly created strategy. To do that, you have to modify the switch case in the method changeSavingStrategy() in the class eme.generator.EcoreMetamodelGenerator. For a new strategy named "MyNewStrategy" the lines from codesnippet 1 should be added. The new strategy can then be chosen in the properties file with the value "MyNew" for the property SavingStrategy.

codesnippet 1:

} else if ("MyNew".equals(strategy)) {
    savingStrategy = new MyNewSavingStrategy();
}
Clone this wiki locally