Klasse Application
- Bekannte direkte Unterklassen:
Main
The main startup class of the GUI application framework.
With this class a Java GUI application can be started. This works as follows:
- The class uses the values of system properties to find out the name of the application's configuration file.
- This configuration file is loaded using commons-configuration.
- From properties defined in the application's configuration the
ApplicationContext
is created and initialized. This includes setting up a resource manager. - The name of the application's main GUI builder script is also determined by configuration properties. This script is executed, and the resulting main window is made visible.
Per default the application's configuration file is expected to be located in
the class path and has the name config.xml. This can be changed
using system properties: The property
net.sf.jguiraffe.configName
allows to change the name of the
configuration file. If defined, a file with this name will be searched in the
class path. If the property net.sf.jguiraffe.configURL
is
provided, the class tries to load this file directly from this URL.
A bunch of configuration properties is evaluated by this class to perform the
correct setup. All of these must be placed in a section called
framework
. The following table lists the available properties:
Property | Description | Optional |
---|---|---|
appctx | In this section some properties of the application context are defined:
|
Yes |
builder | This section contains some setting related to the builders used for
processing bean definitions and GUI scripts. All properties in this section
are optional - meaningful default values are applied if a value is not set.
The following sub elements are supported:
|
Yes |
frame | In this section some properties of the application's main window can be
defined, especially its location and size. The idea is that this information
will be stored in a user configuration so that the last settings can be set
again on next application start. The following properties can be defined in
this section:
|
Yes |
storeuserconfig | A boolean property that determines whether the user specific configuration should be stored when the application terminates. Defaults to false. | Yes |
userconfigname | Defines the name of the user configuration in the configuration definition file. (The configuration definition file can include an arbitrary number of configuration sources. To determine, which of these is the user configuration, its name must be specified. If no name is specified, the default userConfig will be used. | Yes |
A major part of the configuration of the application is defined in terms of
bean definitions. Here many helper classes used by the application are
defined (e.g. the resource manager, the message output object, the GUI
builder, and many more). At start up, the application creates a
BeanContext
that provides access to these beans and creates the
required instances. There is a default bean definition file (
defaultbeans.jelly) with default bean definitions for all available
helper classes. It is loaded first. Concrete applications can override some
or all of these beans. This is a powerful means of customizing the
application.
To override bean definitions, use the
framework.builder.beandefinitions
section in the application's
main configuration file (see above). In this section the names of an
arbitrary number of bean definition files can be specified (the files will be
loaded from the class path). Using the predefined names for the default beans
in these scripts causes the beans to be replaced by the custom ones. Have a
look at the defaultbeans.jelly script for more information; in this
file all available default beans are listed with a documentation for each.
- Version:
- $Id: Application.java 211 2012-07-10 19:49:13Z oheger $
- Autor:
- Oliver Heger
-
Feldübersicht
FelderModifizierer und TypFeldBeschreibungstatic final String
Constant for the name of the bean with the current application instance.static final String
Constant for the name of the bean with the application context.static final String
Constant for the name of the binding strategy bean.static final String
Constant for the name of the builder bean.static final String
Constant for the name of the bean for the class loader provider.static final String
Constant for the name of the command queue bean.static final String
Constant for the name of the bean with the global configuration.static final String
Constant for the name of the bean with the default resource group.static final String
Constant for the name of the bean with the global bean context.static final String
Constant for the name of the GUI synchronizer bean.static final String
Constant for the name of the bean with the locale.static final String
Constant for the prefix for bean definitions used by the framework.static final String
Constant for the section with the builder information.static final String
Constant for the name of the class loader which loaded the application class.static final String
Constant for the configuration section for the framework.static final String
Constant for the default name of the configuration file.static final String
Constant for the frame section in the configuration file.protected final org.apache.commons.logging.Log
The logger to use.static final String
Constant for the application context property in the config file.static final String
Constant for the bean builder factory property.static final String
Constant for the bean definitions property.static final String
Constant for the builder factory property.static final String
Constant for the builder main script property.static final String
Constant for the builder menu icon property.static final String
Constant for the builder toolbar text property.static final String
Constant for the system property with the resource name of the configuration file.static final String
Constant for the system property with the URL to the configuration file.static final String
Constant for the default resource group property in the config file.static final String
Constant for the height property in the config file.static final String
Constant for the locale property in the config file.static final String
Constant for the storeuserconfig property in the config file.static final String
Constant for the userconfigname property in the config file.static final String
Constant for the width property in the config file.static final String
Constant for the xpos property in the config file.static final String
Constant for the ypos property in the config file.static final String
Constant for the name of the user configuration. -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungprotected void
addBeanDuringApplicationStartup
(String name, Object bean) Adds a bean to the application's global root bean store while the application starts up.void
Registers the specified object as a shutdown listeners.protected ApplicationContext
Creates and initializes the application context.protected BeanBuilderFactory
createBeanBuilderFactory
(org.apache.commons.configuration.Configuration config) Creates the factory for the bean builder.protected CommandQueue
createCommandQueue
(ApplicationContext appCtx) Creates and initializes the application's command queue.protected org.apache.commons.configuration.HierarchicalConfiguration
Creates the configuration for this application.protected org.apache.commons.configuration.HierarchicalConfiguration
createConfiguration
(URL configURL) Reads the application's configuration from the specified URL.protected MutableBeanStore
createRootStore
(org.apache.commons.configuration.Configuration config) Creates the root bean store.void
Executes the given command.protected void
exitApplication
(int exitCode) Terminates this application.protected URL
Returns the URL to the configuration file.protected Collection
<Locator> findBeanDefinitions
(org.apache.commons.configuration.Configuration config) Veraltet.protected Collection
<Locator> findBeanDefinitions
(org.apache.commons.configuration.Configuration config, BeanContext beanCtx) Returns a collection with additional bean definition files to process.protected boolean
Calls thecanShutdown()
method on all registered shutdown listeners.protected void
Notifies all registered shutdown listeners about the shutdown of this application.Returns a reference to the actual application context.Returns theBeanBuilderFactory
for obtaining a bean builder.Returns a reference to the command queue that is used for executing commands in another thread.Returns the resource name of the configuration file.Returns the URL from which the configuration file is to be loaded.int
Returns the current exit code for this application.Returns the current exit handler of this application.Returns theGUISynchronizer
object used by this application.static Application
getInstance
(BeanContext context) Obtains the centralApplication
instance from the specifiedBeanContext
.Returns theBeanContext
that was created when processing the builder script for the main window.protected Locator
Returns aLocator
object pointing to a file with bean declarations related to the platform or UI toolkit.org.apache.commons.configuration.Configuration
Returns the configuration object with user specific settings.protected BeanContext
initBeans
(org.apache.commons.configuration.Configuration config) Initializes the application's bean definitions.protected ClassLoaderProvider
Initializes the globalClassLoaderProvider
.protected void
initGUI
(ApplicationContext appCtx) Initializes the application's main GUI.protected void
initMainWindow
(Window window, org.apache.commons.configuration.Configuration config) Initializes the application's main window object.protected Locator
locatorForMainScript
(org.apache.commons.configuration.Configuration config) Returns the locator object for the application's main build script.static void
A main method for applications based on this framework.protected void
A hook for shutdown.void
processCommandLine
(String[] args) Hook method for processing the command line arguments.protected BeanBuilderResult
readBeanDefinition
(Locator script, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider) A convenience method for processing a file with bean definitions.protected void
Releases the results of bean builder operations that were created during initialization of this application.void
Removes the specified shutdown listener.static URL
resolveResourceURL
(String url, String name) Veraltet.This method does not make sense in the public interface of this class.void
run()
The main execute method of this application.void
Stores the configuration with user specific settings if there have been changes.void
saveUserConfiguration
(boolean force) Stores the configuration with user specific settings.void
setApplicationContext
(ApplicationContext context) Sets the application context.static void
setApplicationReference
(Object target, Application ref) Tries to the set a reference to the globalApplication
object in the target object.void
setBeanBuilderFactory
(BeanBuilderFactory beanBuilderFactory) Allows to set theBeanBuilderFactory
.void
Sets the command queue that is used for executing commands.void
setConfigResourceName
(String configResourceName) Sets the resource name under which the configuration file can be loaded.void
setConfigURL
(String configURL) Sets the URL to the configuration file.void
setExitHandler
(Runnable handler) Sets the exit handler for this application.void
Sets theGUISynchronizer
object to be used by this application.protected void
showMainWindow
(Window window) Shows the application's main window.void
shutdown()
Shuts down this application unconditionally.void
shutdown
(boolean force) Shuts down this application unconditionally, optionally without asking shutdown listeners for permission.void
Shuts down this application.static void
startup
(Application application, String[] args) Starts an application.protected void
Updates the user configuration.
-
Felddetails
-
PROP_CONFIG_URL
Constant for the system property with the URL to the configuration file.- Siehe auch:
-
PROP_CONFIG_NAME
Constant for the system property with the resource name of the configuration file.- Siehe auch:
-
DEF_CONFIG_NAME
Constant for the default name of the configuration file.- Siehe auch:
-
BEAN_PREFIX
Constant for the prefix for bean definitions used by the framework.- Siehe auch:
-
BEAN_CONFIGURATION
Constant for the name of the bean with the global configuration.- Siehe auch:
-
BEAN_APPLICATION
Constant for the name of the bean with the current application instance.- Siehe auch:
-
BEAN_APPLICATION_CONTEXT
Constant for the name of the bean with the application context.- Siehe auch:
-
BEAN_GLOBAL_CONTEXT
Constant for the name of the bean with the global bean context.- Siehe auch:
-
BEAN_BUILDER
Constant for the name of the builder bean.- Siehe auch:
-
BEAN_COMMAND_QUEUE
Constant for the name of the command queue bean.- Siehe auch:
-
BEAN_GUI_SYNCHRONIZER
Constant for the name of the GUI synchronizer bean.- Siehe auch:
-
BEAN_BINDING_STRATEGY
Constant for the name of the binding strategy bean.- Siehe auch:
-
BEAN_LOCALE
Constant for the name of the bean with the locale.- Siehe auch:
-
BEAN_DEF_RES_GROUP
Constant for the name of the bean with the default resource group.- Siehe auch:
-
BEAN_CLASS_LOADER_PROVIDER
Constant for the name of the bean for the class loader provider.- Siehe auch:
-
CONFIG_SECTION
Constant for the configuration section for the framework.- Siehe auch:
-
PROP_APPCTX
Constant for the application context property in the config file.- Siehe auch:
-
PROP_LOCALE
Constant for the locale property in the config file.- Siehe auch:
-
PROP_DEFRESGROUP
Constant for the default resource group property in the config file.- Siehe auch:
-
BUILDER_SECTION
Constant for the section with the builder information.- Siehe auch:
-
PROP_BUILDER_FACTORY
Constant for the builder factory property.- Siehe auch:
-
PROP_BEAN_BUILDER_FACTORY
Constant for the bean builder factory property.- Siehe auch:
-
PROP_BEAN_DEFS
Constant for the bean definitions property.- Siehe auch:
-
PROP_BUILDER_MENU_ICON
Constant for the builder menu icon property.- Siehe auch:
-
PROP_BUILDER_TOOLBAR_TEXT
Constant for the builder toolbar text property.- Siehe auch:
-
PROP_BUILDER_MAIN_SCRIPT
Constant for the builder main script property.- Siehe auch:
-
FRAME_SECTION
Constant for the frame section in the configuration file.- Siehe auch:
-
PROP_XPOS
Constant for the xpos property in the config file.- Siehe auch:
-
PROP_YPOS
Constant for the ypos property in the config file.- Siehe auch:
-
PROP_WIDTH
Constant for the width property in the config file.- Siehe auch:
-
PROP_HEIGHT
Constant for the height property in the config file.- Siehe auch:
-
PROP_USRCONF
Constant for the storeuserconfig property in the config file.- Siehe auch:
-
PROP_USRCONFNAME
Constant for the userconfigname property in the config file.- Siehe auch:
-
USRCONF_NAME
Constant for the name of the user configuration.- Siehe auch:
-
CLASS_LOADER
Constant for the name of the class loader which loaded the application class. This class loader is set as the default class loader at theClassLoaderProvider
created at startup.- Seit:
- 1.2
- Siehe auch:
-
log
protected final org.apache.commons.logging.Log logThe logger to use.
-
-
Konstruktordetails
-
Application
public Application()Creates a new instance ofApplication
.
-
-
Methodendetails
-
getConfigURL
Returns the URL from which the configuration file is to be loaded.- Gibt zurück:
- the URL to the configuration file
-
setConfigURL
Sets the URL to the configuration file. The configuration file can either be loaded directly from a URL or as a resource from the class path. If this property is defined, it is loaded directly from the URL specified here.- Parameter:
configURL
- the URL to the configuration file
-
getConfigResourceName
Returns the resource name of the configuration file.- Gibt zurück:
- the resource name of the configuration file
-
setConfigResourceName
Sets the resource name under which the configuration file can be loaded. If no configuration URL is provided, this property is used to look up the configuration file from the class path.- Parameter:
configResourceName
- the resource name of the configuration file
-
getApplicationContext
Returns a reference to the actual application context.- Gibt zurück:
- the
ApplicationContext
-
setApplicationContext
Sets the application context.- Parameter:
context
- the new context
-
getBeanBuilderFactory
Returns theBeanBuilderFactory
for obtaining a bean builder. This method can be used when a bean definition file is to be processed.- Gibt zurück:
- the
BeanBuilderFactory
-
setBeanBuilderFactory
Allows to set theBeanBuilderFactory
. Normally it is not necessary to set this property. When the application is initialized it creates a default factory.- Parameter:
beanBuilderFactory
- the newBeanBuilderFactory
-
addShutdownListener
Registers the specified object as a shutdown listeners.- Parameter:
l
- the listener to register
-
removeShutdownListener
Removes the specified shutdown listener.- Parameter:
l
- the listener to remove
-
resolveResourceURL
Veraltet.This method does not make sense in the public interface of this class. It will be removed in later versions. Use corresponding functionality from theLocatorUtils
class instead.Helper method for locating a resource. The resource can either be specified by a full URL, in which case it is directly loaded, or by a resource name. In the latter case the class loader is used to find the resource.- Parameter:
url
- a URL to the resource; this can be a full qualified URL or the name of a file (either relative or absolute)name
- the resource name- Gibt zurück:
- the URL to the resource or null if it cannot be found
-
setApplicationReference
Tries to the set a reference to the globalApplication
object in the target object. If the target object implements theApplicationClient
interface, the reference can be set.- Parameter:
target
- the target objectref
- the application reference to set
-
getUserConfiguration
public org.apache.commons.configuration.Configuration getUserConfiguration() throws ApplicationRuntimeExceptionReturns the configuration object with user specific settings. This configuration can be used to store personalization settings that override the default configuration. For this method to work the system's main configuration definition file must include an entry for the user configuration that is identified by its name. Per default the name is "userConfig", but can be altered with the
userconfigname
property. The following example fragment from the application's configuration definition file demonstrates how the user configuration should be declared:<configuration> ... <xml fileName="${user.home}/myAppConfig.xml" config-name="userConfig" config-optional="true" config-forceCreate="true"/> <!-- Further configuration sources to load --> ...
In this example the attributes starting with
config-
are of special importance. Withconfig-name
the configuration's name is specified, which is necessary for the framework to retrieve the correct user configuration.config-optional
declares this configuration source as optional. This means that it won't cause an error when this source cannot be loaded (which will probably be the case when a user starts this application for the first time). Theconfig-forceCreate
attribute finally tells the configuration framework to create an empty configuration when loading of the configuration file fails. This will cause the configuration to be automatically created for the new user. If the user customizes the application, these settings can be stored in this configuration. When the application terminates it checks the value of thestoreuserconfig
property. If this is set to true, the user configuration will be stored. So the next time the application starts it will be found there and override the values in all other configuration sources.- Gibt zurück:
- the configuration with user specific settings
- Löst aus:
ApplicationRuntimeException
- if the user configuration cannot be obtained
-
saveUserConfiguration
Stores the configuration with user specific settings if there have been changes. This is equivalent to callingsaveUserConfiguration(false);
.- Löst aus:
ApplicationException
- if an error occurs
-
saveUserConfiguration
Stores the configuration with user specific settings. This method obtains the user configuration by calling thegetUserConfiguration()
method. It expects that the user configuration implements theFileConfiguration
interface. If a different configuration type is used as user configuration, this method should also be adapted. With theforce
flag the behavior can be controlled if the configuration has not been modified: if it is false, no action is taken in this case; otherwise, the configuration is written anyway.- Parameter:
force
- flag whether an unmodified configuration should be saved- Löst aus:
ApplicationException
- if an error occurs- Seit:
- 1.4
-
createApplicationContext
Creates and initializes the application context. Loads the configuration, too.- Gibt zurück:
- the application context
- Löst aus:
ApplicationRuntimeException
- if an error occurs during initialization
-
fetchConfigURL
Returns the URL to the configuration file. This URL is determined by the propertiesconfigURL
andconfigResourceName
.- Gibt zurück:
- the URL to the application's main configuration file
- Löst aus:
ApplicationRuntimeException
- if the configuration file cannot be located
-
createConfiguration
protected org.apache.commons.configuration.HierarchicalConfiguration createConfiguration()Creates the configuration for this application. This method callsfetchConfigURL()
to determine the URL to the main configuration file. Then this file is loaded with commons-configuration.- Gibt zurück:
- the configuration to use
- Löst aus:
ApplicationRuntimeException
- if the configuration file cannot be located
-
createConfiguration
protected org.apache.commons.configuration.HierarchicalConfiguration createConfiguration(URL configURL) Reads the application's configuration from the specified URL. TheDefaultConfigurationBuilder
of Commons Configuration is used for reading the configuration. Occurring exceptions are re-thrown as runtime exceptions.- Parameter:
configURL
- the configuration URL- Gibt zurück:
- the application's main configuration
- Löst aus:
ApplicationRuntimeException
- if the configuration cannot be loaded
-
createRootStore
Creates the root bean store. This bean store will contain the fundamental bean definitions required by the framework. Because it is at the top level the contained bean definitions can be used or even overridden by child stores. This implementation creates a default store and populates it with the configuration and the application instance itself.- Parameter:
config
- the configuration object- Gibt zurück:
- the initialized root bean store
-
createBeanBuilderFactory
protected BeanBuilderFactory createBeanBuilderFactory(org.apache.commons.configuration.Configuration config) Creates the factory for the bean builder. This method is called during initialization phase. It tries to obtain the factory implementation from the main configuration file. If this fails, a default factory instance will be returned.- Parameter:
config
- the main configuration- Gibt zurück:
- the
BeanBuilderFactory
to be used
-
initBeans
Initializes the application's bean definitions. This implementation will first process the framework-internal bean definition file, which defines the standard beans. After thatfindBeanDefinitions()
is called for obtaining a list of additional definition files to be evaluated. Finally a bean context is created allowing access to all beans defined this way. This algorithm allows concrete applications to define their own beans in an easy way and also to override standard beans used by the framework.- Parameter:
config
- the main configuration source- Gibt zurück:
- the global bean context
-
addBeanDuringApplicationStartup
Adds a bean to the application's global root bean store while the application starts up. This method can be called by derived classes that need to create beans dynamically Sometimes it is not sufficient to define beans in additional definition scripts. For instance, objects may have to be looked up from different sources, or complex logic is required for creating the beans. In such cases, this method can be used to make the beans created by a derived application class globally available via the bean context. As the name implies, this method can be called only during application startup phase - after the invocation ofinitBeans(Configuration)
and before the global bean context is accessed. Calling this method to a later point of time is not guaranteed to have the desired effect!- Parameter:
name
- the name of the beanbean
- the bean itself- Seit:
- 1.3.1
-
initClassLoaderProvider
Initializes the globalClassLoaderProvider
. This method is called byinitBeans(Configuration)
after the default beans have been loaded. TheClassLoaderProvider
passed to this method was obtained from the default beans. A derived class can override this method to perform specific initialization of the passed inClassLoaderProvider
. It can even create a completely new object (theClassLoaderProvider
returned by this method will become the globalClassLoaderProvider
; it need not be the same object as was passed to this method). This base implementation registers the class loader which has loaded the concreteApplication
sub class and makes it the default class loader.- Parameter:
clp
- theClassLoaderProvider
as obtained from the default beans- Gibt zurück:
- the new global
ClassLoaderProvider
(must never be null)
-
readBeanDefinition
protected BeanBuilderResult readBeanDefinition(Locator script, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider) A convenience method for processing a file with bean definitions. A new bean builder will be created, which processes the passed in script. The defined beans are stored in the specified root store. Occurring builder exceptions are re-thrown as runtime exceptions.- Parameter:
script
- defines the script with the bean definitionsrootStore
- the root store for storing the resultsloaderProvider
- the optional class loader provider- Gibt zurück:
- the result object returned by the builder
- Löst aus:
IllegalArgumentException
- if required parameters are missingApplicationRuntimeException
- if an error occurs
-
findBeanDefinitions
@Deprecated protected Collection<Locator> findBeanDefinitions(org.apache.commons.configuration.Configuration config) Veraltet.This method is replaced byfindBeanDefinitions(Configuration, BeanContext)
. It is still called during application initialization to keep backwards compatibility, but this base implementation simply returns an empty collection.Returns a collection with additional bean definition files to process.- Parameter:
config
- the main configuration source- Gibt zurück:
- a list with locators to bean definition files to be processed (can be null)
-
findBeanDefinitions
protected Collection<Locator> findBeanDefinitions(org.apache.commons.configuration.Configuration config, BeanContext beanCtx) Returns a collection with additional bean definition files to process. This method is called when the application context is created. All files contained in the returned list will be processed by the bean builder. This base implementation obtains the value(s) of theframework.builder.beandefinitions.beandefinition
configuration property. The values are interpreted as textual representations ofLocator
objects which can be converted using theLocatorConverter
class. Strings that do not contain a locator type prefix (e.g.classpath:
orurl:
are expected to be names of bean definition files, which can be read from the class path. In addition, thegetPlatformBeansLocator()
method is called to obtain aLocator
for a file with platform-specific bean declarations; if this method returns a non-null value, thisLocator
is added to the list, too. If an application has different requirements for specifying additional bean definition files, this method can be overridden.- Parameter:
config
- the main configuration sourcebeanCtx
- the currentBeanContext
- Gibt zurück:
- a list with locators to bean definition files to be processed (can be null)
- Seit:
- 1.2
-
getPlatformBeansLocator
Returns aLocator
object pointing to a file with bean declarations related to the platform or UI toolkit. This method is called when additional bean declaration files to be loaded during application initialization are detected. The base implementation returns a locator pointing to a class path resource with the nameplatformbeans.jelly
. This file contains declarations for beans like the platform-specific component manager, window manager, etc. In a standard JGUIraffe application a single file with this name exists which contains definitions compatible to the supported platform. A derived class may override this method and return a differentLocator
. Result can be null, then no additional bean declaration file is loaded.- Gibt zurück:
- a
Locator
pointing to platform-specific bean declarations - Seit:
- 1.3
-
initGUI
Initializes the application's main GUI. This method checks whether a script for the main GUI is defined in the application's configuration. If this is the case, the script is executed, and the resulting main window is stored.- Parameter:
appCtx
- the application context- Löst aus:
ApplicationRuntimeException
- if an error occurs
-
locatorForMainScript
Returns the locator object for the application's main build script. This implementation checks if a script is specified in the configuration. If this is the case, a class path locator will be returned. Derived classes can use different mechanisms to determine the build script. A return value of null means that no script should be executed.- Parameter:
config
- the configuration- Gibt zurück:
- the locator for the main builder script
-
initMainWindow
Initializes the application's main window object. This method is called after the main window has been created by the main build script. Here the passed in configuration object can be used to initialize properties on this object. This implementation deals with the window's bounds, which can be initialized from the configuration.- Parameter:
window
- the new main window objectconfig
- the actual configuration
-
showMainWindow
Shows the application's main window. This method is called after the main window has been fully initialized. All other parts of the application have also been initialized.- Parameter:
window
- the main window
-
createCommandQueue
Creates and initializes the application's command queue. This implementation obtains the command queue from the global bean context managed by the application context.- Parameter:
appCtx
- the application context- Gibt zurück:
- the new command queue
- Löst aus:
InjectionException
- if the command queue cannot be created
-
getCommandQueue
Returns a reference to the command queue that is used for executing commands in another thread.- Gibt zurück:
- the command queue
-
setCommandQueue
Sets the command queue that is used for executing commands.- Parameter:
q
- the new command queue (must not be null)- Löst aus:
IllegalArgumentException
- if the command queue is null
-
getGUISynchronizer
Returns theGUISynchronizer
object used by this application. This object can be used to deal with the event dispatch thread.- Gibt zurück:
- the GUI synchronizer
-
setGUISynchronizer
Sets theGUISynchronizer
object to be used by this application. This object can be used for safe GUI updates that need to take place at the event dispatch thread. It will also set at the application's command queue, so that always the same synchronizer is used.- Parameter:
sync
- the GUI synchronizer
-
execute
Executes the given command. The command is put into the internal command queue. It is then executed in another thread. If the passed in command implements theApplicationClient
interface, a reference to this application will be automatically set before execution.- Parameter:
cmd
- the command to be executed
-
shutdown
Shuts down this application. This method should always be called by the main window class when the application is to be terminated. This implementation checks if commands are still running. If this is the case, a message is displayed (using the message output object) to the user asking if the application should be ended anyway. The resource for this message is defined by the passed in parameter, which can be a resource ID or anApplicationResourceDef
object. Only if the user confirms this, the application will be ended. If the application has already been shut down, this invocation has no effect.- Parameter:
msgres
- defines the resource of the message to be displayedtitleres
- defines the resource of the title of the message
-
shutdown
public void shutdown()Shuts down this application unconditionally. This version of theshutdown()
method does not check for tasks still running in the background. It directly invokes the registered shutdown listeners and exits the application if none vetos. If the application has already been shut down, this invocation has no effect. -
shutdown
public void shutdown(boolean force) Shuts down this application unconditionally, optionally without asking shutdown listeners for permission. If theforce
parameter is false, thecanShutdown()
method of registered shutdown listeners is invoked, so that they can abort the shutdown operation. With the value true, this is not the case; the method then assumes that no shutdown listener has objections against the operation. If the application has already been shut down, this invocation has no effect.- Parameter:
force
- a flag whether the shutdown should be enforced- Seit:
- 1.4
-
getExitHandler
Returns the current exit handler of this application. This is the object called during ashutdown()
operation. This method never returns null. If no exit handler has been set, a default one is returned. The default exit handler terminates this application by callingSystem.exit()
with the current exit code.- Gibt zurück:
- the exit handler of this application
- Seit:
- 1.2
-
setExitHandler
Sets the exit handler for this application. The exit handler is called eventually byshutdown()
. Its task is to ultimately terminate this application, e.g. by callingSystem.exit()
.- Parameter:
handler
- the exit handler for this application (may be null)- Seit:
- 1.2
-
getExitCode
public int getExitCode()Returns the current exit code for this application. This value is only defined during ashutdown()
operation. This method is intended to be called by an exit handler to find out the exit status of the application.- Gibt zurück:
- this application's exit status
- Seit:
- 1.2
- Siehe auch:
-
getMainWindowBeanContext
Returns theBeanContext
that was created when processing the builder script for the main window. This context may be useful because it contains some central objects defined by the builder script for the main window, e.g. global actions. If this application does not define a builder script for the main window, this method returns null.- Gibt zurück:
- the
BeanContext
created when the main window was constructed - Seit:
- 1.3.1
-
onShutdown
protected void onShutdown()A hook for shutdown. This method is called by the default implementation of theshutdown()
method. Here application specific cleanup can be placed. Note: if this method is overloaded in a derived class, the inherited method should be called. This implementation cares for storing the user specific configuration if thestoreuserconfig
property is true. Before that theupdateUserConfiguration()
method is called. -
updateUserConfiguration
protected void updateUserConfiguration()Updates the user configuration. This method is called during shutdown if thestoreuserconfig
configuration property is set. Here actual settings can be written in the user configuration object so that they can be restored the next time the application is started again. This implementation stores the actual bounds of the main frame in the user config. -
fireCanShutdown
protected boolean fireCanShutdown()Calls thecanShutdown()
method on all registered shutdown listeners. If one of them returns false , the remaining listeners are not invoked and shutdown process is canceled.- Gibt zurück:
- a flag whether to proceed with the shutdown process
-
fireShutdown
protected void fireShutdown()Notifies all registered shutdown listeners about the shutdown of this application. -
releaseBeanBuilderResults
Releases the results of bean builder operations that were created during initialization of this application. The results of all bean builder operations performed byinitBeans(Configuration)
are stored so that they can be released when the application shuts down. This is exactly the task of this method. It is called byshutdown()
.- Parameter:
results
- the collection with the builder results to be released
-
exitApplication
protected void exitApplication(int exitCode) Terminates this application. This method is called byshutdown(Object, Object)
at the very end. It calls the exit handler. This object is responsible for actually terminating this application.- Parameter:
exitCode
- the exit code- Siehe auch:
-
run
The main execute method of this application. Performs all initialization steps and displays the application's main window. This method starts it all.- Löst aus:
ApplicationException
- if an error occurs during initialization
-
processCommandLine
Hook method for processing the command line arguments. Here a derived class can place some logic to evaluate passed in parameters. This base implementation is empty.- Parameter:
args
- the command line arguments- Löst aus:
ApplicationException
- if a command line error occurs
-
startup
Starts an application. This method performs all steps to initialize and startup anApplication
object. First the system properties are checked if the configuration file is specified. Then the application is given the opportunity of processing its command line. Finally itsrun()
method is invoked, which starts the application. A typical use case for this method is to create anApplication
instance (which also can be of a derived class) and pass it to this method together with the command line array. The rest is done by this method.- Parameter:
application
- the application to startargs
- the command line arguments- Löst aus:
ApplicationException
- if an error occurs
-
main
A main method for applications based on this framework. This method tries to determine the name of the configuration file from system properties. Then it creates an instance of this class, initializes it, and calls thestartup()
method.- Parameter:
args
- command line arguments- Löst aus:
ApplicationException
- if an error occurs
-
getInstance
Obtains the centralApplication
instance from the specifiedBeanContext
. This method provides an easy way for obtaining theApplication
when only theApplicationContext
is known: just callApplication myApp = Application.getInstance(appCtx.getBeanContext());
If the application cannot be found in the given bean context, an exception is thrown.- Parameter:
context
- the bean context- Gibt zurück:
- the
Application
object defined in this bean context - Löst aus:
InjectionException
- if the application bean cannot be foundIllegalArgumentException
- if the passed in context is null
-
findBeanDefinitions(Configuration, BeanContext)
.