Class Configuration
- java.lang.Object
-
- net.ssehub.easy.producer.core.persistence.Configuration
-
public class Configuration extends java.lang.ObjectImplements the base (path) configuration of EASy. The configuration normalized the given paths (FileUtils. Internally, configurations store a timestamp in order to determine when to reload them. This class supports the old legacy configuration format (just for reading) and the new XML-based format (reading and writing).- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConfiguration.PathKindDefines the supported paths.
-
Field Summary
Fields Modifier and Type Field Description static ConfigurationDEFAULTprivate java.io.Filefileprivate static net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLoggerLOGGERprivate java.util.Map<Configuration.PathKind,java.util.List<java.lang.String>>pathsprivate java.io.FileprojectFolderprivate longtimestamp(package private) static java.lang.StringTOP_LEVEL_CONFIG_NAME
-
Constructor Summary
Constructors Modifier Constructor Description privateConfiguration()Creates the default configuration.(package private)Configuration(java.io.File projectFolder)Creates a new configuration.(package private)Configuration(Configuration src)Creates a copy of the given configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidcheckForModification()Checks this configuration for modifications since last reading it.static java.lang.StringcheckPath(java.lang.String path)Checks the given path.private voidclear()Clears the configuration.java.lang.StringcombinePath(Configuration.PathKind kind)Returns all paths forkindcombined by the system path separator.private voidcreateStructures()Creates the initial structures / objects for configuration attributes.java.lang.StringgetPath(Configuration.PathKind kind, int index)Returns a path as a string.intgetPathCount(Configuration.PathKind kind)Returns the number of configured paths perkind.java.io.FilegetPathFile(Configuration.PathKind kind, int index)Returns a path as a file within the containing project.private voidinitDefaults()Initializes configuration values lazily with default values.booleanisMaterialized()Returns whether the configuration was materialized (stored) or whether this configuration consists of values loaded from default settings.booleanisPathEasyDefault(Configuration.PathKind kind)Returns whether the specified path is the same as the internal EASy default value.booleanisRecent()Returns whether the configuration file is recent.private voidload()Loads the configuration file.private voidreadOldFormat(java.lang.String firstLine, java.io.LineNumberReader lnr)Reads the configuration from the old (legacy) format.private voidreadXmlFormat(java.io.Reader reader)Reads the configuration for the extensible XML format.voidsetPath(Configuration.PathKind kind, java.io.File path)Sets the given path.voidsetPath(Configuration.PathKind kind, java.lang.String path)Sets the given path and stores the new configuration.private voidsetPathDefault(Configuration.PathKind kind)Sets the default value of a path in case that it has not been set before (lazy).voidsetPathDirect(Configuration.PathKind kind, java.lang.String path)Sets a path due to its string representation, thus, be careful.voidsetToEASyDefaults()Sets all three paths toPersistenceConstants.EASY_FILES_DEFAULT.voidstore()Stores the configuration values.private voidstorePath(IndentationPrintWriter writer, Configuration.PathKind kind)Stores a given path.
-
-
-
Field Detail
-
DEFAULT
public static final Configuration DEFAULT
-
TOP_LEVEL_CONFIG_NAME
static final java.lang.String TOP_LEVEL_CONFIG_NAME
- See Also:
- Constant Field Values
-
LOGGER
private static final net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger LOGGER
-
paths
private java.util.Map<Configuration.PathKind,java.util.List<java.lang.String>> paths
-
projectFolder
private java.io.File projectFolder
-
file
private java.io.File file
-
timestamp
private long timestamp
-
-
Constructor Detail
-
Configuration
private Configuration()
Creates the default configuration. CallssetToEASyDefaults().
-
Configuration
Configuration(Configuration src)
Creates a copy of the given configuration.- Parameters:
src- the source to copy from
-
Configuration
Configuration(java.io.File projectFolder)
Creates a new configuration.- Parameters:
projectFolder- the (canonical) project folder
-
-
Method Detail
-
checkForModification
void checkForModification()
Checks this configuration for modifications since last reading it.
-
setToEASyDefaults
public void setToEASyDefaults()
Sets all three paths toPersistenceConstants.EASY_FILES_DEFAULT.
-
isRecent
public boolean isRecent()
Returns whether the configuration file is recent.- Returns:
trueif the configuration file is recent and does not need to be reloaded,falseelse
-
isMaterialized
public boolean isMaterialized()
Returns whether the configuration was materialized (stored) or whether this configuration consists of values loaded from default settings.- Returns:
trueif this configuration was materialized,falseelse
-
readOldFormat
private void readOldFormat(java.lang.String firstLine, java.io.LineNumberReader lnr) throws java.io.IOExceptionReads the configuration from the old (legacy) format.- Parameters:
firstLine- the first line read for identifying the file formatlnr- the line number reader to read the remaining lines of the file- Throws:
java.io.IOException- in case of I/O problems
-
readXmlFormat
private void readXmlFormat(java.io.Reader reader) throws java.io.IOExceptionReads the configuration for the extensible XML format.- Parameters:
reader- the reader to read from- Throws:
java.io.IOException- in case of I/O problems
-
load
private void load()
Loads the configuration file.
-
createStructures
private void createStructures()
Creates the initial structures / objects for configuration attributes.
-
initDefaults
private void initDefaults()
Initializes configuration values lazily with default values.
-
clear
private void clear()
Clears the configuration.
-
setPathDefault
private void setPathDefault(Configuration.PathKind kind)
Sets the default value of a path in case that it has not been set before (lazy).- Parameters:
kind- the path kind to set the default value
-
checkPath
public static java.lang.String checkPath(java.lang.String path)
Checks the given path.- Parameters:
path- the path to be checked- Returns:
- a modified path if required
-
setPathDirect
public void setPathDirect(Configuration.PathKind kind, java.lang.String path)
Sets a path due to its string representation, thus, be careful. This method does not store the new configuration. Ifpathcontains multiple paths, e.g., separated by ";" or ":", they will be set at once.- Parameters:
kind- the path kind to modifypath- the path value- See Also:
combinePath(PathKind)
-
setPath
public void setPath(Configuration.PathKind kind, java.lang.String path) throws java.io.IOException
Sets the given path and stores the new configuration.- Parameters:
kind- the kind of path to be modifiedpath- the new path value- Throws:
java.io.IOException- in case that setting the path fails as the canonical path cannot be identified- See Also:
setPath(PathKind, File)
-
setPath
public void setPath(Configuration.PathKind kind, java.io.File path) throws java.io.IOException
Sets the given path.- Parameters:
kind- the kind of path to be modifiedpath- the new path value- Throws:
java.io.IOException- in case that setting the path fails as the canonical path cannot be identified
-
getPathCount
public int getPathCount(Configuration.PathKind kind)
Returns the number of configured paths perkind.- Parameters:
kind- the path kind- Returns:
- the number of paths
-
getPath
public java.lang.String getPath(Configuration.PathKind kind, int index)
Returns a path as a string.- Parameters:
kind- the path kindindex- the path index- Returns:
- the related path, null if none was configured for
kind - Throws:
java.lang.IndexOutOfBoundsException- if not within range ofgetPathCount(PathKind)
-
isPathEasyDefault
public boolean isPathEasyDefault(Configuration.PathKind kind)
Returns whether the specified path is the same as the internal EASy default value.- Parameters:
kind- the path kind- Returns:
booleanif the specified path is the same,falseelse
-
getPathFile
public java.io.File getPathFile(Configuration.PathKind kind, int index)
Returns a path as a file within the containing project.- Parameters:
kind- the path kindindex- the path index- Returns:
- the related path
- Throws:
java.lang.IndexOutOfBoundsException- if not within range ofgetPathCount(PathKind)
-
store
public void store()
Stores the configuration values.
-
combinePath
public java.lang.String combinePath(Configuration.PathKind kind)
Returns all paths forkindcombined by the system path separator.- Parameters:
kind- the kind- Returns:
- the combined path
-
storePath
private void storePath(IndentationPrintWriter writer, Configuration.PathKind kind)
Stores a given path.- Parameters:
writer- the writer to store the path tokind- the path kind to store
-
-