net.sf.jguiraffe.gui.app
Class ApplicationContextImpl

java.lang.Object
  extended by net.sf.jguiraffe.gui.app.ApplicationContextImpl
All Implemented Interfaces:
ApplicationContext, TransformerContext

public class ApplicationContextImpl
extends java.lang.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.

Version:
$Id: ApplicationContextImpl.java 172 2009-11-28 20:05:18Z oheger $
Author:
Oliver Heger
See Also:
TransformerContext

Constructor Summary
ApplicationContextImpl()
          Creates a new instance of ApplicationContextImpl.
ApplicationContextImpl(java.util.Locale locale)
          Creates a new instance of ApplicationContextImpl and sets the current locale.
ApplicationContextImpl(java.util.Locale locale, ResourceManager resMan)
          Creates a new instance of ApplicationContextImpl and sets the current locale and the resource manager to use.
 
Method Summary
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 class loader provider.
 org.apache.commons.configuration.Configuration getConfiguration()
          Returns a reference to the global configuration.
 GUISynchronizer getGUISynchronizer()
          Returns the GUISynchronizer.
 java.util.Locale getLocale()
          Returns the actual locale.
 Window getMainWindow()
          Returns the application's main window.
 MessageOutput getMessageOutput()
          Returns a reference to the object for displaying messages.
 java.lang.Object getResource(Message msg)
          Convenience method for looking up a resource that is specified as a Message object.
 java.lang.Object getResource(java.lang.Object resID)
          Convenience method for looking up a resource.
 java.lang.Object getResource(java.lang.Object groupID, java.lang.Object resID)
          Convenience method for looking up a resource specified as group and resource ID.
 ResourceManager getResourceManager()
          Returns the actual resource manager.
 java.lang.String getResourceText(Message msg)
          Convenience method for looking up the text of a resource specified as a Message object.
 java.lang.String getResourceText(java.lang.Object resID)
          Convenience method for looking up the text of a specified resource.
 java.lang.String getResourceText(java.lang.Object groupID, java.lang.Object resID)
          Convenience method for looking up the text of a resource specified as group and resource ID.
<T> T
getTypedProperty(java.lang.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(java.lang.Object resMsg, java.lang.Object resTitle, int msgType, int btnType)
          A convenience method for displaying a message box.
 Builder newBuilder()
          Returns a new Builder instance.
 java.util.Map<java.lang.String,java.lang.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(java.util.Locale locale)
          Sets the actual 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(java.lang.Class<T> propCls, T value)
          Sets the value of the given typed property.
 void setValidationMessageHandler(ValidationMessageHandler validationMessageHandler)
          Sets the ValidationMessageHandler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplicationContextImpl

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


ApplicationContextImpl

public ApplicationContextImpl(java.util.Locale locale)
Creates a new instance of ApplicationContextImpl and sets the current locale.

Parameters:
locale - the Locale

ApplicationContextImpl

public ApplicationContextImpl(java.util.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 java.util.Locale getLocale()
Returns the actual 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(java.util.Locale locale)
Sets the actual locale.

Specified by:
setLocale in interface ApplicationContext
Parameters:
locale - the new Locale

getResourceManager

public ResourceManager getResourceManager()
Returns the actual resource manager.

Specified by:
getResourceManager in interface TransformerContext
Returns:
the ResourceManager for accessing resources

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

properties

public java.util.Map<java.lang.String,java.lang.Object> properties()
Returns a map with properties maintained by this context.

Specified by:
properties in interface TransformerContext
Returns:
a map with properties

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

getBeanContext

public BeanContext getBeanContext()
Returns the global bean context.

Specified by:
getBeanContext in interface ApplicationContext
Returns:
the bean context

setBeanContext

public void setBeanContext(BeanContext beanContext)
Sets the global bean context.

Parameters:
beanContext - the new bean context

getClassLoaderProvider

public ClassLoaderProvider getClassLoaderProvider()
Returns the class loader provider.

Specified by:
getClassLoaderProvider in interface ApplicationContext
Returns:
the ClassLoaderProvider

setClassLoaderProvider

public void setClassLoaderProvider(ClassLoaderProvider classLoaderProvider)
Sets the ClassLoaderProvider.

Specified by:
setClassLoaderProvider in interface ApplicationContext
Parameters:
classLoaderProvider - the new class loader provider

getValidationMessageHandler

public ValidationMessageHandler getValidationMessageHandler()
Returns the ValidationMessageHandler.

Specified by:
getValidationMessageHandler in interface TransformerContext
Returns:
the ValidationMessageHandler

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:
java.lang.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 java.lang.Object getResource(java.lang.Object groupID,
                                    java.lang.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:
java.util.MissingResourceException - if the resource cannot be found

getResource

public java.lang.Object getResource(Message msg)
Convenience method for looking up a resource that is specified as a Message object.

Specified by:
getResource in interface ApplicationContext
Parameters:
msg - the resource definition (must not be null)
Returns:
the found resource
Throws:
java.util.MissingResourceException - if the resource cannot be found
java.lang.IllegalArgumentException - if then message is undefined

getResource

public java.lang.Object getResource(java.lang.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:
java.util.MissingResourceException - if the resource cannot be found

getResourceText

public java.lang.String getResourceText(java.lang.Object groupID,
                                        java.lang.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:
java.util.MissingResourceException - if the resource cannot be found

getResourceText

public java.lang.String getResourceText(Message msg)
Convenience method for looking up the text of a resource specified as a Message object.

Specified by:
getResourceText in interface ApplicationContext
Parameters:
msg - defines the resource (must not be null)
Returns:
the found resource
Throws:
java.util.MissingResourceException - if the resource cannot be found
java.lang.IllegalArgumentException - if the message is undefined

getResourceText

public java.lang.String getResourceText(java.lang.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:
java.util.MissingResourceException - if the resource cannot be found

messageBox

public int messageBox(java.lang.Object resMsg,
                      java.lang.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

getActionStore

public ActionStore getActionStore()
Returns the application's ActionStore.

Specified by:
getActionStore in interface ApplicationContext
Returns:
the application's action store

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:

Specified by:
initBuilderData in interface ApplicationContext
Returns:
an initialized GUI builder parameter object

getTypedProperty

public <T> T getTypedProperty(java.lang.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(java.lang.Class<T> propCls,
                                 T value)
Sets the value of the given typed property.

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:
java.lang.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


Copyright © 2009 The JGUIraffe Team. All Rights Reserved.