Class FileTypeConverter
- java.lang.Object
-
- org.sosy_lab.common.configuration.converters.FileTypeConverter
-
- All Implemented Interfaces:
TypeConverter
public final class FileTypeConverter extends Object implements TypeConverter
ATypeConverter
for options of typeFile
orPath
which offers some additional features like a common base directory for all output files. In order to use these features, the options need to be annotated withFileOption
.This type converter should be registered for the type
FileOption
.The additional features are:
- All specified relative paths are resolved against a given root directory.
- All relative paths of output files are resolved against a separate output directory.
- All output files can be disabled by a central switch.
In order to configure these features, the normal configuration options are used.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable Object
convert(String optionName, String pValue, TypeToken<?> pType, Annotation secondaryOption, Path pSource, LogManager logger)
Convert a String given by the user to an instance of a given type.<T> @Nullable T
convertDefaultValue(String optionName, T pDefaultValue, TypeToken<T> pType, Annotation secondaryOption)
Optionally convert the default value for an option that was given in the source code.<T> @Nullable T
convertDefaultValueFromOtherInstance(String optionName, @Nullable T pDefaultValue, TypeToken<T> pType, @Nullable Annotation secondaryOption)
LikeTypeConverter.convertDefaultValue(String, Object, TypeToken, Annotation)
, but called if the default value was not taken from the fresh instance, but from a different instance (cf.static FileTypeConverter
create(Configuration config)
static FileTypeConverter
createWithSafePathsOnly(Configuration config)
Create an instanceof of this class that allows only injected files that are below the current directory.FileTypeConverter
getInstanceForNewConfiguration(Configuration pNewConfiguration)
Return a (possibly) new instance of this converter that has new configuration values applied.String
getOutputDirectory()
Path
getOutputPath()
-
-
-
Method Detail
-
create
public static FileTypeConverter create(Configuration config) throws InvalidConfigurationException
- Throws:
InvalidConfigurationException
-
createWithSafePathsOnly
public static FileTypeConverter createWithSafePathsOnly(Configuration config) throws InvalidConfigurationException
Create an instanceof of this class that allows only injected files that are below the current directory.- Throws:
InvalidConfigurationException
-
getInstanceForNewConfiguration
public FileTypeConverter getInstanceForNewConfiguration(Configuration pNewConfiguration) throws InvalidConfigurationException
Description copied from interface:TypeConverter
Return a (possibly) new instance of this converter that has new configuration values applied.If this converter has configuration options itself, it may be desired to use new values for these options if the converter instance is used together with a new
Configuration
instance. This method is called whenever an existing converter instance will be used by a newConfiguration
instance, e.g., byConfigurationBuilder.copyFrom(Configuration)
or if the converter instance is taken fromConfiguration.getDefaultConverters()
. It can return a new converter instance according to the options in the newConfiguration
instance, or return the current converter instance. Note that this method should not change the existing instance.- Specified by:
getInstanceForNewConfiguration
in interfaceTypeConverter
- Parameters:
pNewConfiguration
- The new configuration instance which will use the returned converter- Returns:
- A new instance of the same converter, or
this
- Throws:
InvalidConfigurationException
- If applying the new configuration fails
-
getOutputDirectory
public String getOutputDirectory()
-
getOutputPath
public Path getOutputPath()
-
convert
public @Nullable Object convert(String optionName, String pValue, TypeToken<?> pType, Annotation secondaryOption, Path pSource, LogManager logger) throws InvalidConfigurationException
Description copied from interface:TypeConverter
Convert a String given by the user to an instance of a given type.Although the signature of this method does not enforce it, the class of the returned value needs to be assignable to "type" as defined by
TypeToken.isSupertypeOf(java.lang.reflect.Type)
.Before this method is called, the caller ensures that all requirements for the option defined with the
Option
annotation are met.- Specified by:
convert
in interfaceTypeConverter
- Parameters:
optionName
- The name of the option (should only be used for nice error messages).pValue
- The string to parse.pType
- The target type.secondaryOption
- An optional second annotation for the option (this is one of the annotations marked withOptionDetailAnnotation
).pSource
- The file where the configuration option was read from. May contain a dummy value or null if the option was given somehow else.logger
- A logger for warnings etc.- Returns:
- An instance of the target type produced from the string representation-
- Throws:
InvalidConfigurationException
- If the user specified an invalid value.
-
convertDefaultValue
public <T> @Nullable T convertDefaultValue(String optionName, T pDefaultValue, TypeToken<T> pType, Annotation secondaryOption) throws InvalidConfigurationException
Description copied from interface:TypeConverter
Optionally convert the default value for an option that was given in the source code. This method is called if the user gave no explicit value.- Specified by:
convertDefaultValue
in interfaceTypeConverter
- Parameters:
optionName
- The name of the option (should only be used for nice error messages).pDefaultValue
- The default value (may be null).pType
- The target type.secondaryOption
- An optional second annotation for the option- Returns:
- An instance of the target type.
- Throws:
InvalidConfigurationException
- If the default value is invalid for this option.
-
convertDefaultValueFromOtherInstance
public <T> @Nullable T convertDefaultValueFromOtherInstance(String optionName, @Nullable T pDefaultValue, TypeToken<T> pType, @Nullable Annotation secondaryOption) throws InvalidConfigurationException
Description copied from interface:TypeConverter
LikeTypeConverter.convertDefaultValue(String, Object, TypeToken, Annotation)
, but called if the default value was not taken from the fresh instance, but from a different instance (cf.Configuration.injectWithDefaults(Object, Class, Object)
.Override this method if
TypeConverter.convertDefaultValue(String, Object, TypeToken, Annotation)
changes values and this should not be done twice if the value is injected again into another instance.- Specified by:
convertDefaultValueFromOtherInstance
in interfaceTypeConverter
- Throws:
InvalidConfigurationException
-
-