org.springframework.richclient.application.config
Class DefaultApplicationObjectConfigurer

Show UML class diagram
java.lang.Object
  extended by org.springframework.richclient.application.config.DefaultApplicationObjectConfigurer
All Implemented Interfaces:
BeanPostProcessor, ApplicationObjectConfigurer

public class DefaultApplicationObjectConfigurer
extends Object
implements ApplicationObjectConfigurer, BeanPostProcessor

The default implementation of the ApplicationObjectConfigurer interface. This class makes use of several application services in order to determine the property values to be applied to objects being configured. For example, some string properties will be retrieved from the application's message resource bundle using a MessageSource. To configure an object with images and icons, an ImageSource and IconSource respectively will be used. Subclasses can modify this behaviour by overriding the configure(Object, String) method but it may be more convenient to override some of the various methods that deal specificly with objects that implement certain 'configurable' interfaces, such as LabelConfigurable or TitleConfigurable. See the javadoc of the configure(Object, String) method for more details.

Author:
Keith Donald, Kevin Stembridge

Field Summary
static String CAPTION_KEY
          The key fragment used to retrieve the caption for a given object.
static String DESCRIPTION_KEY
          The key fragment used to retrieve the description for a given object.
static String DISABLED_ICON_KEY
          The key fragment used to retrieve the disabled icon for a given object.
static String ICON_KEY
          The key fragment used to retrieve the icon for a given object.
static String IMAGE_KEY
          The key fragment used to retrieve the image for a given object.
static String LABEL_KEY
          The key fragment used to retrieve the label for a given object.
protected  org.apache.commons.logging.Log logger
          Class logger, available to subclasses.
static String PRESSED_ICON_KEY
          The key fragment used to retrieve the pressed icon for a given object.
static String ROLLOVER_ICON_KEY
          The key fragment used to retrieve the rollover icon for a given object.
static String SELECTED_ICON_KEY
          The key fragment used to retrieve the selected icon for a given object.
static String TITLE_KEY
          The key fragment used to retrieve the title for a given object.
 
Constructor Summary
DefaultApplicationObjectConfigurer()
          Creates a new DefaultApplicationObjectConfigurer that will obtain required services from the application services locator.
DefaultApplicationObjectConfigurer(MessageSource messageSource)
          Creates a new DefaultApplicationObjectConfigurer that will use the given message source.
DefaultApplicationObjectConfigurer(MessageSource messageSource, ImageSource imageSource)
          Creates a new DefaultApplicationObjectConfigurer that will use the given message and image sources.
DefaultApplicationObjectConfigurer(MessageSource messageSource, ImageSource imageSource, IconSource iconSource, SecurityControllerManager securityControllerManager)
          Creates a new DefaultApplicationObjectConfigurer that will use the given message, image and icon sources.
 
Method Summary
 void configure(Object object, String objectName)
          Configures the given object according to the interfaces that it implements.
protected  void configureColor(ColorConfigurable configurable, String objectName)
          Sets the foreground and background colours of the given object.
protected  void configureCommandIcons(CommandIconConfigurable configurable, String objectName)
          Sets the icons of the given object.
protected  void configureCommandLabel(CommandLabelConfigurable configurable, String objectName)
          Sets the CommandButtonLabelInfo of the given object.
protected  void configureDescription(DescriptionConfigurable configurable, String objectName)
          Sets the description and caption of the given object.
protected  void configureIcon(IconConfigurable configurable, String objectName)
          Sets the icon of the given object.
protected  void configureImage(ImageConfigurable configurable, String objectName)
          Sets the image of the given object.
protected  void configureLabel(LabelConfigurable configurable, String objectName)
          Sets the LabelInfo of the given object.
protected  void configureSecurityController(SecurityControllable controllable, String objectName)
          Associates the given object with a security controller if it implements the SecurityControllable interface.
protected  void configureTitle(TitleConfigurable configurable, String objectName)
          Sets the title of the given object.
protected  IconSource getIconSource()
          Returns this instance's icon source.
protected  ImageSource getImageSource()
          Returns this instance's image source.
protected  Locale getLocale()
          Returns the system default locale.
protected  MessageSource getMessageSource()
          Returns this instance's message source.
protected  SecurityControllerManager getSecurityControllerManager()
          Returns this instance's security controller manager.
 Object postProcessAfterInitialization(Object bean, String beanName)
          A default implemenation, performing no operation.
 Object postProcessBeforeInitialization(Object bean, String beanName)
          Configures the given object.
protected  void setIconInfo(CommandIconConfigurable object, String objectName, boolean large)
           
 void setLoadOptionalIcons(boolean loadOptionalIcons)
          Sets the flag that determines if optional icons will be loaded for any CommandIconConfigurable objects that are configured by this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRESSED_ICON_KEY

public static final String PRESSED_ICON_KEY
The key fragment used to retrieve the pressed icon for a given object.

See Also:
Constant Field Values

DISABLED_ICON_KEY

