Skip to content
Timur Sağlam edited this page Sep 29, 2017 · 14 revisions

The Saving Strategies

The project supports five 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 five basic saving strategies are:

  • Saving into a newly created project named similarly to the source project: NewProjectSaving
  • Saving into the original project where the metamodel was extracted from: OriginalProjectSaving
  • Saving into a copy of the original project: CopyProjectSaving
  • Saving into a specific output project: ExistingProjectSaving
  • Saving to a specific user given path: CustomPathSaving

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

Adding Saving Strategies

When adding 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. The name of the class has to end with the suffix "Strategy". 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 the 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.

    The class AbstractSavingStrategy offers two methods for saving strategies: projectExists() checks whether a project name is an active project in the Eclipse workspace. createSuffix(String projectName, String base) returns a suffix string for a project. The suffix is the base with a separator character and capitalization depending on the project name.

  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 "MyNewSaving", 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 (isStrategy(MyNewSaving.class, strategyName)) {
  savingStrategy = new MyNewSaving();
}
Clone this wiki locally