M - the specific model typepublic abstract class ModelManagement<M extends IModel>
extends java.lang.Object
IModelLoader. Public access shall be synchronized (in any way) as multiple
source parts and tools may access the information concurrently. Please note that specific
information and settings are available via availableModels(),
events(), loaders(), locale() and locations().
The model needs a loader and a location to operate. After providing this
information, available models can be accessed via availableModels().| Modifier and Type | Field and Description |
|---|---|
private AvailableModels<M> |
availableModels |
private ModelEvents<M> |
events |
private boolean |
inUpdate |
private ModelLoaders<M> |
loaders |
private java.util.Set<ModelInfo<M>> |
loading |
private ModelLocale |
locale |
private ModelLocations<M> |
locations |
private static EASyLoggerFactory.EASyLogger |
LOGGER |
private java.util.List<M> |
models |
private java.util.Set<ModelInfo<M>> |
outdated |
private ModelRepository<M> |
repository |
private Pool<ImportResolver<M>> |
resolverPool |
| Modifier | Constructor and Description |
|---|---|
protected |
ModelManagement()
Singleton.
|
| Modifier and Type | Method and Description |
|---|---|
AvailableModels<M> |
availableModels()
Returns access to the available models.
|
void |
clear()
Clears all loaded models, available models (
availableModels()),
and model locations (locations()). |
(package private) void |
clearLocation(java.io.File file,
ProgressObserver observer)
Removes a file location, i.e. a location from where models can be loaded.
|
void |
clearModel(M model)
Clears
model from the caches. |
void |
clearModel(ModelInfo<M> info)
Clears
info (and the related model) from the caches. |
protected abstract ImportResolver<M> |
createResolver()
Creates a resolver instance.
|
ModelEvents<M> |
events()
Provides access to the event mechanisms.
|
java.util.List<VersionedModelInfos<M>> |
getAvailable(java.lang.String name)
Returns models available for a given model
name. |
M |
getModel(int index)
Returns the specified model.
|
int |
getModelCount()
Returns the number of (known) models.
|
ImportResolver<M> |
getResolverFromPool()
Returns the current top-level resolver.
|
boolean |
isLoading(ModelInfo<M> info)
Returns whether loading the model for
infois currently happening. |
boolean |
isLoading(java.net.URI location)
Returns whether loading a model from
location is currently happening. |
boolean |
isOutdated(M model)
Returns whether a model is outdated (will force a reload upon
load(ModelInfo)). |
boolean |
isOutdated(ModelInfo<M> info)
Returns whether a model information is outdated (will force a reload upon
load(ModelInfo)). |
M |
load(ModelInfo<M> info)
Loads the specified model and resolves its imports.
|
private M |
load(ModelInfo<M> info,
boolean force)
Loads the specified model and resolves its imports by calling
resolveImports(M, java.net.URI, java.util.List<net.ssehub.easy.basics.modelManagement.ModelInfo<M>>). |
(package private) M |
load(ModelInfo<M> info,
ImportResolver<M> resolver,
java.util.List<IMessage> messages)
Loads the model related to
info. |
(package private) M |
load(ModelInfo<M> info,
java.util.List<IMessage> messages)
Loads the model related to
info with a new default import resolver. |
ModelLoaders<M> |
loaders()
Provides access to the model loaders.
|
ModelLocale |
locale()
Provides access to the internationalization mechanisms.
|
ModelLocations<M> |
locations()
Provides access to the model location.
|
private void |
notifyLoading(ModelInfo<M> info,
boolean started)
Handles the notification about model loading.
|
void |
outdateAll()
Unresolves all models / forces reload.
|
protected void |
postLoadModel(ModelInfo<M> info)
Additional code to be executed after a model was loaded.
|
void |
releaseResolver(ImportResolver<M> resolver)
Releases a given resolver instance.
|
private void |
reload(java.util.List<M> models)
Loads a set of models.
|
M |
reload(M model)
Update the given model by trying to reload it.
|
M |
reload(M model,
boolean deepReload)
Update the given model by trying to reload it.
|
protected ModelRepository<M> |
repository()
Returns the repository instance.
|
M |
resolve(java.lang.String modelName,
IVersionRestriction restriction,
java.net.URI baseURI,
IRestrictionEvaluationContext evaluationContext)
Resolves the denoted model considering the given
restrictions. |
java.util.List<IMessage> |
resolveImports(M model,
java.net.URI uri,
java.util.List<ModelInfo<M>> inProgress)
Resolves the imports of the given
model with transitive loading and returns
messages on failures. |
java.util.List<IMessage> |
resolveImports(M model,
java.net.URI uri,
java.util.List<ModelInfo<M>> inProgress,
boolean transitiveLoading)
Resolves the imports of the given
model and returns
messages on failures. |
java.util.List<IMessage> |
resolveImports(M model,
java.net.URI uri,
java.util.List<ModelInfo<M>> inProgress,
ImportResolver<M> resolver)
Resolves the imports of the given
model with transitive loading and returns
messages on failures. |
java.util.List<IMessage> |
resolveImports(M model,
java.net.URI uri,
java.util.List<ModelInfo<M>> inProgress,
ImportResolver<M> resolver,
boolean transitiveLoading)
Resolves the imports of the given
model and returns
messages on failures. |
void |
setOutdated(M model)
Declears a model as outdated (will force a reload upon
load(ModelInfo)). |
void |
setOutdated(ModelInfo<M> info)
Returns whether a model information is outdated.
|
private M |
setResolved(ModelInfo<M> info,
M model)
Defines the resolution for
info and calls the listeners. |
int |
unload(M model,
ProgressObserver observer)
Unloads
model as well as unloadable imported models, but not the related
model information. |
private void |
unloadImpl(M model)
Unloads a certain model.
|
private java.lang.String |
updateAvailableModels(ModelInfoHolder<M> holder)
Updates the list of available models.
|
(package private) void |
updateForLoader(IModelLoader<M> loader,
ProgressObserver observer)
Registers a model loader and updates the model information
provided by the loader.
|
private void |
updateForLoader(ModelLocations.Location location,
IModelLoader<M> loader,
ModelInfoHolder<M> holder,
ObservableTask task,
java.util.Set<ModelLocations.Location> done)
Updates
location via loader. |
void |
updateModel(M model,
java.net.URI uri)
Add a model to this management instance.
|
void |
updateModel(M model,
java.net.URI uri,
IModelLoader<M> loader)
Add a model to this management instance.
|
void |
updateModel(M model,
java.net.URI uri,
IModelLoader<M> loader,
boolean deepReload)
Add a model to this management instance.
|
private void |
updateModelInformation(java.io.File file,
ModelInfoHolder<M> holder,
ProgressObserver observer,
ProgressObserver.ITask task)
Updates the model information in
file considering known. |
void |
updateModelInformation(java.io.File file,
ProgressObserver observer)
Updates the model information in
file. |
private void |
updateModelInformation(ModelLocations.Location location,
ModelInfoHolder<M> holder,
ProgressObserver observer,
ProgressObserver.ITask task,
java.util.Set<ModelLocations.Location> done)
Updates the model information in the given
location and the dependent locations. |
void |
updateModelInformation(ProgressObserver observer)
Updates the model information in all known locations.
|
private static final EASyLoggerFactory.EASyLogger LOGGER
private ModelLocale locale
private AvailableModels<M extends IModel> availableModels
private ModelRepository<M extends IModel> repository
private ModelEvents<M extends IModel> events
private ModelLocations<M extends IModel> locations
private ModelLoaders<M extends IModel> loaders
private transient boolean inUpdate
private Pool<ImportResolver<M extends IModel>> resolverPool
protected abstract ImportResolver<M> createResolver()
public ModelLocale locale()
public ModelEvents<M> events()
public ModelLoaders<M> loaders()
public ModelLocations<M> locations()
public AvailableModels<M> availableModels()
protected ModelRepository<M> repository()
public ImportResolver<M> getResolverFromPool()
releaseResolver(ImportResolver)public void releaseResolver(ImportResolver<M> resolver)
resolver - the resolver to be releasedgetResolverFromPool()public void updateModel(M model, java.net.URI uri, IModelLoader<M> loader)
model - the model to be addeduri - the URI of the model (used for unique identification)loader - The parser able to load modelpublic void updateModel(M model, java.net.URI uri, IModelLoader<M> loader, boolean deepReload)
model - the model to be addeduri - the URI of the model (used for unique identification)loader - The parser able to load modeldeepReload - perform a deep reload of the dependent modelsprivate void reload(java.util.List<M> models)
models - the models to be (re)loaded (entries may be null)public M reload(M model)
model - the model to be reloadedmodel if no new model was loaded)public M reload(M model, boolean deepReload)
model - the model to be reloadeddeepReload - perform a deep reload of the dependent modelsmodel if no new model was loaded)public int unload(M model, ProgressObserver observer) throws ModelManagementException
model as well as unloadable imported models, but not the related
model information. No events will be sent but event listeners will be cleared.
Please note that references within model will not be modified and not managed
by this class after calling this method! Please release all references to model
after calling this method!model - the model to be unloadedobserver - an optional progress observer (use ProgressObserver.NO_OBSERVER but
not null in case that no observation is intended)ModelManagementException - in case that unloading failsprivate void unloadImpl(M model)
model - the model to unloadpublic void updateModel(M model, java.net.URI uri)
model - the model to be addeduri - the URI of the model (used for unique identification)private M setResolved(ModelInfo<M> info, M model)
info and calls the listeners.
Calls IModel.dispose() if needed.info - the information object to be updatedmodel - the resolving modelmodel (may be null if inconsistent
or not yet loaded)public int getModelCount()
public M getModel(int index)
index - the 0-based index of the modeljava.lang.IndexOutOfBoundsException - if
index<=0 || index>=getModelCount()public java.util.List<IMessage> resolveImports(M model, java.net.URI uri, java.util.List<ModelInfo<M>> inProgress)
model with transitive loading and returns
messages on failures. Exceptions might be appropriate here but the
caller shall be able to decide how to handle the level of detail, i.e.
whether the first message shall be emitted or all. May modify model
as a side effect. This method uses a new default import resolver.model - the model to be resolveduri - the URI of the model to resolve (in order to find the closest
model, may be null)inProgress - the model information objects of the models currently being
processed at once (may be null)null or empty if nonepublic java.util.List<IMessage> resolveImports(M model, java.net.URI uri, java.util.List<ModelInfo<M>> inProgress, boolean transitiveLoading)
model and returns
messages on failures. Exceptions might be appropriate here but the
caller shall be able to decide how to handle the level of detail, i.e.
whether the first message shall be emitted or all. May modify model
as a side effect. This method uses a new default import resolver.model - the model to be resolveduri - the URI of the model to resolve (in order to find the closest
model, may be null)inProgress - the model information objects of the models currently being
processed at once (may be null)transitiveLoading - with or without transitive loading (see ImportResolver)null or empty if nonepublic java.util.List<IMessage> resolveImports(M model, java.net.URI uri, java.util.List<ModelInfo<M>> inProgress, ImportResolver<M> resolver)
model with transitive loading and returns
messages on failures. Exceptions might be appropriate here but the
caller shall be able to decide how to handle the level of detail, i.e.
whether the first message shall be emitted or all. May modify model
as a side effect.model - the model to be resolveduri - the URI of the model to resolve (in order to find the closest
model, may be null)inProgress - the model information objects of the models currently being
processed at once (may be null)resolver - the import resolver (may be null to use a new default import resolver)null or empty if nonepublic java.util.List<IMessage> resolveImports(M model, java.net.URI uri, java.util.List<ModelInfo<M>> inProgress, ImportResolver<M> resolver, boolean transitiveLoading)
model and returns
messages on failures. Exceptions might be appropriate here but the
caller shall be able to decide how to handle the level of detail, i.e.
whether the first message shall be emitted or all. May modify model
as a side effect.model - the model to be resolveduri - the URI of the model to resolve (in order to find the closest
model, may be null)inProgress - the model information objects of the models currently being
processed at once (may be null)resolver - the import resolver (may be null to use a new default import resolver)transitiveLoading - with or without transitive loading (see ImportResolver)null or empty if nonepublic M resolve(java.lang.String modelName, IVersionRestriction restriction, java.net.URI baseURI, IRestrictionEvaluationContext evaluationContext) throws ModelManagementException
restrictions. This method uses a new default
import resolver.modelName - the name of the modelrestriction - the restriction (may be null if there is none)baseURI - the URI where to start the resolution at (may be an existing model)evaluationContext - the context for evaluating import restrictions (variable definitions...
interpreted locally)ModelManagementException - in case of resolution failuresM load(ModelInfo<M> info, java.util.List<IMessage> messages)
info with a new default import resolver.info - the model info to load the model formessages - the messages collected so far (modified as a side effect)M load(ModelInfo<M> info, ImportResolver<M> resolver, java.util.List<IMessage> messages)
info.info - the model info to load the model forresolver - the resolver to use (null for a new default import resolver)messages - the messages collected so far (modified as a side effect)private void notifyLoading(ModelInfo<M> info, boolean started)
info - the information object to notify aboutstarted - true if loading started, false elsepublic boolean isLoading(ModelInfo<M> info)
infois currently happening.info - the information object to look fortrue if loading is currently in progress, false elseIModelProcessingListenerpublic boolean isLoading(java.net.URI location)
location is currently happening.location - the location to look fortrue if loading is currently in progress, false elseIModelProcessingListenerprotected void postLoadModel(ModelInfo<M> info) throws java.io.IOException
info - the information object describing the modeljava.io.IOException - in case that loading fails - however, model loading will not failpublic M load(ModelInfo<M> info) throws ModelManagementException
info - the information object of the model to loadModelManagementException - in case of any error during loading infopublic void updateModelInformation(java.io.File file,
ProgressObserver observer)
throws ModelManagementException
file.file - the location folder to searchobserver - an optional progress observer (use ProgressObserver.NO_OBSERVER but
not null in case that no observation is intended)ModelManagementException - in case that the available information
may be come inconsistent due to this updatepublic void updateModelInformation(ProgressObserver observer) throws ModelManagementException
observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but
not null in case that no observation is intended)ModelManagementException - in case that the available information
may be come inconsistent due to this updateprivate void updateModelInformation(ModelLocations.Location location, ModelInfoHolder<M> holder, ProgressObserver observer, ProgressObserver.ITask task, java.util.Set<ModelLocations.Location> done) throws ModelManagementException
location and the dependent locations.location - the location to update the information forholder - the combined information and result collection instanceobserver - an optional progress observer (use ProgressObserver.NO_OBSERVER but
not null in case that no observation is intended)task - the task to run in (may be null in order to start a new task)done - already processed locations (in order to avoid cycles)ModelManagementException - in case that the available information
may be come inconsistent due to this updatevoid updateForLoader(IModelLoader<M> loader, ProgressObserver observer) throws ModelManagementException
loader - the model loader (must not be null)observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but
not null in case that no observation is intended)ModelManagementException - in case that the loader aims at loading
inconsistent informationprivate void updateForLoader(ModelLocations.Location location, IModelLoader<M> loader, ModelInfoHolder<M> holder, ObservableTask task, java.util.Set<ModelLocations.Location> done)
location via loader.location - the location to be updatedholder - the combined information and result collection instanceloader - the specific loader to consider (may be null)task - the task to be informeddone - already processed locations in order to prevent loopsvoid clearLocation(java.io.File file,
ProgressObserver observer)
file - the file location (null is ignored)observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but
not null in case that no observation is intended)public java.util.List<VersionedModelInfos<M>> getAvailable(java.lang.String name)
name.name - the name to search forprivate java.lang.String updateAvailableModels(ModelInfoHolder<M> holder)
holder - the instance containing the resultsprivate void updateModelInformation(java.io.File file,
ModelInfoHolder<M> holder,
ProgressObserver observer,
ProgressObserver.ITask task)
throws ModelManagementException
file considering known.file - the location to searchholder - the combined information and result collection instanceobserver - an optional progress observer (use ProgressObserver.NO_OBSERVER but
not null in case that no observation is intended)task - the task to run in (may be null in order to start a new task)ModelManagementException - in case of model information inconsistenciesprivate M load(ModelInfo<M> info, boolean force) throws ModelManagementException
resolveImports(M, java.net.URI, java.util.List<net.ssehub.easy.basics.modelManagement.ModelInfo<M>>). Be careful when calling
this method from inside this class as it automatically resolves
the imports. Loading an already loaded model does not cause physical
reloading but returns the cached model contents.info - the information object of the model to loadforce - load anywayModelManagementException - in case of any error during loading infopublic void clear()
availableModels()),
and model locations (locations()). This method will not remove any IModelLoaders or
ImportResolvers.public void clearModel(M model)
model from the caches. Please handle with care.model - the model to be clearedpublic void clearModel(ModelInfo<M> info)
info (and the related model) from the caches. Please handle with care.info - the info to be clearedpublic void outdateAll()
public boolean isOutdated(M model)
load(ModelInfo)).model - the model to be tested (may be null)true if it is outdated, false elsepublic boolean isOutdated(ModelInfo<M> info)
load(ModelInfo)).info - the object to be tested (may be null)true if it is outdated, false (also for info==null) elsepublic void setOutdated(M model)
load(ModelInfo)).model - the model to be tested (may be null)Copyright © 2009 - 2018 SSE. All Rights Reserved.