-
Notifications
You must be signed in to change notification settings - Fork 0
4. Saving
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
.
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.
-
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 classAbstractSavingStrategy
also refreshes the project folder to make the model file visible in the eclipse IDE.The new strategy should implement three methods:
beforeSaving()
,getFileName()
andgetFilePath()
.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()
andgetFilePath()
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. -
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 classeme.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();
}