Package adams.env

Class AbstractEnvironment

    • Field Detail

      • KEY_DEFINITIONS

        public static final String KEY_DEFINITIONS
        the constant for the key in the properties definition props file.
        See Also:
        Constant Field Values
      • ADAMS_HOME

        public static final String ADAMS_HOME
        environment variable for setting the home directory.
        See Also:
        Constant Field Values
      • m_EnvironmentClass

        protected static Class m_EnvironmentClass
        The class to use. This class needs to be set correctly in projects implementing their own Environment class.
      • m_Environment

        protected static AbstractEnvironment m_Environment
        The current instance of the environment.
      • m_Database

        protected static Database m_Database
        The Database environment instance.
      • m_HomeDirectory

        protected static File m_HomeDirectory
        the directory to use as home directory.
      • m_InstantiationTimestamp

        protected static Date m_InstantiationTimestamp
        the instantiation time.
    • Constructor Detail

      • AbstractEnvironment

        protected AbstractEnvironment()
        Initializes the object.
    • Method Detail

      • initialize

        protected void initialize()
        Initializes the setup.
      • finishInit

        protected void finishInit()
        Finishes up the initialization.

        Tries to create the project's home directory
      • getPropertiesDefinitions

        protected abstract List<String> getPropertiesDefinitions()
        Returns the URLs of the properties files with the definitions.
        Returns:
        the URLs
      • setUp

        protected void setUp()
        Performs the setup of the properties files.
      • getProject

        public abstract String getProject()
        Returns the project's name.
        Returns:
        the internal name of the project
      • setHome

        public static void setHome​(String value)
        Sets the home directory to use.

        Note: no placeholders allowed, should be absolute path.
        Parameters:
        value - the new home directory, use empty string or null to use default home
      • getDefaultHome

        public String getDefaultHome​(String project)
        Returns the project's default "home" directory (underneath the user's home directory). For Windows this is the project name preceded by an underscore ("_") and for all the other OS preceded by a dot (".").
        Parameters:
        project - the project name
        Returns:
        the home directory, null if none available
      • getDefaultHome

        public String getDefaultHome()
        Returns the project's default "home" directory (underneath the user's home directory). For Windows this is the project name preceded by an underscore ("_") and for all the other OS preceded by a dot (".").
        Returns:
        the home directory, null if none available
        See Also:
        getProject()
      • getHome

        public String getHome()
        Returns the project's "home" directory (underneath the user's home directory). For Windows this is the project name preceded by an underscore ("_") and for all the other OS preceded by a dot (".").
        Returns:
        the home directory, null if none available
        See Also:
        getProject()
      • getDatabase

        public Database getDatabase()
        Returns the Database environment instance.
        Returns:
        the Database environment instance
      • getProperties

        protected Hashtable<String,​List<Setup>> getProperties()
        Returns the underlying properties.
        Returns:
        the properties and their setups
      • getDirectories

        public List<String> getDirectories​(String propsfile,
                                           String home)
        Returns the default directories to search for props files. The first directory has to be the location of the props file in the classpath (e.g., "adams/gui" for "adams/gui/something.props").
        Parameters:
        propsfile - the props file (e.g., "adams/gui/something.props")
        home - the home directory to use, ignored if null
        Returns:
        the directories
      • getDirectories

        public List<String> getDirectories​(String propsfile)
        Returns the default directories to search for props files. The first directory has to be the location of the props file in the classpath (e.g., "adams/gui" for "adams/gui/something.props").
        Parameters:
        propsfile - the props file (e.g., "adams/gui/something.props")
        Returns:
        the directories
        See Also:
        getHome()
      • add

        public void add​(String key,
                        String propsfile,
                        String[] overrides)
        Adds the props file under they specified key.
        Parameters:
        key - the key for the props file
        propsfile - the location of the props file (e.g., "adams/gui/something.props")
        overrides - the keys to override with the values from props files added later on
      • add

        public void add​(String key,
                        String propsfile,
                        String home,
                        String[] overrides)
        Adds the props file under they specified key.
        Parameters:
        key - the key for the props file
        propsfile - the location of the props file (e.g., "adams/gui/something.props")
        home - the home directory to use
        overrides - the keys to override with the values from props files added later on
      • add

        public void add​(String key,
                        String propsfile,
                        List<String> dirs,
                        String[] overrides)
        Adds the props file under they specified key.
        Parameters:
        key - the key for the props file
        propsfile - the location of the props file (e.g., "adams/gui/something.props")
        dirs - the directories to look for
        overrides - the keys (or regular expression of keys) to override with the values from props files added later on
      • replace

        public void replace​(String key,
                            String propsfile)
        Adds the props file under they specified key. Previously added props files are removed first.
        Parameters:
        key - the key for the props file
        propsfile - the location of the props file (e.g., "adams/gui/something.props")
      • replace

        public void replace​(String key,
                            String propsfile,
                            String home)
        Adds the props file under they specified key. Previously added props files are removed first.
        Parameters:
        key - the key for the props file
        propsfile - the location of the props file (e.g., "adams/gui/something.props")
        home - the home directory to use
      • replace

        public void replace​(String key,
                            String propsfile,
                            List<String> dirs)
        Adds the props file under they specified key. Previously added props files are removed first.
        Parameters:
        key - the key for the props file
        propsfile - the location of the props file (e.g., "adams/gui/something.props")
        dirs - the directories to look for
      • keys

        public Iterator<String> keys()
        Returns the keys for the properties files.
        Returns:
        the keys
      • getKey

        public String getKey​(String propsfile)
        Determines the key for the given properties file.
        Parameters:
        propsfile - the propsfile to determine the key for
        Returns:
        the key or null if not found
      • read

        public Properties read​(String key)
        Returns the properties object generated from all the stored props files.
        Parameters:
        key - the key for the props files to retrieve
        Returns:
        the merged properties
      • write

        public boolean write​(String key,
                             Properties props)
        Writes the properties to the project's home directory.
        Parameters:
        key - the key for the props
        props - the properties to write
        Returns:
        true if successfully written
      • getCustomPropertiesFilename

        public String getCustomPropertiesFilename​(String key)
        Returns the filename of the properties file in the project's home directory.
        Parameters:
        key - the key for the props
        Returns:
        the filename, null if no definition available for properties
      • createPropertiesFilename

        public String createPropertiesFilename​(String file)
        Creates the full path for a props file, located in the project's home directory.
        Parameters:
        file - the file's name without the path
        Returns:
        the full path
      • setApplicationFrame

        public void setApplicationFrame​(AbstractApplicationFrame value)
        Sets the main GUI application frame (which was started from commandline).
        Parameters:
        value - the frame
      • getApplicationFrame

        public AbstractApplicationFrame getApplicationFrame()
        Returns the main GUI application.
        Returns:
        the frame, null if not set
      • setApplicationTerminal

        public void setApplicationTerminal​(AbstractTerminalApplication value)
        Sets the main terminal application frame (which was started from commandline).
        Parameters:
        value - the frame
      • getApplicationTerminal

        public AbstractTerminalApplication getApplicationTerminal()
        Returns the main terminal application.
        Returns:
        the frame, null if not set
      • getInstance

        public static AbstractEnvironment getInstance()
        Returns the instance of the Environment class to use.
        Returns:
        the instance to use
      • getInstantiationTimestamp

        public static Date getInstantiationTimestamp()
        Returns the timestamp this environment was initialized (ie startup time of the application).
        Returns:
        the timestamp
      • toString

        public String toString()
        Returns a string representation of the stored props files.
        Overrides:
        toString in class Object
        Returns:
        the string representation
      • setEnvironmentClass

        public static void setEnvironmentClass​(Class cls)
        Sets the class to use for handling the props files etc. Needs to be set by any class with a main method!
        Parameters:
        cls - the concrete Environment class to use
      • getEnvironmentClass

        public static Class getEnvironmentClass()
        Returns the currently set environment class.
        Returns:
        the class, can be null if not yet set
      • runEnvironment

        public static void runEnvironment​(Class env,
                                          String[] args)
                                   throws Exception
        Executes the environment class from commandline.
        Parameters:
        env - the environment class to use
        args - the commandline arguments
        Throws:
        Exception