Package adams.terminal.application
Class AbstractTerminalApplication
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.terminal.application.AbstractTerminalApplication
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,DatabaseConnectionHandler
,DatabaseConnectionProvider
,DatabaseConnectionUser
,DatabaseConnectionChangeListener
,RemoteScriptingEngineHandler
,Serializable
public abstract class AbstractTerminalApplication extends AbstractOptionHandler implements DatabaseConnectionHandler, DatabaseConnectionChangeListener, RemoteScriptingEngineHandler
Ancestor for terminal-based applications.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected String
m_ApplicationTitle
the title of the application.protected AbstractDatabaseConnection
m_DbConn
the global database connection.protected RemoteScriptingEngine
m_RemoteScriptingEngine
the remote command scripting engine.protected String
m_RemoteScriptingEngineCmdLine
the commandline of the remote scripting engine to use at startup time.protected Set<RemoteScriptingEngineUpdateListener>
m_RemoteScriptingEngineUpdateListeners
the listeners for changes to the remote scripting engine.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTerminalApplication()
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addRemoteScriptingEngine(RemoteScriptingEngine value)
Adds the scripting engine to execute.void
addRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Adds the listener for remote scripting engine changes.String
applicationTitleTipText()
Returns the tip text for this property.protected abstract Handler
createLogHandler()
Returns the log handler to use.void
createTitle(String title)
creates and displays the title.void
databaseConnectionStateChanged(DatabaseConnectionChangeEvent e)
A change in the database connection occurred.void
defineOptions()
Adds options to the internal list of options.protected abstract void
finishTerminal()
Finishes the initialization.static AbstractTerminalApplication
forCommandLine(String cmdline)
Instantiates the application from the given commandline (i.e., classname and optional options).static AbstractTerminalApplication
forName(String classname, String[] options)
Instantiates the application with the given options.String
getApplicationTitle()
Returns the currently set application title.AbstractDatabaseConnection
getDatabaseConnection()
Returns the currently used database connection object, can be null.protected abstract String
getDefaultApplicationTitle()
Returns the default title of the application.protected abstract AbstractDatabaseConnection
getDefaultDatabaseConnection()
Returns the default database connection.RemoteScriptingEngine
getRemoteScriptingEngine()
Returns the current scripting engine if any.String
getRemoteScriptingEngineCmdLine()
Returns the commandline of the remote scripting engine to execute at startup time.protected void
initialize()
Initializes the members.protected abstract void
initTerminal()
Initializes the terminal.abstract void
logError(String msg)
Logs the error.abstract void
logError(String msg, Throwable t)
Logs the error.abstract void
logMessage(String msg)
Logs the message.void
notifyRemoteScriptingEngineUpdateListeners(RemoteScriptingEngineUpdateEvent e)
Notifies all listeners of remote scripting engine changes.String
remoteScriptingEngineCmdLineTipText()
Returns the tip text for this property.void
removeRemoteScriptingEngine(RemoteScriptingEngine value)
Removes the scripting engine (and stops it).void
removeRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Removes the listener for remote scripting engine changes.static void
runApplication(Class env, Class app, String[] options)
Runs the application from the commandline.void
setApplicationTitle(String value)
Sets the application title to use.void
setDatabaseConnection(AbstractDatabaseConnection value)
Sets the database connection object to use.void
setLoggingLevel(LoggingLevel value)
Sets the logging level.void
setRemoteScriptingEngine(RemoteScriptingEngine value)
Sets the scripting engine to execute.void
setRemoteScriptingEngineCmdLine(String value)
Sets the commandline of the remote scripting engine to execute at startup time.protected abstract void
setTitle(String value)
Sets the title to use.abstract void
start()
Starts the application.abstract void
stop()
Stops the application.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, loggingLevelTipText, newOptionManager, reset, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
m_DbConn
protected AbstractDatabaseConnection m_DbConn
the global database connection.
-
m_ApplicationTitle
protected String m_ApplicationTitle
the title of the application.
-
m_RemoteScriptingEngineCmdLine
protected String m_RemoteScriptingEngineCmdLine
the commandline of the remote scripting engine to use at startup time.
-
m_RemoteScriptingEngine
protected RemoteScriptingEngine m_RemoteScriptingEngine
the remote command scripting engine.
-
m_RemoteScriptingEngineUpdateListeners
protected Set<RemoteScriptingEngineUpdateListener> m_RemoteScriptingEngineUpdateListeners
the listeners for changes to the remote scripting engine.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractOptionHandler
-
initTerminal
protected abstract void initTerminal()
Initializes the terminal.
-
logMessage
public abstract void logMessage(String msg)
Logs the message.- Parameters:
msg
- the message to log
-
logError
public abstract void logError(String msg)
Logs the error.- Parameters:
msg
- the error message to log
-
logError
public abstract void logError(String msg, Throwable t)
Logs the error.- Parameters:
msg
- the error message to logt
- the exception
-
createLogHandler
protected abstract Handler createLogHandler()
Returns the log handler to use.- Returns:
- the handler
-
finishTerminal
protected abstract void finishTerminal()
Finishes the initialization.
-
start
public abstract void start()
Starts the application.
-
stop
public abstract void stop()
Stops the application.
-
getDefaultApplicationTitle
protected abstract String getDefaultApplicationTitle()
Returns the default title of the application.- Returns:
- the default title
-
getDefaultDatabaseConnection
protected abstract AbstractDatabaseConnection getDefaultDatabaseConnection()
Returns the default database connection.- Returns:
- the default database connection
-
getDatabaseConnection
public AbstractDatabaseConnection getDatabaseConnection()
Returns the currently used database connection object, can be null.- Specified by:
getDatabaseConnection
in interfaceDatabaseConnectionProvider
- Returns:
- the current object
-
setDatabaseConnection
public void setDatabaseConnection(AbstractDatabaseConnection value)
Sets the database connection object to use.- Specified by:
setDatabaseConnection
in interfaceDatabaseConnectionHandler
- Parameters:
value
- the object to use
-
databaseConnectionStateChanged
public void databaseConnectionStateChanged(DatabaseConnectionChangeEvent e)
A change in the database connection occurred.- Specified by:
databaseConnectionStateChanged
in interfaceDatabaseConnectionChangeListener
- Parameters:
e
- the event
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Specified by:
setLoggingLevel
in interfaceLoggingLevelHandler
- Overrides:
setLoggingLevel
in classAbstractOptionHandler
- Parameters:
value
- the level
-
setRemoteScriptingEngineCmdLine
public void setRemoteScriptingEngineCmdLine(String value)
Sets the commandline of the remote scripting engine to execute at startup time.- Parameters:
value
- the commandline, use empty string if not to use one
-
getRemoteScriptingEngineCmdLine
public String getRemoteScriptingEngineCmdLine()
Returns the commandline of the remote scripting engine to execute at startup time.- Returns:
- the commandline, empty string it not to use one
-
remoteScriptingEngineCmdLineTipText
public String remoteScriptingEngineCmdLineTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
addRemoteScriptingEngine
public void addRemoteScriptingEngine(RemoteScriptingEngine value)
Adds the scripting engine to execute. Doesn't stop any running engines.- Specified by:
addRemoteScriptingEngine
in interfaceRemoteScriptingEngineHandler
- Parameters:
value
- the engine to add
-
removeRemoteScriptingEngine
public void removeRemoteScriptingEngine(RemoteScriptingEngine value)
Removes the scripting engine (and stops it). Doesn't stop any running engines.- Specified by:
removeRemoteScriptingEngine
in interfaceRemoteScriptingEngineHandler
- Parameters:
value
- the engine to remove
-
setRemoteScriptingEngine
public void setRemoteScriptingEngine(RemoteScriptingEngine value)
Sets the scripting engine to execute. Any running engine is stopped first.- Specified by:
setRemoteScriptingEngine
in interfaceRemoteScriptingEngineHandler
- Parameters:
value
- the engine to use, null to turn off scripting
-
getRemoteScriptingEngine
public RemoteScriptingEngine getRemoteScriptingEngine()
Returns the current scripting engine if any.- Specified by:
getRemoteScriptingEngine
in interfaceRemoteScriptingEngineHandler
- Returns:
- the engine in use, null if none running
-
addRemoteScriptingEngineUpdateListener
public void addRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Adds the listener for remote scripting engine changes.- Specified by:
addRemoteScriptingEngineUpdateListener
in interfaceRemoteScriptingEngineHandler
- Parameters:
l
- the listener
-
removeRemoteScriptingEngineUpdateListener
public void removeRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Removes the listener for remote scripting engine changes.- Specified by:
removeRemoteScriptingEngineUpdateListener
in interfaceRemoteScriptingEngineHandler
- Parameters:
l
- the listener
-
notifyRemoteScriptingEngineUpdateListeners
public void notifyRemoteScriptingEngineUpdateListeners(RemoteScriptingEngineUpdateEvent e)
Notifies all listeners of remote scripting engine changes.- Parameters:
e
- the event to send
-
getApplicationTitle
public String getApplicationTitle()
Returns the currently set application title.- Returns:
- the current title
-
setApplicationTitle
public void setApplicationTitle(String value)
Sets the application title to use.- Parameters:
value
- the title to use
-
applicationTitleTipText
public String applicationTitleTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setTitle
protected abstract void setTitle(String value)
Sets the title to use.- Parameters:
value
- the title
-
createTitle
public void createTitle(String title)
creates and displays the title.- Parameters:
title
- the additional part of the title
-
forName
public static AbstractTerminalApplication forName(String classname, String[] options)
Instantiates the application with the given options.- Parameters:
classname
- the classname of the application to instantiateoptions
- the options for the application- Returns:
- the instantiated application or null if an error occurred
-
forCommandLine
public static AbstractTerminalApplication forCommandLine(String cmdline)
Instantiates the application from the given commandline (i.e., classname and optional options).- Parameters:
cmdline
- the classname (and optional options) of the application to instantiate- Returns:
- the instantiated application or null if an error occurred
-
-