org.openmrs.messagesource.impl
Class MessageSourceServiceImpl

java.lang.Object
  extended by org.openmrs.messagesource.impl.MessageSourceServiceImpl
All Implemented Interfaces:
MessageSourceService, MutableMessageSource, org.springframework.context.HierarchicalMessageSource, org.springframework.context.MessageSource

public class MessageSourceServiceImpl
extends java.lang.Object
implements MessageSourceService

Extensible implementation of the MessageSourceService, which relies on injected implementations of MutableMessageSource to actually provide the services. The sub-services are loaded by special BeanPostProcessor handling, which looks for beans named For example: ResourceBundleMessageSourceService can be specified in the applicationContext-service.xml file to use the usual .properties files to provide messages.


Constructor Summary
MessageSourceServiceImpl()
           
 
Method Summary
 void addPresentation(PresentationMessage message)
          Adds a presentation message to the source.
 MutableMessageSource getActiveMessageSource()
          Gets the message source service which is currently providing services.
 java.util.Collection<java.util.Locale> getLocales()
          Gets the locales which are available from the current message source.
 java.lang.String getMessage(org.springframework.context.MessageSourceResolvable resolvable, java.util.Locale locale)
           
 java.lang.String getMessage(java.lang.String s)
          Get the message with the given code from the current user's selected locale.
 java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, java.util.Locale locale)
           
 java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, java.lang.String defaultMessage, java.util.Locale locale)
           
 java.util.Set<MutableMessageSource> getMessageSources()
           
 org.springframework.context.MessageSource getParentMessageSource()
           
 PresentationMessage getPresentation(java.lang.String key, java.util.Locale forLocale)
          Gets the PresentationMessage for a particular locale.
 java.util.Collection<PresentationMessage> getPresentations()
          Returns all available messages.
 java.util.Collection<PresentationMessage> getPresentationsInLocale(java.util.Locale locale)
          Gets alll the available messages in a particular locale, packaged as PresentationMessages.
 void merge(MutableMessageSource fromSource, boolean overwrite)
          Merges messages from another message source into the active (current) message source.
 void publishProperties(java.util.Properties props, java.lang.String locale, java.lang.String namespace, java.lang.String name, java.lang.String version)
          Deprecated. use merge(MutableMessageSource, boolean) instead
 void removePresentation(PresentationMessage message)
          Removes a presentation message from the source.
 void setActiveMessageSource(MutableMessageSource activeMessageSource)
          Sets the message source service which will actually provide services.
 void setMessageSources(java.util.Set<MutableMessageSource> availableMessageSources)
           
 void setParentMessageSource(org.springframework.context.MessageSource parent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageSourceServiceImpl

public MessageSourceServiceImpl()
Method Detail

getMessage

public java.lang.String getMessage(java.lang.String s)
Description copied from interface: MessageSourceService
Get the message with the given code from the current user's selected locale.

Specified by:
getMessage in interface MessageSourceService
Parameters:
s - message code to retrieve
Returns:
the translated message
See Also:
MessageSourceService.getMessage(java.lang.String)

getActiveMessageSource

public MutableMessageSource getActiveMessageSource()
Gets the message source service which is currently providing services.

Specified by:
getActiveMessageSource in interface MessageSourceService
Returns:
the activeMessageSource

setActiveMessageSource

public void setActiveMessageSource(MutableMessageSource activeMessageSource)
Sets the message source service which will actually provide services.

Specified by:
setActiveMessageSource in interface MessageSourceService
Parameters:
activeMessageSource - the activeMessageSourceService to set

getLocales

public java.util.Collection<java.util.Locale> getLocales()
Gets the locales which are available from the current message source.

Specified by:
getLocales in interface MutableMessageSource
Returns:
available message locales
See Also:
MutableMessageSource.getLocales()

publishProperties

public void publishProperties(java.util.Properties props,
                              java.lang.String locale,
                              java.lang.String namespace,
                              java.lang.String name,
                              java.lang.String version)
Deprecated. use merge(MutableMessageSource, boolean) instead

Presumes to append the messages to a message.properties file which is already being monitored by the super ReloadableResourceBundleMessageSource. This is a blind, trusting hack.

Specified by:
publishProperties in interface MessageSourceService
Specified by:
publishProperties in interface MutableMessageSource
Parameters:
props - key/value properties for the messages
locale - locale in which the messages are expressed
namespace - namespace within which the properties are valid ("" for generic, "module" for modules, etc)
name - unique name for the properties within the namespace
version - version of the properties
See Also:
MessageSourceService.publishProperties(Properties, String, String, String, String)

getPresentations

public java.util.Collection<PresentationMessage> getPresentations()
Returns all available messages.

Specified by:
getPresentations in interface MutableMessageSource
Returns:
collection of presentation messages
See Also:
MutableMessageSource.getPresentations()

getMessage

public java.lang.String getMessage(org.springframework.context.MessageSourceResolvable resolvable,
                                   java.util.Locale locale)
Specified by:
getMessage in interface org.springframework.context.MessageSource
See Also:
MessageSource.getMessage(org.springframework.context.MessageSourceResolvable, java.util.Locale)

getMessage

public java.lang.String getMessage(java.lang.String code,
                                   java.lang.Object[] args,
                                   java.util.Locale locale)
                            throws org.springframework.context.NoSuchMessageException
Specified by:
getMessage in interface org.springframework.context.MessageSource
Throws:
org.springframework.context.NoSuchMessageException
See Also:
MessageSource.getMessage(java.lang.String, java.lang.Object[], java.util.Locale)

getMessage

public java.lang.String getMessage(java.lang.String code,
                                   java.lang.Object[] args,
                                   java.lang.String defaultMessage,
                                   java.util.Locale locale)
Specified by:
getMessage in interface org.springframework.context.MessageSource
See Also:
MessageSource.getMessage(java.lang.String, java.lang.Object[], java.lang.String, java.util.Locale)

addPresentation

public void addPresentation(PresentationMessage message)
Description copied from interface: MutableMessageSource
Adds a presentation message to the source. This operation should overwrite any existing message which conflicts (has the same code and locale).

Specified by:
addPresentation in interface MutableMessageSource
Parameters:
message - message to add to the source
See Also:
MutableMessageSource.addPresentation(org.openmrs.messagesource.PresentationMessage)

removePresentation

public void removePresentation(PresentationMessage message)
Description copied from interface: MutableMessageSource
Removes a presentation message from the source.

Specified by:
removePresentation in interface MutableMessageSource
Parameters:
message - the message to remove
See Also:
MutableMessageSource.addPresentation(org.openmrs.messagesource.PresentationMessage)

getMessageSources

public java.util.Set<MutableMessageSource> getMessageSources()
Specified by:
getMessageSources in interface MessageSourceService
Returns:
the availableMessageSources

setMessageSources

public void setMessageSources(java.util.Set<MutableMessageSource> availableMessageSources)
Specified by:
setMessageSources in interface MessageSourceService
Parameters:
availableMessageSources - the availableMessageSources to set

merge

public void merge(MutableMessageSource fromSource,
                  boolean overwrite)
Merges messages from another message source into the active (current) message source.

Specified by:
merge in interface MutableMessageSource
Parameters:
fromSource - message source from which messages should be merge
overwrite - whether to overwrite existing messages
See Also:
MutableMessageSource.merge(MutableMessageSource, boolean)

getPresentation

public PresentationMessage getPresentation(java.lang.String key,
                                           java.util.Locale forLocale)
Description copied from interface: MutableMessageSource
Gets the PresentationMessage for a particular locale.

Specified by:
getPresentation in interface MutableMessageSource
Parameters:
key - textual key for the message
forLocale - locale for which to get the message
Returns:
corresponding PresentationMessage, or null if not available
See Also:
MutableMessageSource.getPresentation(java.lang.String, java.util.Locale)

getPresentationsInLocale

public java.util.Collection<PresentationMessage> getPresentationsInLocale(java.util.Locale locale)
Description copied from interface: MutableMessageSource
Gets alll the available messages in a particular locale, packaged as PresentationMessages.

Specified by:
getPresentationsInLocale in interface MutableMessageSource
Parameters:
locale - locale for which to get the messages
Returns:
collection of PresentationMessages in the locale
See Also:
MutableMessageSource.getPresentationsInLocale(java.util.Locale)

getParentMessageSource

public org.springframework.context.MessageSource getParentMessageSource()
Specified by:
getParentMessageSource in interface org.springframework.context.HierarchicalMessageSource
See Also:
HierarchicalMessageSource.getParentMessageSource()

setParentMessageSource

public void setParentMessageSource(org.springframework.context.MessageSource parent)
Specified by:
setParentMessageSource in interface org.springframework.context.HierarchicalMessageSource
See Also:
HierarchicalMessageSource.setParentMessageSource(org.springframework.context.MessageSource)

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change