Class ModelLocations<M extends IModel>
- java.lang.Object
-
- net.ssehub.easy.basics.modelManagement.ModelLocations<M>
-
- Type Parameters:
M- the specific model type
public class ModelLocations<M extends IModel> extends java.lang.ObjectManages the model locations. Locations are stored in terms of a list, which also defines the model resolution sequence. This class is not intended to be instantiated directly rather than being created fromModelManagement. Please not that each individual location is considered recursively, i.e., nested folders will be considered automatically and do not need to be added separately.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classModelLocations.LocationRepresents a location with dependent locations (to be considered while loading a model).
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.io.File>excludedLocationsprivate java.util.Map<java.lang.String,ModelLocations.Location>knownLocationsprivate java.util.List<ModelLocations.Location>locationsprivate IModelManagementRepository<M>repository
-
Constructor Summary
Constructors Constructor Description ModelLocations(IModelManagementRepository<M> repository)Prevents this class from being instantiated from outside this package.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExcludedLocation(java.io.File location)Adds an excluded model location.private ModelLocations.LocationaddLocation(java.io.File file, boolean front, ProgressObserver observer)Adds a file location, i.e., a location from where models can be loaded.ModelLocations.LocationaddLocation(java.io.File file, ProgressObserver observer)Adds a file location to the end of the list of locations, i.e., a location from where models can be loaded.ModelLocations.LocationaddLocationToFront(java.io.File file, ProgressObserver observer)Adds a file location, i.e., a location from where models can be loaded.(package private) voidclear()Removes all known model locations.private static intcount(java.io.File location, java.util.Set<java.io.File> excludedLocations)Returns the number of files in the given location.(package private) intcountFilesInLocations()Returns the number of files in all locations.ModelLocations.LocationgetLocation(int index)Returns the specified location.intgetLocationCount()Returns the number of locations configured.private ModelLocations.LocationgetLocationFor(java.io.File file)Returns the location forfile.private ModelLocations.LocationgetLocationFor(java.io.File file, boolean create)Returns the location forfile.ModelLocations.LocationgetLocationFor(java.net.URI uri)Returns the location foruri.booleanisLocationKnown(java.io.File file)Returns whether the specified location is already known.voidremoveExcludedLocation(java.io.File location)Removes an excluded model location.voidremoveLocation(java.io.File file, ProgressObserver observer)Removes a file location, i.e.(package private) voidremoveLocation(ModelLocations.Location location)Removes the given location from the set of model locations of this instance as well as from all dependent locations.voidremoveLocation(ModelLocations.Location location, ProgressObserver observer)Removes a location, i.e.(package private) voidremoveLocationFor(java.io.File file)Removes the location forfilefrom the set of model locations of this instance as well as from all dependent locations.(package private) voidscan(java.io.File location, ModelInfoHolder<M> holder, IModelLoader<M> loader, ObservableTask task, java.util.Set<java.io.File> done)Scans the given location for model information objects.voidupdateLocation(java.io.File file, ProgressObserver observer)Updates a file location, i.e., a location from where models can be loaded.voidupdateModelInformation()Updates all model information for all locations.
-
-
-
Field Detail
-
knownLocations
private java.util.Map<java.lang.String,ModelLocations.Location> knownLocations
-
repository
private IModelManagementRepository<M extends IModel> repository
-
locations
private java.util.List<ModelLocations.Location> locations
-
excludedLocations
private java.util.Set<java.io.File> excludedLocations
-
-
Constructor Detail
-
ModelLocations
ModelLocations(IModelManagementRepository<M> repository)
Prevents this class from being instantiated from outside this package.- Parameters:
repository- the model management repository for callbacks
-
-
Method Detail
-
clear
void clear()
Removes all known model locations.
-
addExcludedLocation
public void addExcludedLocation(java.io.File location)
Adds an excluded model location. The location disables all contained locations and will be considered with the next update of the file information (already known models will not be discarded).- Parameters:
location- the location to be excluded
-
removeExcludedLocation
public void removeExcludedLocation(java.io.File location)
Removes an excluded model location.- Parameters:
location- the location to be discarded
-
getLocationFor
public ModelLocations.Location getLocationFor(java.net.URI uri)
Returns the location foruri.- Parameters:
uri- the URI to search for- Returns:
- the related location
-
getLocationFor
private ModelLocations.Location getLocationFor(java.io.File file) throws ModelManagementException
Returns the location forfile.- Parameters:
file- the file to return the location for- Returns:
- the location (or null if the related location is currently not known)
- Throws:
ModelManagementException- in case thatfilecannot be accessed / resolved- See Also:
getLocationFor(File, boolean)
-
getLocationFor
private ModelLocations.Location getLocationFor(java.io.File file, boolean create) throws ModelManagementException
Returns the location forfile.- Parameters:
file- the file to return the location forcreate-trueif a location shall be created forfileif no location is known,falseif no new location shall be created- Returns:
- the location related to
file, may be null depending oncreate - Throws:
ModelManagementException- in case thatfilecannot be accessed / resolved
-
addLocation
public ModelLocations.Location addLocation(java.io.File file, ProgressObserver observer) throws ModelManagementException
Adds a file location to the end of the list of locations, i.e., a location from where models can be loaded. Please not thatfileis considered recursively, i.e., nested folders will be considered automatically and do not need to be added separately.- Parameters:
file- the file location (null is ignored)observer- an optional progress observer (useProgressObserver.NO_OBSERVERbut not null in case that no observation is intended)- Returns:
- the actual location object corresponding to
file - Throws:
ModelManagementException- in case that the available information may be come inconsistent due to the new location or thatfilecannot be accessed / resolved
-
addLocationToFront
public ModelLocations.Location addLocationToFront(java.io.File file, ProgressObserver observer) throws ModelManagementException
Adds a file location, i.e., a location from where models can be loaded. Please not thatfileis considered recursively, i.e., nested folders will be considered automatically and do not need to be added separately.- Parameters:
file- the file location (null is ignored)observer- an optional progress observer (useProgressObserver.NO_OBSERVERbut not null in case that no observation is intended)- Returns:
- the actual location object corresponding to
file - Throws:
ModelManagementException- in case that the available information may be come inconsistent due to the new location or thatfilecannot be accessed / resolved
-
addLocation
private ModelLocations.Location addLocation(java.io.File file, boolean front, ProgressObserver observer) throws ModelManagementException
Adds a file location, i.e., a location from where models can be loaded. Please not thatfileis considered recursively, i.e., nested folders will be considered automatically and do not need to be added separately.- Parameters:
file- the file location (null is ignored)front- add to the front or the end of the list of locationsobserver- an optional progress observer (useProgressObserver.NO_OBSERVERbut not null in case that no observation is intended)- Returns:
- the actual location object corresponding to
file - Throws:
ModelManagementException- in case that the available information may be come inconsistent due to the new location or thatfilecannot be accessed / resolved
-
removeLocation
public void removeLocation(ModelLocations.Location location, ProgressObserver observer) throws ModelManagementException
Removes a location, i.e. a location from where models can be loaded.- Parameters:
location- the location (null is ignored)observer- an optional progress observer (useProgressObserver.NO_OBSERVERbut not null in case that no observation is intended)- Throws:
ModelManagementException- in case thatfilecannot be accessed
-
removeLocation
public void removeLocation(java.io.File file, ProgressObserver observer) throws ModelManagementExceptionRemoves a file location, i.e. a location from where models can be loaded.- Parameters:
file- the file location (null is ignored)observer- an optional progress observer (useProgressObserver.NO_OBSERVERbut not null in case that no observation is intended)- Throws:
ModelManagementException- in case thatfilecannot be accessed
-
updateLocation
public void updateLocation(java.io.File file, ProgressObserver observer) throws ModelManagementExceptionUpdates a file location, i.e., a location from where models can be loaded. The location must be registered beforehand usingaddLocation(File, ProgressObserver).- Parameters:
file- the file location (null is ignored)observer- an optional progress observer (useProgressObserver.NO_OBSERVERbut not null in case that no observation is intended)- Throws:
ModelManagementException- in case that the available information may be come inconsistent due to the new location orfilecannot be accessed
-
isLocationKnown
public boolean isLocationKnown(java.io.File file)
Returns whether the specified location is already known.- Parameters:
file- the location to search for- Returns:
trueif it is known,falseelse
-
count
private static int count(java.io.File location, java.util.Set<java.io.File> excludedLocations)Returns the number of files in the given location.- Parameters:
location- the location to scanexcludedLocations- explicitly excluded locations (may be null if no locations shall be excluded)- Returns:
- the number of files
-
countFilesInLocations
int countFilesInLocations()
Returns the number of files in all locations.- Returns:
- the number of files in all locations
-
getLocationCount
public int getLocationCount()
Returns the number of locations configured.- Returns:
- the number of locations
-
getLocation
public ModelLocations.Location getLocation(int index)
Returns the specified location.- Parameters:
index- the index pointing to the desired location- Returns:
- the specified location
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getLocationCount()
-
scan
void scan(java.io.File location, ModelInfoHolder<M> holder, IModelLoader<M> loader, ObservableTask task, java.util.Set<java.io.File> done)Scans the given location for model information objects.- Parameters:
location- the location to scanholder- the combined information and result collection instanceloader- the specific loader to consider (may be null)task- the task to be informeddone- records visited directories in order to avoid unintended looping
-
removeLocationFor
void removeLocationFor(java.io.File file) throws ModelManagementExceptionRemoves the location forfilefrom the set of model locations of this instance as well as from all dependent locations.- Parameters:
file- the file pointing to the location- Throws:
ModelManagementException- in case thatfilecannot be resolved
-
removeLocation
void removeLocation(ModelLocations.Location location)
Removes the given location from the set of model locations of this instance as well as from all dependent locations.- Parameters:
location- the location to be removed
-
updateModelInformation
public void updateModelInformation() throws ModelManagementExceptionUpdates all model information for all locations.- Throws:
ModelManagementException- in case that updating fails for some reason
-
-