Package eu.bandm.tools.util.files
Class SourceHabitats
java.lang.Object
eu.bandm.tools.util.files.SourceHabitats
Organizes a collection of places where to look for resources (=input files).
A sequence of SourceHabitats.SourceHabitat
is maintained which will
be searched for a file, ie. a data source with a certain file name.
Currently this can be a SourceHabitats.SourceHabitat_file
as a pointer
into the file system, or a SourceHabitats.SourceHabitat_resource
as a class
which comes with "resources", eg. in a ".jar" file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Represents the only one data source which has been successfully found for one particular resource nam.class
Represents one of many potential sources which have to be searched for library modules, etc.protected class
Represents a source habitat which is a directory in the file system.protected class
Represents a source habitat which points to a directory, relative to the position of a loaded java class. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final BiConsumer
<String, Object[]> Reports errors only duringappendNewHabitat(String,String)
.static final String
The prefix of all habitat names which are realized by a position in the file system.static final String
The prefix of all habitat names which are realized by a Java class-relative resource.static final String
The separator between the class name and all file name components of resource habitats.protected List
<SourceHabitats.SourceHabitat> List of all habitats to search. -
Constructor Summary
ConstructorsConstructorDescriptionSourceHabitats
(BiConsumer<String, Object[]> msg) Sets the receiver for those error messages which occur only duringappendNewHabitat(String,String)
. -
Method Summary
Modifier and TypeMethodDescriptionReturn a human-readable representation of all places to search.void
appendNewHabitat
(String s, @Opt String additionalErrorText) Service access point for adding a habitat to the end of the search list.protected void
Reports errors only duringappendNewHabitat(String,String)
.protected @Opt SourceHabitats.SourceHabitat
makeHabitat
(String name, @Opt String additionalErrorText) Internal method to check whether the input toappendNewHabitat(String,String)
is consistent.searchAllPlaces
(String name, @Opt BiConsumer<String, Object[]> verbose, String... suffices) Service access point for searching all habitats for the given name of the resource, tested with all given suffixes.
-
Field Details
-
PREFIX_FILE
The prefix of all habitat names which are realized by a position in the file system.- See Also:
-
PREFIX_RESOURCE
The prefix of all habitat names which are realized by a Java class-relative resource.- See Also:
-
RELATIVE_PATH_SEPARATOR
The separator between the class name and all file name components of resource habitats.- See Also:
-
msg
Reports errors only duringappendNewHabitat(String,String)
. -
sourceList
List of all habitats to search. The sequential order stands for priority.
-
-
Constructor Details
-
SourceHabitats
Sets the receiver for those error messages which occur only duringappendNewHabitat(String,String)
.- Parameters:
msg
- the receiver for all messages
-
-
Method Details
-
allPlaces_toString
Return a human-readable representation of all places to search.- Returns:
- a human-readable representation of all places to search.
-
searchAllPlaces
@Opt public @Opt SourceHabitats.FoundSource searchAllPlaces(String name, @Opt @Opt BiConsumer<String, Object[]> verbose, String... suffices) Service access point for searching all habitats for the given name of the resource, tested with all given suffixes. The suffixes are tested faster, i.e. they all are tested in the sequential order of the method argument, for one particular habitat. The habitats are tested in the sequential order of the "add"-calls to this object. Each suffix must include a leading dot (="."), but can also be totally empty.- Parameters:
name
- the file stem to look forverbose
- the receiver for log messagessuffices
- to test for files, in this sequential order- Returns:
- a found file description, or null if no is found
-
appendNewHabitat
Service access point for adding a habitat to the end of the search list. Does so only if consistency checks okay.- Parameters:
s
- name of the habitat according to the defined prefices, seemakeHabitat(java.lang.String, java.lang.String)
.additionalErrorText
- describes the context of the habitat modification attempt
-
error
Reports errors only duringappendNewHabitat(String,String)
.- Parameters:
txt
- the error textargs
- the arguments of the error text
-
makeHabitat
@Opt protected @Opt SourceHabitats.SourceHabitat makeHabitat(String name, @Opt @Opt String additionalErrorText) Internal method to check whether the input toappendNewHabitat(String,String)
is consistent.- Parameters:
name
- the specification where this habitat is found. The prefix decides which subclass ofSourceHabitats.SourceHabitat
is constructed and how the rest of the name is used for searching (file system position or a Java resource). See the doucmentationSourceHabitats.SourceHabitat
.additionalErrorText
- describes the context of the habitat modification attempt.- Returns:
- a new habitat, if the data is consistent
-