Class ModelFileFinderImpl
- java.lang.Object
-
- cern.accsoft.steering.jmad.modeldefs.io.impl.ModelFileFinderImpl
-
- All Implemented Interfaces:
ModelFileFinder
public class ModelFileFinderImpl extends java.lang.Object implements ModelFileFinder
This is the implementation of a class that finds model-files.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cern.accsoft.steering.jmad.modeldefs.io.ModelFileFinder
ModelFileFinder.RepositoryFilePriority
-
-
Constructor Summary
Constructors Constructor Description ModelFileFinderImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getArchivePath(ModelFile modelFile)
puts together the resource path for the filejava.io.File
getFile(ModelFile modelFile, JMadKernel kernel)
returns an accessible file that is searched according to the givenModelFile
, but (in case coming from an archive) extracted in a way that it is unique for the given kerne.java.io.File
getFile(ModelFile modelFile, java.util.function.Function<java.lang.String,java.io.File> tmpFileFunction)
java.util.Optional<java.io.File>
getLocalSourceFile(ModelFile modelFile)
Returns an optional file that is the source of the given model file.ModelFileFinder.RepositoryFilePriority
getRepositoryFilePriority()
java.lang.String
getRepositoryPath(ModelFile modelFile)
puts together the path within the repositoryjava.io.InputStream
getStream(ModelFile modelFile)
returns the content of the model file as input stream.void
setFileUtil(TempFileUtil fileUtil)
void
setModelFilePathOffsets(ModelPathOffsets modelPathOffsets)
the setter for the necessary offsets.void
setPreferences(JMadPreferences preferences)
void
setRepositoryFilePriority(ModelFileFinder.RepositoryFilePriority priority)
set the priority mode for searching repository files.void
setSourceInformation(SourceInformation sourceInformation)
-
-
-
Method Detail
-
setModelFilePathOffsets
public void setModelFilePathOffsets(ModelPathOffsets modelPathOffsets)
the setter for the necessary offsets.- Parameters:
modelPathOffsets
- the offsets to use.
-
getFile
public java.io.File getFile(ModelFile modelFile, JMadKernel kernel)
Description copied from interface:ModelFileFinder
returns an accessible file that is searched according to the givenModelFile
, but (in case coming from an archive) extracted in a way that it is unique for the given kerne. This avoids potential name conflicts between files coming from different model packages used in kernels that are concurrently running.- Specified by:
getFile
in interfaceModelFileFinder
- Parameters:
modelFile
- the instance ofModelFile
which describes where to find the filekernel
- the jmad kernel relative to whose temp path files should be placed.- Returns:
- the file
-
getFile
public java.io.File getFile(ModelFile modelFile, java.util.function.Function<java.lang.String,java.io.File> tmpFileFunction)
-
getStream
public java.io.InputStream getStream(ModelFile modelFile)
Description copied from interface:ModelFileFinder
returns the content of the model file as input stream. This is useful e.g. for copying the file or for packing it into a zip archive.- Specified by:
getStream
in interfaceModelFileFinder
- Parameters:
modelFile
- the model file for which to get the stream- Returns:
- the input stream
-
getLocalSourceFile
public java.util.Optional<java.io.File> getLocalSourceFile(ModelFile modelFile)
Description copied from interface:ModelFileFinder
Returns an optional file that is the source of the given model file. This will return an empty optional in case the source of this model file is not a plain file, but is supposed to be extracted from an archive. In other words, the model definition for which this file finder is responsible is not coming from a file.- Specified by:
getLocalSourceFile
in interfaceModelFileFinder
- Parameters:
modelFile
- the model file for which to retrieve the source file- Returns:
- an optional of the source file for the given model file, or
Optional.empty()
if the source of the model definition does not come from a file
-
getArchivePath
public java.lang.String getArchivePath(ModelFile modelFile)
Description copied from interface:ModelFileFinder
puts together the resource path for the file- Specified by:
getArchivePath
in interfaceModelFileFinder
- Parameters:
modelFile
- theModelFile
for which to put together the resource path- Returns:
- the relative path used in jars below
ModelDefinitionUtil.PACKAGE_OFFSET
and in zip archives.
-
getRepositoryPath
public java.lang.String getRepositoryPath(ModelFile modelFile)
Description copied from interface:ModelFileFinder
puts together the path within the repository- Specified by:
getRepositoryPath
in interfaceModelFileFinder
- Parameters:
modelFile
- the model file for which to put together the path- Returns:
- the absolute path to the file
-
setPreferences
public void setPreferences(JMadPreferences preferences)
-
setFileUtil
public void setFileUtil(TempFileUtil fileUtil)
-
getRepositoryFilePriority
public ModelFileFinder.RepositoryFilePriority getRepositoryFilePriority()
- Specified by:
getRepositoryFilePriority
in interfaceModelFileFinder
- Returns:
- the actual priority mode for searching repository files.
-
setRepositoryFilePriority
public void setRepositoryFilePriority(ModelFileFinder.RepositoryFilePriority priority)
Description copied from interface:ModelFileFinder
set the priority mode for searching repository files.- Specified by:
setRepositoryFilePriority
in interfaceModelFileFinder
- Parameters:
priority
- the new priority
-
setSourceInformation
public void setSourceInformation(SourceInformation sourceInformation)
-
-