public static final String DISABLED_ICON_KEY
The key fragment used to retrieve the disabled icon for a given object.

See Also:
Constant Field Values

ROLLOVER_ICON_KEY

public static final String ROLLOVER_ICON_KEY
The key fragment used to retrieve the rollover icon for a given object.

See Also:
Constant Field Values

SELECTED_ICON_KEY

public static final String SELECTED_ICON_KEY
The key fragment used to retrieve the selected icon for a given object.

See Also:
Constant Field Values

ICON_KEY

public static final String ICON_KEY
The key fragment used to retrieve the icon for a given object.

See Also:
Constant Field Values

IMAGE_KEY

public static final String IMAGE_KEY
The key fragment used to retrieve the image for a given object.

See Also:
Constant Field Values

DESCRIPTION_KEY

public static final String DESCRIPTION_KEY
The key fragment used to retrieve the description for a given object.

See Also:
Constant Field Values

CAPTION_KEY

public static final String CAPTION_KEY
The key fragment used to retrieve the caption for a given object.

See Also:
Constant Field Values

TITLE_KEY

public static final String TITLE_KEY
The key fragment used to retrieve the title for a given object.

See Also:
Constant Field Values

LABEL_KEY

public static final String LABEL_KEY
The key fragment used to retrieve the label for a given object.

See Also:
Constant Field Values

logger

protected final org.apache.commons.logging.Log logger
Class logger, available to subclasses.

Constructor Detail

DefaultApplicationObjectConfigurer

public DefaultApplicationObjectConfigurer()
Creates a new DefaultApplicationObjectConfigurer that will obtain required services from the application services locator.


DefaultApplicationObjectConfigurer

public DefaultApplicationObjectConfigurer(MessageSource messageSource)
Creates a new DefaultApplicationObjectConfigurer that will use the given message source. Other application services will be retrieved using the application services locator.

Parameters:
messageSource - The message source. May be null.

DefaultApplicationObjectConfigurer

public DefaultApplicationObjectConfigurer(MessageSource messageSource,
                                          ImageSource imageSource)
Creates a new DefaultApplicationObjectConfigurer that will use the given message and image sources. Other application services will be retrieved using the application services locator.

Parameters:
messageSource - The message source. May be null.
imageSource - The image source. May be null.

DefaultApplicationObjectConfigurer

public DefaultApplicationObjectConfigurer(MessageSource messageSource,
                                          ImageSource imageSource,
                                          IconSource iconSource,
                                          SecurityControllerManager securityControllerManager)
Creates a new DefaultApplicationObjectConfigurer that will use the given message, image and icon sources. If any of these services are null, they will be retrieved using the application services locator.

Parameters:
messageSource - The message source. May be null.
imageSource - The image source. May be null.
iconSource - The icon source. May be null.
securityControllerManager - The security controller manager. May be null.
Method Detail

setLoadOptionalIcons

public void setLoadOptionalIcons(boolean loadOptionalIcons)
Sets the flag that determines if optional icons will be loaded for any CommandIconConfigurable objects that are configured by this instance. The default is true.

Parameters:
loadOptionalIcons - The flag to load optional options.

getMessageSource

protected MessageSource getMessageSource()
Returns this instance's message source. If a source was not provided at construction, it will be retrieved by the application services locator.

Returns:
The message source, never null.
Throws:
ServiceNotFoundException - if a source was not provided at construction time and the application services locator cannot find an instance of a message source.

getIconSource

protected IconSource getIconSource()
Returns this instance's icon source. If a source was not provided at construction, it will be retrieved by the application services locator.

Returns:
The icon source, never null.
Throws:
ServiceNotFoundException - if a source was not provided at construction time and the application services locator cannot find an instance of an icon source.

getImageSource

protected ImageSource getImageSource()
Returns this instance's image source. If a source was not provided at construction, it will be retrieved by the application services locator.

Returns:
The image source, never null.
Throws:
ServiceNotFoundException - if a source was not provided at construction time and the application services locator cannot find an instance of an image source.

getSecurityControllerManager

protected SecurityControllerManager getSecurityControllerManager()
Returns this instance's security controller manager. If the security manager was not provided at construction, it will be retrieved by the application services locator.

Returns:
The security controller manager, never null.
Throws:
ServiceNotFoundException - if a security controller manager was not provided at construction time and the application services locator cannot find an instance of the service.

configure

public void configure(Object object,
                      String objectName)
Configures the given object according to the interfaces that it implements.

This implementation forwards the object to the following overridable methods in the order listed. Subclasses can use these methods as hooks to modify the default configuration behaviour without having to override this method entirely.

Specified by:
configure in interface ApplicationObjectConfigurer
Parameters:
object - The object to be configured. May be null.
objectName - The name for the object, expected to be unique within the application. If object is not null, then objectName must also be non-null.
Throws:
IllegalArgumentException - if object is not null, but objectName is null.

configureTitle

