public class ApplicationContextImpl extends Object implements ApplicationContext
A default implementation of the ApplicationContext interface.
This class is used by the Application class to store global
information that is needed by different components of an application. Because
an ApplicationContext implementation also implements the
TransformerContext interface instances can also be passed to
transformer objects.
Note that this implementation is not thread-safe. The intended use case is that an instance is created at application startup and initialized with the central helper objects managed by the instance. Later these objects should not be changed any more. If used in this way, the instance can be used from both the event dispatch thread and from commands executing in background threads.
TransformerContext| Constructor and Description |
|---|
ApplicationContextImpl()
Creates a new instance of
ApplicationContextImpl. |
ApplicationContextImpl(Locale locale)
Creates a new instance of
ApplicationContextImpl and sets
the current locale. |
ApplicationContextImpl(Locale locale,
ResourceManager resMan)
Creates a new instance of
ApplicationContextImpl and sets
the current locale and the resource manager to use. |
| Modifier and Type | Method and Description |
|---|---|
protected BindingStrategy |
fetchBindingStrategy()
Obtains the
BindingStrategy for a builder operation. |
ActionStore |
getActionStore()
Returns the application's
ActionStore. |
BeanContext |
getBeanContext()
Returns the global bean context.
|
ClassLoaderProvider |
getClassLoaderProvider()
Returns the
ClassLoaderProvider. |
org.apache.commons.configuration.Configuration |
getConfiguration()
Returns a reference to the global configuration.
|
GUISynchronizer |
getGUISynchronizer()
Returns the
GUISynchronizer. |
Locale |
getLocale()
Returns the current locale.
|
Window |
getMainWindow()
Returns the application's main window.
|
MessageOutput |
getMessageOutput()
Returns a reference to the object for displaying messages.
|
Object |
getResource(Message msg)
Convenience method for looking up a resource that is specified as a
Message object. |
Object |
getResource(Object resID)
Convenience method for looking up a resource.
|
Object |
getResource(Object groupID,
Object resID)
Convenience method for looking up a resource specified as group and
resource ID.
|
ResourceManager |
getResourceManager()
Returns the actual resource manager.
|
String |
getResourceText(Message msg)
Convenience method for looking up the text of a resource specified as a
Message object. |
String |
getResourceText(Object resID)
Convenience method for looking up the text of a specified resource.
|
String |
getResourceText(Object groupID,
Object resID)
Convenience method for looking up the text of a resource specified as
group and resource ID.
|
<T> T |
getTypedProperty(Class<T> propCls)
Returns the value of the specified typed property or null if it
cannot be found.
|
ValidationMessageHandler |
getValidationMessageHandler()
Returns the
ValidationMessageHandler. |
ApplicationBuilderData |
initBuilderData()
Returns an initialized
ApplicationBuilderData object that
can be used for calling the GUI builder. |
int |
messageBox(Object resMsg,
Object resTitle,
int msgType,
int btnType)
A convenience method for displaying a message box.
|
Builder |
newBuilder()
Returns a new
instance. |
Map<String,Object> |
properties()
Returns a map with properties maintained by this context.
|
void |
setActionStore(ActionStore actionStore)
Sets the application's
ActionStore. |
void |
setBeanContext(BeanContext beanContext)
Sets the global bean context.
|
void |
setClassLoaderProvider(ClassLoaderProvider classLoaderProvider)
Sets the
ClassLoaderProvider. |
void |
setConfiguration(org.apache.commons.configuration.Configuration configuration)
Sets the global configuration.
|
void |
setLocale(Locale locale)
Sets the current locale.
|
void |
setMainWindow(Window mainWindow)
Allows to set the application's main window.
|
void |
setMessageOutput(MessageOutput msg)
Sets the message output object to be used by this application.
|
void |
setResourceManager(ResourceManager resourceManager)
Sets the resource manager.
|
<T> void |
setTypedProperty(Class<T> propCls,
T value)
Sets the value of the given typed property.
|
void |
setValidationMessageHandler(ValidationMessageHandler validationMessageHandler)
Sets the
ValidationMessageHandler. |
public ApplicationContextImpl()
ApplicationContextImpl. The
instance is not yet initialized.public ApplicationContextImpl(Locale locale)
ApplicationContextImpl and sets
the current locale.locale - the Localepublic ApplicationContextImpl(Locale locale, ResourceManager resMan)
ApplicationContextImpl and sets
the current locale and the resource manager to use.locale - the LocaleresMan - the ResourceManager to usepublic Locale getLocale()
getLocale in interface TransformerContextLocalepublic void setLocale(Locale locale)
setLocale in interface ApplicationContextlocale - the new Localepublic ResourceManager getResourceManager()
getResourceManager in interface TransformerContextResourceManager for accessing resourcespublic void setResourceManager(ResourceManager resourceManager)
setResourceManager in interface ApplicationContextresourceManager - the ResourceManagerpublic Map<String,Object> properties()
properties in interface TransformerContextpublic org.apache.commons.configuration.Configuration getConfiguration()
getConfiguration in interface ApplicationContextpublic void setConfiguration(org.apache.commons.configuration.Configuration configuration)
setConfiguration in interface ApplicationContextconfiguration - the configuration objectpublic BeanContext getBeanContext()
getBeanContext in interface ApplicationContextpublic void setBeanContext(BeanContext beanContext)
beanContext - the new bean contextpublic ClassLoaderProvider getClassLoaderProvider()
ClassLoaderProvider. This implementation always returns
the ClassLoaderProvider managed by the current BeanContext.getClassLoaderProvider in interface ApplicationContextClassLoaderProviderpublic void setClassLoaderProvider(ClassLoaderProvider classLoaderProvider)
ClassLoaderProvider. This implementation does not store
the ClassLoaderProvider in a separate member field. Rather, it is
passed to the current BeanContext. To avoid inconsistencies when
loading classes there must be only a single ClassLoaderProvider
instance. If this method is called before a BeanContext was set,
an IllegalStateException exception is thrown.setClassLoaderProvider in interface ApplicationContextclassLoaderProvider - the new class loader providerIllegalStateException - if no BeanContext has been setpublic ValidationMessageHandler getValidationMessageHandler()
ValidationMessageHandler.getValidationMessageHandler in interface TransformerContextValidationMessageHandlerpublic void setValidationMessageHandler(ValidationMessageHandler validationMessageHandler)
ValidationMessageHandler. This object can be
queried by validators to obtain a specific validation message.validationMessageHandler - the new
ValidationMessageHandler (must not be null)IllegalArgumentException - if the passed validation message handler
is nullpublic MessageOutput getMessageOutput()
getMessageOutput in interface ApplicationContextpublic void setMessageOutput(MessageOutput msg)
setMessageOutput in interface ApplicationContextmsg - the new MessageOutput objectpublic Object getResource(Object groupID, Object resID)
getResource in interface ApplicationContextgroupID - the resource group IDresID - the resource IDMissingResourceException - if the resource cannot be foundpublic Object getResource(Message msg)
Message object.getResource in interface ApplicationContextmsg - the resource definition (must not be null)MissingResourceException - if the resource cannot be foundIllegalArgumentException - if then message is undefinedpublic Object getResource(Object resID)
Message. If
this is the case, the resource group and the resource ID are extracted
from this object. Otherwise the passed in object is interpreted as
resource ID and the default resource group will be used.getResource in interface ApplicationContextresID - the resource IDMissingResourceException - if the resource cannot be foundpublic String getResourceText(Object groupID, Object resID)
getResourceText in interface ApplicationContextgroupID - the resource group IDresID - the resource IDMissingResourceException - if the resource cannot be foundpublic String getResourceText(Message msg)
Message object.getResourceText in interface ApplicationContextmsg - defines the resource (must not be null)MissingResourceException - if the resource cannot be foundIllegalArgumentException - if the message is undefinedpublic String getResourceText(Object resID)
getResourceText(Object),
especially the passed in object can be an instance of
Message.getResourceText in interface ApplicationContextresID - defines the requested resourceMissingResourceException - if the resource cannot be foundpublic int messageBox(Object resMsg, Object resTitle, int msgType, int btnType)
MessageOutput object. Before
that the passed in resource IDs (which can be either resource IDs or
instances of the Message
class) will be resolved.messageBox in interface ApplicationContextresMsg - the resource defining the message to be displayedresTitle - the resource defining the message box's title (can be
null)msgType - the message type (one of the MESSAGE_XXX
constants of MessageOutput)btnType - the button type (one of the BTN_XXX constants
of MessageOutput)RET_XXX
constants of MessageOutput)MessageOutputpublic GUISynchronizer getGUISynchronizer()
GUISynchronizer. This implementation obtains
the synchronizer from the bean context.getGUISynchronizer in interface ApplicationContextGUISynchronizerpublic Window getMainWindow()
getMainWindow in interface ApplicationContextpublic void setMainWindow(Window mainWindow)
setMainWindow in interface ApplicationContextmainWindow - the new main windowpublic ActionStore getActionStore()
ActionStore.getActionStore in interface ApplicationContextpublic void setActionStore(ActionStore actionStore)
ActionStore. This object contains
the definitions for all top level actions known to the application.setActionStore in interface ApplicationContextactionStore - the new action storepublic Builder newBuilder()
Builder instance. This
implementation obtains the builder instance from the global bean context.newBuilder in interface ApplicationContextBuilder instancepublic ApplicationBuilderData initBuilderData()
ApplicationBuilderData object that
can be used for calling the GUI builder. Most of the properties of the
returned object are already set to default values, so only specific
settings must be performed. The following properties have already been
initialized with information available directly in this object or from
the configuration:
BeanContextActionStore managed by this object is empty, it is
directly used. Otherwise a new ActionStore instance is
created with the managed ActionStore as parent. This has
the effect that the first builder script will populate the global action
store. Further scripts use their own store.MessageOutput objectCommandQueueBindingStrategyBeanCreationListener is set that can inject a reference to
the central Application object into beans implementing the
ApplicationClient interfaceinitBuilderData in interface ApplicationContextpublic <T> T getTypedProperty(Class<T> propCls)
getTypedProperty in interface TransformerContextT - the type of the propertypropCls - the property classpublic <T> void setTypedProperty(Class<T> propCls, T value)
setTypedProperty in interface ApplicationContextT - the type of the propertypropCls - the property class (must not be null)value - the new value (null for clearing this property)IllegalArgumentException - if the property class is nullprotected BindingStrategy fetchBindingStrategy()
BindingStrategy for a builder operation. This method
is invoked by initBuilderData() for populating the bindingStrategy property of the ApplicationBuilderData object.
The default algorithm looks up the BindingStrategy from the
global BeanContext.BindingStrategyCopyright © 2016 The JGUIraffe Team. All rights reserved.