Class Path
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.artifactModel.Path
-
- All Implemented Interfaces:
IStringValueProvider,IVilType
- Direct Known Subclasses:
JavaPath
public class Path extends java.lang.Object implements IVilType, IStringValueProvider
Represents a path within a file system (not a folder!).- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPath(java.lang.String path, ArtifactModel model)Creates a path from the given string representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringconcat(java.lang.String string, Path path)Represents the path/string concatenation operation.static java.lang.Stringconcat(Path path, java.lang.String string)Represents the path/string concatenation operation.static Pathconvert(java.lang.String val)Conversion operation.static IFileSystemArtifactconvert(Path path)Converts a path into a file system artifact.Set<IFileSystemArtifact>copy(IFileSystemArtifact target)Copies the artifacts denoted by this path totarget.static Pathcreate(java.lang.String path)Creates a path from the given string representation.static PathcreateInstance(java.io.File file, ArtifactModel model)Creates a path from the given string representation.static PathcreateInstance(java.lang.String path, ArtifactModel model)Creates a path from the given string representation.static PathcreateInstance(Path path, ArtifactModel model)Creates a path from the given (relative)pathand directly localizes it intomodel.voiddelete()Deletes the underlying artifact.voiddeleteAll()Deletes all files in the given path.booleanexists()Returns whether this artifact is exists.java.io.FilegetAbsolutePath()Returns the absolute path with respect tomodel.private java.io.FilegetAbsolutePath(java.io.File base)Returns the absolute path.ArtifactModelgetArtifactModel()Returns the containing artifact model.java.lang.StringgetName()Returns the simple name of this artifact.PathgetParent()Returns the parent of this path.java.lang.StringgetPath()Returns the path represented by this instance.java.lang.StringgetPathSegments()Returns the path segments of this path (excluding the names).java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.booleanisPattern()Returns whether this path is a pattern.booleanisTemporary()Returns whether this path is considered to be temporary.longlastModification()Returns the last modification timestamp of this artifact.private static PathlookupOrCreate(java.lang.String path, ArtifactModel model)Looks up the given path in the path cache or creates a new path object registering it in the path cache ofmodel.private static booleanmatch(Path pattern, Path path, boolean prefix)Convert the paths into absolute normalized paths and match or test for prefix equality.booleanmatches(Path path)Returns whether this path matches the given path.voidmkdir()Creates the directories pointing to path.Set<IFileSystemArtifact>move(IFileSystemArtifact target)Moves the artifacts denoted by this path totarget.Pathrename(java.lang.String name)Renames the underlying artifact and returns a new path if necessary.Set<FileArtifact>selectAll()Selects all file artifacts represented by this path.Set<FileArtifact>selectByKind(java.lang.Class<?> type)Does type selection of artifacts by sub-typing.Set<FileArtifact>selectByType(java.lang.Class<?> type)Does type selection of artifacts by type equality.java.lang.StringtoAbsoluteOSPath()Turns this path into an absolute native OS path.JavaPathtoJavaPath()Turns this path into a java package name.JavaPathtoJavaPath(java.lang.String prefixRegEx)Turns this path into a java package name.java.lang.StringtoOSPath()Turns this path into a relative native OS path.java.lang.StringtoString()Set<FileArtifact>typeReject(java.lang.Class<?> type)Does type selection of artifacts by not matched sub-typing.
-
-
-
Field Detail
-
SEPARATOR
public static final java.lang.String SEPARATOR
- See Also:
- Constant Field Values
-
DUMMY
public static final Path DUMMY
-
path
private java.lang.String path
-
model
private ArtifactModel model
-
-
Constructor Detail
-
Path
protected Path(java.lang.String path, ArtifactModel model)Creates a path from the given string representation. A path may be a (regular) pattern!- Parameters:
path- the path to construct the path object frommodel- the artifact model as a basis for relative paths
-
-
Method Detail
-
createInstance
public static Path createInstance(Path path, ArtifactModel model)
Creates a path from the given (relative)pathand directly localizes it intomodel. A path may be a (regular) pattern!- Parameters:
path- the path to construct this path object frommodel- the artifact model as a basis for relative paths- Returns:
- the created path
-
createInstance
public static Path createInstance(java.lang.String path, ArtifactModel model)
Creates a path from the given string representation. A path may be a (regular) pattern!- Parameters:
path- the path to construct the path object frommodel- the artifact model as a basis for relative paths- Returns:
- the created path
-
createInstance
public static Path createInstance(java.io.File file, ArtifactModel model)
Creates a path from the given string representation. A path may be a (regular) pattern!- Parameters:
file- the file to construct the path frommodel- the artifact model as a basis for relative paths- Returns:
- the created path
-
lookupOrCreate
private static Path lookupOrCreate(java.lang.String path, ArtifactModel model)
Looks up the given path in the path cache or creates a new path object registering it in the path cache ofmodel.- Parameters:
path- the path to create the path object formodel- the artifact model as a basis for relative paths- Returns:
- the created/found path
-
getArtifactModel
public ArtifactModel getArtifactModel()
Returns the containing artifact model.- Returns:
- the containing artifact model
-
create
public static Path create(java.lang.String path) throws VilException
Creates a path from the given string representation. A path may be a (regular) pattern!- Parameters:
path- the path to construct the path object from- Returns:
- the created path object
- Throws:
VilException- in case that the path does not comply to Java conventions
-
getPath
public java.lang.String getPath()
Returns the path represented by this instance. This path may be a pattern.- Returns:
- the represented path
-
getAbsolutePath
public java.io.File getAbsolutePath()
Returns the absolute path with respect tomodel.- Returns:
- the absolute path
-
getParent
public Path getParent()
Returns the parent of this path.- Returns:
- the parent, this if there is no further parent
-
getAbsolutePath
private java.io.File getAbsolutePath(java.io.File base)
Returns the absolute path.- Parameters:
base- the base path for turning relative paths into absolute paths- Returns:
- the absolute path
-
isPattern
public boolean isPattern()
Returns whether this path is a pattern.- Returns:
trueif it is a pattern,falseelse
-
toJavaPath
public JavaPath toJavaPath() throws VilException
Turns this path into a java package name.- Returns:
- the related java Package name
- Throws:
VilException- in case that the related Java path cannot be created
-
toJavaPath
public JavaPath toJavaPath(java.lang.String prefixRegEx) throws VilException
Turns this path into a java package name.- Parameters:
prefixRegEx- an optional regular expression (intended for path prefixes) to be replaced by the empty string (may be null)- Returns:
- the related java Package name
- Throws:
VilException- in case that the related Java path cannot be created
-
toOSPath
public java.lang.String toOSPath()
Turns this path into a relative native OS path.- Returns:
- the native OS path as a string
-
toAbsoluteOSPath
public java.lang.String toAbsoluteOSPath() throws VilExceptionTurns this path into an absolute native OS path.- Returns:
- the native OS path as a string
- Throws:
VilException- in case that accessing the absolute path fails
-
deleteAll
public void deleteAll() throws VilExceptionDeletes all files in the given path.- Throws:
VilException- in case of I/O problems
-
mkdir
public void mkdir() throws VilExceptionCreates the directories pointing to path.- Throws:
VilException- in case of a pattern path or if access to the absolute path fails
-
convert
public static Path convert(java.lang.String val)
Conversion operation.- Parameters:
val- the value to be converted- Returns:
- the converted value
-
convert
public static IFileSystemArtifact convert(Path path) throws VilException
Converts a path into a file system artifact.- Parameters:
path- the path to be converted- Returns:
- the resulting artifact
- Throws:
VilException- in case of problems
-
matches
public boolean matches(Path path)
Returns whether this path matches the given path.- Parameters:
path- the path to check the match for- Returns:
trueof the match is positive,falseelse
-
match
private static boolean match(Path pattern, Path path, boolean prefix)
Convert the paths into absolute normalized paths and match or test for prefix equality.- Parameters:
pattern- the path representing the patternpath- the path to be matchedprefix- do a prefix check ofpatterninpathor matchpatternas ANT pattern inpath- Returns:
trueifpathmatchespattern,falseelse
-
selectByType
public Set<FileArtifact> selectByType(java.lang.Class<?> type)
Does type selection of artifacts by type equality.- Parameters:
type- the target type- Returns:
- the selected artifacts (the type will be adjusted to the actual
type of
type)
-
selectByKind
public Set<FileArtifact> selectByKind(java.lang.Class<?> type)
Does type selection of artifacts by sub-typing.- Parameters:
type- the target type- Returns:
- the selected artifacts (the type will be adjusted to the actual
type of
type)
-
typeReject
public Set<FileArtifact> typeReject(java.lang.Class<?> type)
Does type selection of artifacts by not matched sub-typing.- Parameters:
type- the target type- Returns:
- the selected artifacts (the type will be adjusted to the actual
type of
type)
-
selectAll
public Set<FileArtifact> selectAll()
Selects all file artifacts represented by this path.- Returns:
- all file artifacts represented by path
-
concat
public static java.lang.String concat(Path path, java.lang.String string)
Represents the path/string concatenation operation.- Parameters:
path- the Path to be consideredstring- the String to be considered- Returns:
- path + string
-
concat
public static java.lang.String concat(java.lang.String string, Path path)Represents the path/string concatenation operation.- Parameters:
string- the String to be consideredpath- the Path to be considered- Returns:
- string + path
-
getStringValue
public java.lang.String getStringValue(IStringValueProvider.StringComparator comparator)
Description copied from interface:IStringValueProviderReturns the string value of this object.- Specified by:
getStringValuein interfaceIStringValueProvider- Parameters:
comparator- if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned- Returns:
- the string value
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
lastModification
public long lastModification()
Returns the last modification timestamp of this artifact.- Returns:
- the last modification timestamp, 0 if unknown
-
exists
public boolean exists()
Returns whether this artifact is exists.- Returns:
trueif this artifact exists,falseelse
-
delete
public void delete() throws VilExceptionDeletes the underlying artifact. Handles patterns throughArtifactModel.delete(Path).- Throws:
VilException- in case that deletion fails
-
getName
public java.lang.String getName() throws VilExceptionReturns the simple name of this artifact.- Returns:
- the simple name
- Throws:
VilException- in case that the operation cannot continue
-
getPathSegments
public java.lang.String getPathSegments()
Returns the path segments of this path (excluding the names).- Returns:
- the path segments
-
rename
public Path rename(java.lang.String name) throws VilException
Renames the underlying artifact and returns a new path if necessary.- Parameters:
name- the new name (absolute or relative)- Returns:
- the new path reflecting the replaced artifact
- Throws:
VilException- in case that renaming fails
-
isTemporary
public boolean isTemporary()
Returns whether this path is considered to be temporary.- Returns:
trueif it is temporary,falseelse
-
copy
public Set<IFileSystemArtifact> copy(IFileSystemArtifact target) throws VilException
Copies the artifacts denoted by this path totarget.- Parameters:
target- the target artifact- Returns:
- the created or touched artifacts
- Throws:
VilException- in case that file system operations or artifact model operations fail
-
move
public Set<IFileSystemArtifact> move(IFileSystemArtifact target) throws VilException
Moves the artifacts denoted by this path totarget.- Parameters:
target- the target artifact- Returns:
- the created or touched artifacts
- Throws:
VilException- in case that file system operations or artifact model operations fail
-
-