Class ModelContainer<M extends IModel>
- java.lang.Object
-
- net.ssehub.easy.producer.core.varMod.container.ModelContainer<M>
-
- Type Parameters:
M- the specific model type
- All Implemented Interfaces:
IModelData,IModelListener<M>
- Direct Known Subclasses:
ProjectContainer,ScriptContainer
public abstract class ModelContainer<M extends IModel> extends java.lang.Object implements IModelListener<M>, IModelData
Extended capabilities forIModels.- Author:
- El-Sharkawy
-
-
Field Summary
Fields Modifier and Type Field Description private SemanticErrorDescriptiondescriptionA optional description of exceptions, caught during parsing the model.private IModelListener<M>listenerOptionalIModelListenerfor getting informed whenever the managed model was replaced by the parser.private ConfigurationlocationThe location (folder) of the managed model.private static EASyLoggerFactory.EASyLoggerLOGGERprivate MmodelThe model which should be managed by this container.private ModelManagement<M>modelManagerThe container holding and managing all models of type <M>.
-
Constructor Summary
Constructors Modifier Constructor Description protectedModelContainer(M model, ModelManagement<M> modelManager, Configuration location)Default constructor of this class.protectedModelContainer(M model, SemanticErrorDescription description, ModelManagement<M> modelManager, Configuration location)Constructor if an Exception occurred during parsing the model.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SemanticErrorDescriptiongetDescription()Getter for theSemanticErrorDescription(describing a caught exception).VersiongetHighestVersion()Returns the highest Version that is available for the managed model.abstract java.io.FilegetLocation()Returns the location, where the model is loaded from.protected java.io.FilegetLocation(Configuration.PathKind kind)Returns the location, where the model is loaded from.MgetModel()Getter for the model.java.lang.StringgetName()Returns the name of the model.VersiongetVersion()Returns the version of the model.booleanisSaveable()Checks whether the model works and can be saved, or if a dummy was used to avoidNullPointerExceptions.java.util.List<ModelInfo<M>>listAvailableModels()Returns a list with all (alternative) models of this model.voidnotifyReplaced(M oldModel, M newModel)Is called to notify thatoldModelis replaced bynewModel.voidregisterModelListener(IModelListener<M> listener)Sets theIModelListenerfor the managed model, to get informed when the model was replaced by the parser.voidsetMainModel(ModelInfo<M> newMainModel)Changes the managed Model.voidunregisterModelListener()Removes the registeredIModelListener.
-
-
-
Field Detail
-
LOGGER
private static final EASyLoggerFactory.EASyLogger LOGGER
-
description
private SemanticErrorDescription description
A optional description of exceptions, caught during parsing the model.
-
modelManager
private ModelManagement<M extends IModel> modelManager
The container holding and managing all models of type <M>.
-
location
private Configuration location
The location (folder) of the managed model.
-
listener
private IModelListener<M extends IModel> listener
OptionalIModelListenerfor getting informed whenever the managed model was replaced by the parser.
-
-
Constructor Detail
-
ModelContainer
protected ModelContainer(M model, ModelManagement<M> modelManager, Configuration location)
Default constructor of this class.- Parameters:
model- The model, which should be managed by this container.modelManager- The container holding and managing all models of type <M>.location- The location (folder) of the managed model.
-
ModelContainer
protected ModelContainer(M model, SemanticErrorDescription description, ModelManagement<M> modelManager, Configuration location)
Constructor if an Exception occurred during parsing the model. The model can be used but not be saved, as long the semantic error is not solved.- Parameters:
model- The model, which should be managed by this container.description- A description of an occurred semantic error while parsing the model. Can be null, then this constructor has the same behavior as#ModelContainer(IModel).modelManager- The container holding and managing all models of type <M>.location- The location (folder) of the managed model.
-
-
Method Detail
-
getModel
public M getModel()
Getter for the model.- Returns:
- Returns the managed model.
-
getVersion
public Version getVersion()
Returns the version of the model.- Specified by:
getVersionin interfaceIModelData- Returns:
- the version, may be null if no version is specified
-
getName
public java.lang.String getName()
Returns the name of the model.- Specified by:
getNamein interfaceIModelData- Returns:
- the name
-
getLocation
protected final java.io.File getLocation(Configuration.PathKind kind)
Returns the location, where the model is loaded from.- Parameters:
kind- Must match to the type of the model (getModel())- Returns:
- The location of the loaded model.
-
getLocation
public abstract java.io.File getLocation()
Returns the location, where the model is loaded from.- Returns:
- The location of the loaded model.
-
getDescription
public SemanticErrorDescription getDescription()
Getter for theSemanticErrorDescription(describing a caught exception).- Returns:
- The
SemanticErrorDescription(describing a caught exception), or null if the model has no semantic errors (i.e. parser errors).
-
isSaveable
public boolean isSaveable()
Checks whether the model works and can be saved, or if a dummy was used to avoidNullPointerExceptions.- Returns:
- true if a loaded model is used and can be saved, false if a dummy was used, which should not be saved.
-
notifyReplaced
public void notifyReplaced(M oldModel, M newModel)
Is called to notify thatoldModelis replaced bynewModel. The listener registrations foroldModelwill be adjusted accordingly.
Do not modify the the listeners ofoldModelornewModelduring this method. If this method is called, the storedgetDescription()will be set to null as this is usually only called if the parser has parsed the model successfully.- Specified by:
notifyReplacedin interfaceIModelListener<M extends IModel>- Parameters:
oldModel- the old model being replacednewModel- the new model (the replacement)
-
getHighestVersion
public Version getHighestVersion()
Returns the highest Version that is available for the managed model.- Returns:
- The highest version that exists within all models stored at the same configFolder (or null if no model exists).
- See Also:
listAvailableModels()
-
listAvailableModels
public java.util.List<ModelInfo<M>> listAvailableModels()
Returns a list with all (alternative) models of this model.- Returns:
- A list with all (alternative) models of this model.
- See Also:
setMainModel(ModelInfo)
-
setMainModel
public void setMainModel(ModelInfo<M> newMainModel)
Changes the managed Model. The model should be add the specified location (getLocation().- Parameters:
newMainModel- The model that should be used by this container.- See Also:
listAvailableModels()
-
registerModelListener
public void registerModelListener(IModelListener<M> listener)
Sets theIModelListenerfor the managed model, to get informed when the model was replaced by the parser.- Parameters:
listener- A listener for the managed model.- See Also:
unregisterModelListener()
-
unregisterModelListener
public void unregisterModelListener()
Removes the registeredIModelListener.- See Also:
registerModelListener(IModelListener)
-
-