Package adams.env
Class AbstractEnvironment
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.env.AbstractEnvironment
-
- All Implemented Interfaces:
LoggingSupporter,SizeOfHandler,Serializable
- Direct Known Subclasses:
Environment
public abstract class AbstractEnvironment extends LoggingObject implements Serializable
Manages properties files and returns merged versions.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringADAMS_HOMEenvironment variable for setting the home directory.static StringFILENAMEthe constant for the properties definition props file.static StringKEY_DEFINITIONSthe constant for the key in the properties definition props file.protected AbstractApplicationFramem_ApplicationFramethe main GUI application.protected AbstractTerminalApplicationm_ApplicationTerminalthe main terminal application.protected static Databasem_DatabaseThe Database environment instance.protected Hashtable<String,AbstractPropertiesDefinition>m_Definitionsthe key - definition relation.protected static AbstractEnvironmentm_EnvironmentThe current instance of the environment.protected static Classm_EnvironmentClassThe class to use.protected static Filem_HomeDirectorythe directory to use as home directory.protected static Datem_InstantiationTimestampthe instantiation time.protected Hashtable<String,List<Setup>>m_Propertiesthe key - setups relation.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractEnvironment()Initializes the object.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(String key, String propsfile, String[] overrides)Adds the props file under they specified key.voidadd(String key, String propsfile, String home, String[] overrides)Adds the props file under they specified key.voidadd(String key, String propsfile, List<String> dirs, String[] overrides)Adds the props file under they specified key.StringcreatePropertiesFilename(String file)Creates the full path for a props file, located in the project's home directory.protected voidfinishInit()Finishes up the initialization.AbstractApplicationFramegetApplicationFrame()Returns the main GUI application.AbstractTerminalApplicationgetApplicationTerminal()Returns the main terminal application.StringgetCustomPropertiesFilename(String key)Returns the filename of the properties file in the project's home directory.DatabasegetDatabase()Returns the Database environment instance.StringgetDefaultHome()Returns the project's default "home" directory (underneath the user's home directory).StringgetDefaultHome(String project)Returns the project's default "home" directory (underneath the user's home directory).List<String>getDirectories(String propsfile)Returns the default directories to search for props files.List<String>getDirectories(String propsfile, String home)Returns the default directories to search for props files.static ClassgetEnvironmentClass()Returns the currently set environment class.StringgetHome()Returns the project's "home" directory (underneath the user's home directory).static AbstractEnvironmentgetInstance()Returns the instance of the Environment class to use.static DategetInstantiationTimestamp()Returns the timestamp this environment was initialized (ie startup time of the application).StringgetKey(String propsfile)Determines the key for the given properties file.abstract StringgetProject()Returns the project's name.protected Hashtable<String,List<Setup>>getProperties()Returns the underlying properties.protected abstract List<String>getPropertiesDefinitions()Returns the URLs of the properties files with the definitions.protected voidinitialize()Initializes the setup.Iterator<String>keys()Returns the keys for the properties files.Propertiesread(String key)Returns the properties object generated from all the stored props files.voidreplace(String key, String propsfile)Adds the props file under they specified key.voidreplace(String key, String propsfile, String home)Adds the props file under they specified key.voidreplace(String key, String propsfile, List<String> dirs)Adds the props file under they specified key.static voidrunEnvironment(Class env, String[] args)Executes the environment class from commandline.voidsetApplicationFrame(AbstractApplicationFrame value)Sets the main GUI application frame (which was started from commandline).voidsetApplicationTerminal(AbstractTerminalApplication value)Sets the main terminal application frame (which was started from commandline).static voidsetEnvironmentClass(Class cls)Sets the class to use for handling the props files etc.static voidsetHome(String value)Sets the home directory to use.protected voidsetUp()Performs the setup of the properties files.StringtoString()Returns a string representation of the stored props files.booleanwrite(String key, Properties props)Writes the properties to the project's home directory.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
FILENAME
public static final String FILENAME
the constant for the properties definition props file.- See Also:
- Constant Field Values
-
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.
-
m_Definitions
protected Hashtable<String,AbstractPropertiesDefinition> m_Definitions
the key - definition relation.
-
m_ApplicationFrame
protected AbstractApplicationFrame m_ApplicationFrame
the main GUI application.
-
m_ApplicationTerminal
protected AbstractTerminalApplication m_ApplicationTerminal
the main terminal application.
-
-
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 filepropsfile- 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 filepropsfile- the location of the props file (e.g., "adams/gui/something.props")home- the home directory to useoverrides- 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 filepropsfile- the location of the props file (e.g., "adams/gui/something.props")dirs- the directories to look foroverrides- 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 filepropsfile- 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 filepropsfile- 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 filepropsfile- the location of the props file (e.g., "adams/gui/something.props")dirs- the directories to look for
-
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 propsprops- 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.
-
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
-
-