protected void configureTitle(TitleConfigurable configurable,
                              String objectName)
Sets the title of the given object. The title is loaded from this instance's MessageSource using a message code in the format
                     <objectName>.title
 

Parameters:
configurable - The object to be configured. Must not be null.
objectName - The name of the configurable object, unique within the application. Must not be null.
Throws:
IllegalArgumentException - if either argument is null.

configureLabel

protected void configureLabel(LabelConfigurable configurable,
                              String objectName)
Sets the LabelInfo of the given object. The label info is created after loading the encoded label string from this instance's MessageSource using a message code in the format
                     <objectName>.label
 

Parameters:
configurable - The object to be configured. Must not be null.
objectName - The name of the configurable object, unique within the application. Must not be null.
Throws:
IllegalArgumentException - if either argument is null.

configureColor

protected void configureColor(ColorConfigurable configurable,
                              String objectName)
Sets the foreground and background colours of the given object. Use the following message codes:
 <objectName>.foreground
 <objectName>.background
 

Parameters:
configurable - The object to be configured. Must not be null.
objectName - The name of the configurable object, unique within the application. Must not be null.
Throws:
IllegalArgumentException - if either argument is null.

configureCommandLabel

protected void configureCommandLabel(CommandLabelConfigurable configurable,
                                     String objectName)
Sets the CommandButtonLabelInfo of the given object. The label info is created after loading the encoded label string from this instance's MessageSource using a message code in the format
   <objectName>.label
 

Parameters:
configurable - The object to be configured. Must not be null.
objectName - The name of the configurable object, unique within the application. Must not be null.
Throws:
IllegalArgumentException - if either argument is null.

configureDescription

protected void configureDescription(DescriptionConfigurable configurable,
                                    String objectName)
Sets the description and caption of the given object. These values are loaded from this instance's MessageSource using message codes in the format
   <objectName>.description
 
and
   <objectName>.caption
 
respectively.

Parameters:
configurable - The object to be configured. Must not be null.
objectName - The name of the configurable object, unique within the application. Must not be null.
Throws:
IllegalArgumentException - if either argument is null.

configureImage

protected void configureImage(ImageConfigurable configurable,
                              String objectName)
Sets the image of the given object. The image is loaded from this instance's ImageSource using a key in the format
   <objectName>.image
 
If the image source cannot find an image under that key, the object's image will be set to null.

Parameters:
configurable - The object to be configured. Must not be null.
objectName - The name of the configurable object, unique within the application. Must not be null.
Throws:
IllegalArgumentException - if either argument is null.

configureIcon

protected void configureIcon(IconConfigurable configurable,
                             String objectName)
Sets the icon of the given object. The icon is loaded from this instance's IconSource using a key in the format
   <objectName>.icon
 
If the icon source cannot find an icon under that key, the object's icon will be set to null.

Parameters:
configurable - The object to be configured. Must not be null.
objectName - The name of the configurable object, unique within the application. Must not be null.
Throws:
IllegalArgumentException - if either argument is null.

configureCommandIcons

protected void configureCommandIcons(CommandIconConfigurable configurable,
                                     String objectName)
Sets the icons of the given object.

The icons are loaded from this instance's IconSource. using a key in the format

   <objectName>.someIconType
 

The keys used to retrieve large icons from the icon source are created by concatenating the given objectName with a dot (.), the text 'large' and then an icon type like so:

  <myObjectName>.large.someIconType
 

If the icon source cannot find an icon under that key, the object's icon will be set to null.

If the loadOptionalIcons flag is set to true (it is by default) all the following icon types will be used. If the flag is false, only the first will be used:

Parameters:
configurable - The object to be configured. Must not be null.
objectName - The name of the configurable object, unique within the application. Must not be null.
Throws:
IllegalArgumentException - if either argument is null.

configureSecurityController

protected void configureSecurityController(SecurityControllable controllable,
                                           String objectName)
Associates the given object with a security controller if it implements the SecurityControllable interface.

Parameters:
object - The object to be configured.
objectName - The name (id) of the object.
Throws:
BeansException - if a referenced security controller is not found or is of the wrong type

setIconInfo

protected void setIconInfo(CommandIconConfigurable object,
                           String objectName,
                           boolean large)

postProcessBeforeInitialization

public Object postProcessBeforeInitialization(Object bean,
                                              String beanName)
                                       throws BeansException
Configures the given object.

Specified by:
postProcessBeforeInitialization in interface BeanPostProcessor
Throws:
BeansException
See Also:
configure(Object, String)

getLocale

protected Locale getLocale()
Returns the system default locale.

Returns:
The system default locale, never null.

postProcessAfterInitialization

public Object postProcessAfterInitialization(Object bean,
                                             String beanName)
                                      throws BeansException
A default implemenation, performing no operation.

Specified by:
postProcessAfterInitialization in interface BeanPostProcessor
Throws:
BeansException


Copyright © 2004-2009 The Spring Framework. All Rights Reserved.