Class Configuration


  • public class Configuration
    extends java.lang.Object
    Implements 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
    • Field Detail

      • 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
      • 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. Calls setToEASyDefaults().
      • 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.
      • isRecent

        public boolean isRecent()
        Returns whether the configuration file is recent.
        Returns:
        true if the configuration file is recent and does not need to be reloaded, false else
      • isMaterialized

        public boolean isMaterialized()
        Returns whether the configuration was materialized (stored) or whether this configuration consists of values loaded from default settings.
        Returns:
        true if this configuration was materialized, false else
      • readOldFormat

        private void readOldFormat​(java.lang.String firstLine,
                                   java.io.LineNumberReader lnr)
                            throws java.io.IOException
        Reads the configuration from the old (legacy) format.
        Parameters:
        firstLine - the first line read for identifying the file format
        lnr - 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.IOException
        Reads 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. If path contains multiple paths, e.g., separated by ";" or ":", they will be set at once.
        Parameters:
        kind - the path kind to modify
        path - 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 modified
        path - 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 modified
        path - 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 per kind.
        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 kind
        index - the path index
        Returns:
        the related path, null if none was configured for kind
        Throws:
        java.lang.IndexOutOfBoundsException - if not within range of getPathCount(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:
        boolean if the specified path is the same, false else
      • 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 kind
        index - the path index
        Returns:
        the related path
        Throws:
        java.lang.IndexOutOfBoundsException - if not within range of getPathCount(PathKind)
      • store

        public void store()
        Stores the configuration values.
      • combinePath

        public java.lang.String combinePath​(Configuration.PathKind kind)
        Returns all paths for kind combined by the system path separator.
        Parameters:
        kind - the kind
        Returns:
        the combined path