Class ArtifactModel
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.artifactModel.ArtifactModel
-
public class ArtifactModel extends java.lang.ObjectImplements the artifact model starting at a certain file root. However, the artifact model may also contain related artifacts outside the base directory subtree which must then be absolute. Typically, an artifact model will be created up incrementally but may be created in one step usingscanAll(ProgressObserver).- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.Filebaseprivate java.lang.StringbasePathprivate java.util.TreeMap<java.lang.String,IFileSystemArtifact>fileArtifactsprivate java.util.TreeMap<java.lang.Object,IArtifact>otherArtifactsprivate java.util.Map<java.lang.String,Path>pathCacheprivate java.util.Map<ProjectSettings,java.lang.Object>settings
-
Constructor Summary
Constructors Constructor Description ArtifactModel(java.io.File base)Creates an artifact model instance as instantiation environment.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidafterRename(IFileSystemArtifact artifact)Called after rename in order to create the changed artifacts.(package private) voidafterRename(Path path)Called after a path was renamed.(package private) voidbeforeRename(IFileSystemArtifact artifact)Called before renaming an artifact to cleanup.(package private) voidbeforeRename(Path path)Called before a path is renamed, i.e., it is about to be renamed.(package private) voidclear()Clears this artifact.(package private) voiddelete(java.io.File path)Deletes a path and possible related artifacts.(package private) voiddelete(Path path)Deletes a path and possible related artifacts.(package private) voiddiscardPath(Path path)Discards a path before it becomes invalid, e.g., as its scope is discarded during execution.(package private) IArtifactgetArtifact(java.lang.Object real)Returns a known artifact.java.io.FilegetBase()Returns the base directory.java.lang.StringgetBasePath()Returns the (absolute) base path ofgetBase().(package private) PathgetPathFromCache(java.lang.String pathKey)Returns a path from the path cache.private java.lang.StringgetPathKey(Path path)Returns the internal path cache key forpath.java.lang.ObjectgetSettings(ProjectSettings key)Returns the settings object for the specified key.(package private) inthandles(java.lang.Object real)Returns whether this artifact model handles the given real object.private static booleanisOfType(java.lang.Class<?> type, IFileSystemArtifact artifact, boolean byKind, boolean negate)Returns whether type selection matches.(package private) java.lang.StringmakeRelative(java.io.File file)Makes the givenfilerelative to this model.(package private) static java.lang.StringmakeRelative(java.io.File file, ArtifactModel model)Makes the givenfilerelative to the givenmodel.(package private) java.lang.StringmakeRelative(java.lang.String path)Makes the givenpathrelative to this model.(package private) static java.lang.StringmakeRelative(java.lang.String path, ArtifactModel model)Makes the givenpathrelative to the givenmodel.(package private) java.lang.StringmakeRelativeFile(java.io.File file)Makes the givenfilerelative to this model.private static booleanmatchesPath(Path path, IFileSystemArtifact artifact)Returns whether the givenpath(may be a pattern) matches the path ofartifact.(package private) booleanregister(java.lang.Object real, IArtifact artifact)Registers a given artifact created by the artifact factory.(package private) voidregisterPath(Path path)Called if a path is created.private intscanAll(java.io.File location, int count, ProgressObserver observer, ProgressObserver.ITask task, java.util.List<VilException> errors)Processes all files inlocationin a recursive manner.voidscanAll(ProgressObserver observer)Scans the entire environment starting atroot.Set<FolderArtifact>selectAllFolders()Returns all artifacts.Set<FileArtifact>selectByKind(java.lang.Class<?> type, boolean negate)Does type selection of artifacts by subtyping.Set<FileArtifact>selectByName(java.lang.String name)Does name selection of artifacts.(package private) voidselectByName(java.util.regex.Pattern pattern, java.lang.String name, java.util.List<FileArtifact> result)Does type selection of artifacts based onpathandtype.Set<FileArtifact>selectByType(java.lang.Class<?> type, boolean negate)Does type selection of artifacts by type equality.(package private) voidselectByType(Path path, java.lang.Class<?> type, java.util.List<FileArtifact> result, boolean byKind, boolean negate)Does type selection of artifacts based onpathandtype.voidsetSettings(ProjectSettings key, java.lang.Object object)Sets the settings for the artifact model.
-
-
-
Field Detail
-
base
private java.io.File base
-
basePath
private java.lang.String basePath
-
fileArtifacts
private java.util.TreeMap<java.lang.String,IFileSystemArtifact> fileArtifacts
-
otherArtifacts
private java.util.TreeMap<java.lang.Object,IArtifact> otherArtifacts
-
settings
private java.util.Map<ProjectSettings,java.lang.Object> settings
-
pathCache
private java.util.Map<java.lang.String,Path> pathCache
-
-
Method Detail
-
getBase
public java.io.File getBase()
Returns the base directory.- Returns:
- the base directory
-
getBasePath
public java.lang.String getBasePath()
Returns the (absolute) base path ofgetBase().- Returns:
- the absolute base path
-
scanAll
public void scanAll(ProgressObserver observer) throws VilException
Scans the entire environment starting atroot.- Parameters:
observer- the observer to be notified in case of progress, useProgressObserver.NO_OBSERVERif progress shall not be monitored- Throws:
VilException- in case that creating / obtaining artifacts fails
-
scanAll
private int scanAll(java.io.File location, int count, ProgressObserver observer, ProgressObserver.ITask task, java.util.List<VilException> errors)Processes all files inlocationin a recursive manner. May be used to count the number of files to be processed.- Parameters:
location- the location to be scannedcount- the number of files counted so far (call initially with0)observer- the progress observer (do not create artifacts if this is null)task- the progress task (ignored if null)errors- exceptions caught during scanning (do not create artifacts if this is null)- Returns:
- the number of files processed
- See Also:
ArtifactFactory.createFileSystemArtifact(File)
-
selectAllFolders
public Set<FolderArtifact> selectAllFolders()
Returns all artifacts.- Returns:
- the selected artifacts
-
selectByType
public Set<FileArtifact> selectByType(java.lang.Class<?> type, boolean negate)
Does type selection of artifacts by type equality.- Parameters:
type- the target typenegate- negate the selection- Returns:
- the selected artifacts (the type will be adjusted to the actual
type of
type)
-
selectByKind
public Set<FileArtifact> selectByKind(java.lang.Class<?> type, boolean negate)
Does type selection of artifacts by subtyping.- Parameters:
type- the target typenegate- negate the selection- Returns:
- the selected artifacts (the type will be adjusted to the actual
type of
type)
-
selectByName
public Set<FileArtifact> selectByName(java.lang.String name)
Does name selection of artifacts.- Parameters:
name- the regular name pattern for artifact selection- Returns:
- the selected artifacts
-
selectByName
void selectByName(java.util.regex.Pattern pattern, java.lang.String name, java.util.List<FileArtifact> result)Does type selection of artifacts based onpathandtype.- Parameters:
pattern- an optional regular expression to be matched (may be null)name- the name used to build the pattern used as fallback ifpatternis nullresult- to be modified as a side effect
-
selectByType
void selectByType(Path path, java.lang.Class<?> type, java.util.List<FileArtifact> result, boolean byKind, boolean negate)
Does type selection of artifacts based onpathandtype.- Parameters:
path- the path to be considered for selection (may be null)type- the type to be considered (may be null, than this parameter is ignored)result- to be modified as a side effectbyKind- do the selection by subtyping (true) or by equality (false)negate- negate the selection
-
isOfType
private static boolean isOfType(java.lang.Class<?> type, IFileSystemArtifact artifact, boolean byKind, boolean negate)Returns whether type selection matches.- Parameters:
type- the type to be considered (may be null, than this parameter is ignored)artifact- the artifact to testbyKind- do the selection by subtyping (true) or by equality (false)negate- negate the result- Returns:
trueif types match,falseelse
-
matchesPath
private static boolean matchesPath(Path path, IFileSystemArtifact artifact)
Returns whether the givenpath(may be a pattern) matches the path ofartifact.- Parameters:
path- the path to be considered (as pattern)artifact- the artifact to be matched against the pattern- Returns:
trueif it matches,falseelse
-
register
boolean register(java.lang.Object real, IArtifact artifact)Registers a given artifact created by the artifact factory.- Parameters:
real- the real underlying artifactartifact- the artifact to be registered- Returns:
trueif the artifact was registered,falseelse
-
makeRelativeFile
java.lang.String makeRelativeFile(java.io.File file)
Makes the givenfilerelative to this model.- Parameters:
file- the file to make relative- Returns:
- the normalized and relative file if this model matches as prefix, the normalized absolute file path else
-
makeRelative
java.lang.String makeRelative(java.io.File file)
Makes the givenfilerelative to this model.- Parameters:
file- the file to make relative- Returns:
- the normalized and relative path if this model matches as prefix, the normalized absolute file else
-
makeRelative
java.lang.String makeRelative(java.lang.String path)
Makes the givenpathrelative to this model.- Parameters:
path- the path to make relative- Returns:
- the normalized and relative path if this model matches as prefix, the normalized absolute file else
-
makeRelative
static java.lang.String makeRelative(java.lang.String path, ArtifactModel model)Makes the givenpathrelative to the givenmodel.- Parameters:
path- the path to make relativemodel- the model to consider (may be null)- Returns:
- the normalized and relative path if
modelis given and matches as prefix, the normalized absolute file else
-
makeRelative
static java.lang.String makeRelative(java.io.File file, ArtifactModel model)Makes the givenfilerelative to the givenmodel.- Parameters:
file- the file to make relativemodel- the model to consider (may be null)- Returns:
- the normalized and relative path if
modelis given and matches as prefix, the normalized absolute file else
-
getArtifact
IArtifact getArtifact(java.lang.Object real)
Returns a known artifact.- Parameters:
real- the real underlying artifact- Returns:
- the artifact or null if no artifact is known for
real
-
handles
int handles(java.lang.Object real)
Returns whether this artifact model handles the given real object.- Parameters:
real- the real object- Returns:
- a numeric value allowing to rank multiple artifact models handling
real, i.e., 0 if it does not handle, 1 if it basically handles, a larger number for higher priority (e.g., the length ofbasePath)
-
delete
void delete(java.io.File path)
Deletes a path and possible related artifacts.- Parameters:
path- the path being deleted
-
getPathKey
private java.lang.String getPathKey(Path path)
Returns the internal path cache key forpath.- Parameters:
path- the path- Returns:
- the path cache key
-
discardPath
void discardPath(Path path)
Discards a path before it becomes invalid, e.g., as its scope is discarded during execution.- Parameters:
path- the path to discard
-
getPathFromCache
Path getPathFromCache(java.lang.String pathKey)
Returns a path from the path cache.- Parameters:
pathKey- the path key (normalized path)- Returns:
- the path (may be null if unknown)
-
registerPath
void registerPath(Path path)
Called if a path is created.- Parameters:
path- the path to discard
-
beforeRename
void beforeRename(IFileSystemArtifact artifact) throws VilException
Called before renaming an artifact to cleanup.- Parameters:
artifact- the artifact being renamed- Throws:
VilException- in case of problems obtaining the path
-
afterRename
void afterRename(IFileSystemArtifact artifact) throws VilException
Called after rename in order to create the changed artifacts.- Parameters:
artifact- the renamed artifact- Throws:
VilException- in case of problems obtaining the path
-
beforeRename
void beforeRename(Path path)
Called before a path is renamed, i.e., it is about to be renamed.- Parameters:
path- the path
-
afterRename
void afterRename(Path path)
Called after a path was renamed.- Parameters:
path- the path
-
delete
void delete(Path path)
Deletes a path and possible related artifacts. This method is called fromPath.- Parameters:
path- the path being deleted
-
clear
void clear()
Clears this artifact. For internal use only.
-
setSettings
public void setSettings(ProjectSettings key, java.lang.Object object)
Sets the settings for the artifact model.- Parameters:
key- ID for the settings objectobject- the settings
-
getSettings
public java.lang.Object getSettings(ProjectSettings key)
Returns the settings object for the specified key.- Parameters:
key- the key assigned to the settings object- Returns:
- the settings object
-
-