Class ApplicationContextImpl

  • All Implemented Interfaces:
    ApplicationContext, TransformerContext

    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.

    Version:
    $Id: ApplicationContextImpl.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    See Also:
    TransformerContext
    • Constructor Detail

      • ApplicationContextImpl

        public ApplicationContextImpl()
        Creates a new instance of ApplicationContextImpl. The instance is not yet initialized.
      • ApplicationContextImpl

        public ApplicationContextImpl​(Locale locale)
        Creates a new instance of ApplicationContextImpl and sets the current locale.
        Parameters:
        locale - the Locale
      • ApplicationContextImpl

        public ApplicationContextImpl​(Locale locale,
                                      ResourceManager resMan)
        Creates a new instance of ApplicationContextImpl and sets the current locale and the resource manager to use.
        Parameters:
        locale - the Locale
        resMan - the ResourceManager to use
    • Method Detail

      • getLocale

        public Locale getLocale()
        Returns the current locale. If no specific locale has been set yet, the system's default locale will be used.
        Specified by:
        getLocale in interface TransformerContext
        Returns:
        the Locale
      • setLocale

        public void setLocale​(Locale locale)
        Sets the current locale. Note: This implementation is thread-safe; the newly set locale is visible for other threads, too.
        Specified by:
        setLocale in interface ApplicationContext
        Parameters:
        locale - the new Locale
      • setResourceManager

        public void setResourceManager​(ResourceManager resourceManager)
        Sets the resource manager. Access to system resources will be handled by this object.
        Specified by:
        setResourceManager in interface ApplicationContext
        Parameters:
        resourceManager - the ResourceManager
      • getConfiguration

        public org.apache.commons.configuration.Configuration getConfiguration()
        Returns a reference to the global configuration.
        Specified by:
        getConfiguration in interface ApplicationContext
        Returns:
        the configuration object
      • setConfiguration

        public void setConfiguration​(org.apache.commons.configuration.Configuration configuration)
        Sets the global configuration.
        Specified by:
        setConfiguration in interface ApplicationContext
        Parameters:
        configuration - the configuration object
      • setBeanContext

        public void setBeanContext​(BeanContext beanContext)
        Sets the global bean context.
        Parameters:
        beanContext - the new bean context
      • setClassLoaderProvider

        public void setClassLoaderProvider​(ClassLoaderProvider classLoaderProvider)
        Sets the 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.
        Specified by:
        setClassLoaderProvider in interface ApplicationContext
        Parameters:
        classLoaderProvider - the new class loader provider
        Throws:
        IllegalStateException - if no BeanContext has been set
      • setValidationMessageHandler

        public void setValidationMessageHandler​(ValidationMessageHandler validationMessageHandler)
        Sets the ValidationMessageHandler. This object can be queried by validators to obtain a specific validation message.
        Parameters:
        validationMessageHandler - the new ValidationMessageHandler (must not be null)
        Throws:
        IllegalArgumentException - if the passed validation message handler is null
      • getMessageOutput

        public MessageOutput getMessageOutput()
        Returns a reference to the object for displaying messages. This object can be used to create message boxes.
        Specified by:
        getMessageOutput in interface ApplicationContext
        Returns:
        the object for displaying messages
      • setMessageOutput

        public void setMessageOutput​(MessageOutput msg)
        Sets the message output object to be used by this application.
        Specified by:
        setMessageOutput in interface ApplicationContext
        Parameters:
        msg - the new MessageOutput object
      • getResource

        public Object getResource​(Object groupID,
                                  Object resID)
        Convenience method for looking up a resource specified as group and resource ID.
        Specified by:
        getResource in interface ApplicationContext
        Parameters:
        groupID - the resource group ID
        resID - the resource ID
        Returns:
        the found resource
        Throws:
        MissingResourceException - if the resource cannot be found
      • getResource

        public Object getResource​(Object resID)
        Convenience method for looking up a resource. The passed in object is checked to be an instance of 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.
        Specified by:
        getResource in interface ApplicationContext
        Parameters:
        resID - the resource ID
        Returns:
        the found resource
        Throws:
        MissingResourceException - if the resource cannot be found
      • getResourceText

        public String getResourceText​(Object groupID,
                                      Object resID)
        Convenience method for looking up the text of a resource specified as group and resource ID.
        Specified by:
        getResourceText in interface ApplicationContext
        Parameters:
        groupID - the resource group ID
        resID - the resource ID
        Returns:
        the found resource text
        Throws:
        MissingResourceException - if the resource cannot be found
      • getResourceText

        public String getResourceText​(Object resID)
        Convenience method for looking up the text of a specified resource. This method works analogous to getResourceText(Object), especially the passed in object can be an instance of Message.
        Specified by:
        getResourceText in interface ApplicationContext
        Parameters:
        resID - defines the requested resource
        Returns:
        the found resource
        Throws:
        MissingResourceException - if the resource cannot be found
      • messageBox

        public int messageBox​(Object resMsg,
                              Object resTitle,
                              int msgType,
                              int btnType)
        A convenience method for displaying a message box. This method invokes the application's associated MessageOutput object. Before that the passed in resource IDs (which can be either resource IDs or instances of the Message class) will be resolved.
        Specified by:
        messageBox in interface ApplicationContext
        Parameters:
        resMsg - the resource defining the message to be displayed
        resTitle - 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)
        Returns:
        the message box's return value (one of the RET_XXX constants of MessageOutput)
        See Also:
        MessageOutput
      • getGUISynchronizer

        public GUISynchronizer getGUISynchronizer()
        Returns the GUISynchronizer. This implementation obtains the synchronizer from the bean context.
        Specified by:
        getGUISynchronizer in interface ApplicationContext
        Returns:
        the GUISynchronizer
      • getMainWindow

        public Window getMainWindow()
        Returns the application's main window.
        Specified by:
        getMainWindow in interface ApplicationContext
        Returns:
        the main window of this application
      • setMainWindow

        public void setMainWindow​(Window mainWindow)
        Allows to set the application's main window.
        Specified by:
        setMainWindow in interface ApplicationContext
        Parameters:
        mainWindow - the new main window
      • setActionStore

        public void setActionStore​(ActionStore actionStore)
        Sets the application's ActionStore. This object contains the definitions for all top level actions known to the application.
        Specified by:
        setActionStore in interface ApplicationContext
        Parameters:
        actionStore - the new action store
      • newBuilder

        public Builder newBuilder()
        Returns a new Builder instance. This implementation obtains the builder instance from the global bean context.
        Specified by:
        newBuilder in interface ApplicationContext
        Returns:
        the new Builder instance
      • initBuilderData

        public ApplicationBuilderData initBuilderData()
        Returns an initialized 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:
        • the parent BeanContext
        • the default resource group
        • the menu icon flag
        • the tool bar text flag
        • the transformer context
        • the parent window
        • the action store: Here the following strategy is used: if the ActionStore 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.
        • the MessageOutput object
        • the CommandQueue
        • the BindingStrategy
        • a BeanCreationListener is set that can inject a reference to the central Application object into beans implementing the ApplicationClient interface
        Specified by:
        initBuilderData in interface ApplicationContext
        Returns:
        an initialized GUI builder parameter object
      • getTypedProperty

        public <T> T getTypedProperty​(Class<T> propCls)
        Returns the value of the specified typed property or null if it cannot be found.
        Specified by:
        getTypedProperty in interface TransformerContext
        Type Parameters:
        T - the type of the property
        Parameters:
        propCls - the property class
        Returns:
        the value of this typed property
      • setTypedProperty

        public <T> void setTypedProperty​(Class<T> propCls,
                                         T value)
        Sets the value of the given typed property. Note: This method is thread-safe. It ensures proper synchronization so that the property is visible to other threads, too.
        Specified by:
        setTypedProperty in interface ApplicationContext
        Type Parameters:
        T - the type of the property
        Parameters:
        propCls - the property class (must not be null)
        value - the new value (null for clearing this property)
        Throws:
        IllegalArgumentException - if the property class is null
      • fetchBindingStrategy

        protected BindingStrategy fetchBindingStrategy()
        Obtains the 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.
        Returns:
        the BindingStrategy