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.StringgetArchivePath(ModelFile modelFile)puts together the resource path for the filejava.io.FilegetFile(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.FilegetFile(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.RepositoryFilePrioritygetRepositoryFilePriority()java.lang.StringgetRepositoryPath(ModelFile modelFile)puts together the path within the repositoryjava.io.InputStreamgetStream(ModelFile modelFile)returns the content of the model file as input stream.voidsetFileUtil(TempFileUtil fileUtil)voidsetModelFilePathOffsets(ModelPathOffsets modelPathOffsets)the setter for the necessary offsets.voidsetPreferences(JMadPreferences preferences)voidsetRepositoryFilePriority(ModelFileFinder.RepositoryFilePriority priority)set the priority mode for searching repository files.voidsetSourceInformation(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:ModelFileFinderreturns 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:
getFilein interfaceModelFileFinder- Parameters:
modelFile- the instance ofModelFilewhich 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:ModelFileFinderreturns 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:
getStreamin 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:ModelFileFinderReturns 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:
getLocalSourceFilein 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:ModelFileFinderputs together the resource path for the file- Specified by:
getArchivePathin interfaceModelFileFinder- Parameters:
modelFile- theModelFilefor which to put together the resource path- Returns:
- the relative path used in jars below
ModelDefinitionUtil.PACKAGE_OFFSETand in zip archives.
-
getRepositoryPath
public java.lang.String getRepositoryPath(ModelFile modelFile)
Description copied from interface:ModelFileFinderputs together the path within the repository- Specified by:
getRepositoryPathin 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:
getRepositoryFilePriorityin interfaceModelFileFinder- Returns:
- the actual priority mode for searching repository files.
-
setRepositoryFilePriority
public void setRepositoryFilePriority(ModelFileFinder.RepositoryFilePriority priority)
Description copied from interface:ModelFileFinderset the priority mode for searching repository files.- Specified by:
setRepositoryFilePriorityin interfaceModelFileFinder- Parameters:
priority- the new priority
-
setSourceInformation
public void setSourceInformation(SourceInformation sourceInformation)
-
-