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 Stringm_ApplicationTitlethe title of the application.protected AbstractDatabaseConnectionm_DbConnthe global database connection.protected RemoteScriptingEnginem_RemoteScriptingEnginethe remote command scripting engine.protected Stringm_RemoteScriptingEngineCmdLinethe commandline of the remote scripting engine to use at startup time.protected Set<RemoteScriptingEngineUpdateListener>m_RemoteScriptingEngineUpdateListenersthe 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 protectedAbstractTerminalApplication()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddRemoteScriptingEngine(RemoteScriptingEngine value)Adds the scripting engine to execute.voidaddRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)Adds the listener for remote scripting engine changes.StringapplicationTitleTipText()Returns the tip text for this property.protected abstract HandlercreateLogHandler()Returns the log handler to use.voidcreateTitle(String title)creates and displays the title.voiddatabaseConnectionStateChanged(DatabaseConnectionChangeEvent e)A change in the database connection occurred.voiddefineOptions()Adds options to the internal list of options.protected abstract voidfinishTerminal()Finishes the initialization.static AbstractTerminalApplicationforCommandLine(String cmdline)Instantiates the application from the given commandline (i.e., classname and optional options).static AbstractTerminalApplicationforName(String classname, String[] options)Instantiates the application with the given options.StringgetApplicationTitle()Returns the currently set application title.AbstractDatabaseConnectiongetDatabaseConnection()Returns the currently used database connection object, can be null.protected abstract StringgetDefaultApplicationTitle()Returns the default title of the application.protected abstract AbstractDatabaseConnectiongetDefaultDatabaseConnection()Returns the default database connection.RemoteScriptingEnginegetRemoteScriptingEngine()Returns the current scripting engine if any.StringgetRemoteScriptingEngineCmdLine()Returns the commandline of the remote scripting engine to execute at startup time.protected voidinitialize()Initializes the members.protected abstract voidinitTerminal()Initializes the terminal.abstract voidlogError(String msg)Logs the error.abstract voidlogError(String msg, Throwable t)Logs the error.abstract voidlogMessage(String msg)Logs the message.voidnotifyRemoteScriptingEngineUpdateListeners(RemoteScriptingEngineUpdateEvent e)Notifies all listeners of remote scripting engine changes.StringremoteScriptingEngineCmdLineTipText()Returns the tip text for this property.voidremoveRemoteScriptingEngine(RemoteScriptingEngine value)Removes the scripting engine (and stops it).voidremoveRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)Removes the listener for remote scripting engine changes.static voidrunApplication(Class env, Class app, String[] options)Runs the application from the commandline.voidsetApplicationTitle(String value)Sets the application title to use.voidsetDatabaseConnection(AbstractDatabaseConnection value)Sets the database connection object to use.voidsetLoggingLevel(LoggingLevel value)Sets the logging level.voidsetRemoteScriptingEngine(RemoteScriptingEngine value)Sets the scripting engine to execute.voidsetRemoteScriptingEngineCmdLine(String value)Sets the commandline of the remote scripting engine to execute at startup time.protected abstract voidsetTitle(String value)Sets the title to use.abstract voidstart()Starts the application.abstract voidstop()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:
initializein 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:
getDatabaseConnectionin interfaceDatabaseConnectionProvider- Returns:
- the current object
-
setDatabaseConnection
public void setDatabaseConnection(AbstractDatabaseConnection value)
Sets the database connection object to use.- Specified by:
setDatabaseConnectionin interfaceDatabaseConnectionHandler- Parameters:
value- the object to use
-
databaseConnectionStateChanged
public void databaseConnectionStateChanged(DatabaseConnectionChangeEvent e)
A change in the database connection occurred.- Specified by:
databaseConnectionStateChangedin interfaceDatabaseConnectionChangeListener- Parameters:
e- the event
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractOptionHandler
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Specified by:
setLoggingLevelin interfaceLoggingLevelHandler- Overrides:
setLoggingLevelin 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:
addRemoteScriptingEnginein 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:
removeRemoteScriptingEnginein 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:
setRemoteScriptingEnginein 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:
getRemoteScriptingEnginein 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:
addRemoteScriptingEngineUpdateListenerin interfaceRemoteScriptingEngineHandler- Parameters:
l- the listener
-
removeRemoteScriptingEngineUpdateListener
public void removeRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Removes the listener for remote scripting engine changes.- Specified by:
removeRemoteScriptingEngineUpdateListenerin 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
-
-