Example usage for org.springframework.context.support AbstractMessageSource setParentMessageSource

List of usage examples for org.springframework.context.support AbstractMessageSource setParentMessageSource

Introduction

In this page you can find the example usage for org.springframework.context.support AbstractMessageSource setParentMessageSource.

Prototype

@Override
    public void setParentMessageSource(@Nullable MessageSource parent) 

Source Link

Usage

From source file:nz.co.senanque.perspectivemanager.BundleListenerImpl.java

public void add(String bundleName, BundleRoot root) {
    m_logger.debug("added bundle {}", root.getProperties().get("bundle.name"));
    String bundleNameNoVersion = (String) root.getProperties().get("Bundle-Name");
    try {//from   w ww. ja  v  a 2s. c  om
        SubApplication subApplication = (SubApplication) root.getApplicationContext().getBean("SubApplication");
        SubApplication existing = m_subApplications.get(bundleNameNoVersion);
        if (existing == null || (existing.getVersion().compareToIgnoreCase(subApplication.getVersion()) < 0)) {
            // If this is the latest version of this bundle then set the app message source as the parent message source
            // and add the sub application to the map.
            AbstractMessageSource messageSource = (AbstractMessageSource) subApplication.getMessageSource();
            messageSource.setParentMessageSource(getMessageSource());
            m_subApplications.put(bundleNameNoVersion, subApplication);
        }
    } catch (BeansException e) {
        // ignore bundles with missing bean, assume they do something else.
    }
}

From source file:nz.co.senanque.perspectiveslibrary.BundleListenerImpl.java

/**
 * Given a BundleVersion set up the Sub Application.
 * Do nothing if there is an existing Sub Application with a later version.
 * @param bundleVersion//from w w  w.  j a va2 s. c om
 */
private void addSubApplication(BundleVersion bundleVersion) {
    String bundleName = bundleVersion.getName();
    try {
        BundleRoot root = bundleVersion.getRoot();
        SubApplication subApplication = (SubApplication) root.getApplicationContext().getBean("SubApplication");
        SubApplication existing = m_subApplications.get(bundleName);
        if (existing == null || (existing.getVersion().compareToIgnoreCase(subApplication.getVersion()) < 0)) {
            // If this is the latest version of this bundle then set the app message source as the parent message source
            // and add the sub application to the map.
            AbstractMessageSource messageSource = (AbstractMessageSource) subApplication.getMessageSource();
            messageSource.setParentMessageSource(getMessageSource());
            m_subApplications.put(bundleName, subApplication);
            subApplication.setBundleVersion(bundleVersion);
        }
    } catch (BeansException e) {
        // ignore bundles with missing bean, assume they do something else.
    }
    m_logger.info("added SubApplication {}", bundleVersion.getId());
}

From source file:com.acc.storefront.web.theme.StorefrontResourceBundleSource.java

protected MessageSource createMessageSource(final String basename, final MessageSource parentMessageSource) {
    final AbstractMessageSource messageSource = createMessageSource(basename);
    messageSource.setParentMessageSource(parentMessageSource);
    messageSource.setUseCodeAsDefaultMessage(true);
    return messageSource;
}

From source file:net.solarnetwork.node.runtime.JobSettingSpecifierProvider.java

/**
 * Construct with settings UID./*w  ww.j  av a  2  s. c  o  m*/
 * 
 * @param settingUID
 *        the setting UID
 * @param source
 *        a message source
 */
public JobSettingSpecifierProvider(String settingUID, MessageSource source) {
    super();
    this.settingUID = settingUID;
    this.messageSource = source;
    if (source == null || !hasMessage(source, "title")) {
        messages.put("title", new MessageFormat(titleValue(settingUID)));
    }

    AbstractMessageSource msgSource = new AbstractMessageSource() {

        @Override
        protected MessageFormat resolveCode(String code, Locale locale) {
            return messages.get(code);
        }
    };
    msgSource.setParentMessageSource(source);
    this.messageSource = msgSource;
}