Class ModelLocations<M extends IModel>
java.lang.Object
net.ssehub.easy.basics.modelManagement.ModelLocations<M>
- Type Parameters:
M- the specific model type
Manages 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 from
ModelManagement. 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 ClassesModifier and TypeClassDescriptionstatic classRepresents a location with dependent locations (to be considered while loading a model). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<String, ModelLocations.Location> private List<ModelLocations.Location> private IModelManagementRepository<M> -
Constructor Summary
ConstructorsConstructorDescriptionModelLocations(IModelManagementRepository<M> repository) Prevents this class from being instantiated from outside this package. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExcludedLocation(File location) Adds an excluded model location.private ModelLocations.LocationaddLocation(File file, boolean front, ProgressObserver observer) Adds a file location, i.e., a location from where models can be loaded.addLocation(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.addLocationToFront(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 intReturns the number of files in the given location.(package private) intReturns the number of files in all locations.Returns the known default library locations.getLocation(int index) Returns the specified location.intReturns the number of locations configured.private ModelLocations.LocationgetLocationFor(File file) Returns the location forfile.private ModelLocations.LocationgetLocationFor(File file, boolean create) Returns the location forfile.getLocationFor(URI uri) Returns the location foruri.booleanisLocationKnown(File file) Returns whether the specified location is already known.voidremoveExcludedLocation(File location) Removes an excluded model location.voidremoveLocation(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(File file) Removes the location forfilefrom the set of model locations of this instance as well as from all dependent locations.(package private) voidscan(File location, ModelInfoHolder<M> holder, IModelLoader<M> loader, ObservableTask task, Set<File> done) Scans the given location for model information objects.voidupdateLocation(File file, ProgressObserver observer) Updates a file location, i.e., a location from where models can be loaded.voidUpdates all model information for all locations.
-
Field Details
-
knownLocations
-
repository
-
locations
-
excludedLocations
-
-
Constructor Details
-
ModelLocations
ModelLocations(IModelManagementRepository<M> repository) Prevents this class from being instantiated from outside this package.- Parameters:
repository- the model management repository for callbacks
-
-
Method Details
-
clear
void clear()Removes all known model locations. -
addExcludedLocation
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
Removes an excluded model location.- Parameters:
location- the location to be discarded
-
getLocationFor
Returns the location foruri.- Parameters:
uri- the URI to search for- Returns:
- the related location
-
getLocationFor
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
private ModelLocations.Location getLocationFor(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(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 note 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(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(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
Removes 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
Updates 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
Returns whether the specified location is already known.- Parameters:
file- the location to search for- Returns:
trueif it is known,falseelse
-
count
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
Returns the specified location.- Parameters:
index- the index pointing to the desired location- Returns:
- the specified location
- Throws:
IndexOutOfBoundsException- ifindex < 0 || index >=getLocationCount()
-
scan
void scan(File location, ModelInfoHolder<M> holder, IModelLoader<M> loader, ObservableTask task, Set<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
Removes 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
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
Updates all model information for all locations.- Throws:
ModelManagementException- in case that updating fails for some reason
-
getDefaultLibraryLocations
Returns the known default library locations.- Returns:
- the locations
-