Java Code Examples for org.springframework.context.HierarchicalMessageSource#getParentMessageSource()

The following examples show how to use org.springframework.context.HierarchicalMessageSource#getParentMessageSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractApplicationContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Initialize the MessageSource.
 * Use parent's if none defined in this context.
 */
protected void initMessageSource() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(MESSAGE_SOURCE_BEAN_NAME)) {
		this.messageSource = beanFactory.getBean(MESSAGE_SOURCE_BEAN_NAME, MessageSource.class);
		// Make MessageSource aware of parent MessageSource.
		if (this.parent != null && this.messageSource instanceof HierarchicalMessageSource) {
			HierarchicalMessageSource hms = (HierarchicalMessageSource) this.messageSource;
			if (hms.getParentMessageSource() == null) {
				// Only set parent context as parent MessageSource if no parent MessageSource
				// registered already.
				hms.setParentMessageSource(getInternalParentMessageSource());
			}
		}
		if (logger.isTraceEnabled()) {
			logger.trace("Using MessageSource [" + this.messageSource + "]");
		}
	}
	else {
		// Use empty MessageSource to be able to accept getMessage calls.
		DelegatingMessageSource dms = new DelegatingMessageSource();
		dms.setParentMessageSource(getInternalParentMessageSource());
		this.messageSource = dms;
		beanFactory.registerSingleton(MESSAGE_SOURCE_BEAN_NAME, this.messageSource);
		if (logger.isTraceEnabled()) {
			logger.trace("No '" + MESSAGE_SOURCE_BEAN_NAME + "' bean, using [" + this.messageSource + "]");
		}
	}
}
 
Example 2
Source File: ResourceBundleThemeSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Initialize the MessageSource of the given theme with the
 * one from the corresponding parent of this ThemeSource.
 * @param theme the Theme to (re-)initialize
 */
protected void initParent(Theme theme) {
	if (theme.getMessageSource() instanceof HierarchicalMessageSource) {
		HierarchicalMessageSource messageSource = (HierarchicalMessageSource) theme.getMessageSource();
		if (getParentThemeSource() != null && messageSource.getParentMessageSource() == null) {
			Theme parentTheme = getParentThemeSource().getTheme(theme.getName());
			if (parentTheme != null) {
				messageSource.setParentMessageSource(parentTheme.getMessageSource());
			}
		}
	}
}
 
Example 3
Source File: AbstractApplicationContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Initialize the MessageSource.
 * Use parent's if none defined in this context.
 */
protected void initMessageSource() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(MESSAGE_SOURCE_BEAN_NAME)) {
		this.messageSource = beanFactory.getBean(MESSAGE_SOURCE_BEAN_NAME, MessageSource.class);
		// Make MessageSource aware of parent MessageSource.
		if (this.parent != null && this.messageSource instanceof HierarchicalMessageSource) {
			HierarchicalMessageSource hms = (HierarchicalMessageSource) this.messageSource;
			if (hms.getParentMessageSource() == null) {
				// Only set parent context as parent MessageSource if no parent MessageSource
				// registered already.
				hms.setParentMessageSource(getInternalParentMessageSource());
			}
		}
		if (logger.isTraceEnabled()) {
			logger.trace("Using MessageSource [" + this.messageSource + "]");
		}
	}
	else {
		// Use empty MessageSource to be able to accept getMessage calls.
		DelegatingMessageSource dms = new DelegatingMessageSource();
		dms.setParentMessageSource(getInternalParentMessageSource());
		this.messageSource = dms;
		beanFactory.registerSingleton(MESSAGE_SOURCE_BEAN_NAME, this.messageSource);
		if (logger.isTraceEnabled()) {
			logger.trace("No '" + MESSAGE_SOURCE_BEAN_NAME + "' bean, using [" + this.messageSource + "]");
		}
	}
}
 
Example 4
Source File: ResourceBundleThemeSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Initialize the MessageSource of the given theme with the
 * one from the corresponding parent of this ThemeSource.
 * @param theme the Theme to (re-)initialize
 */
protected void initParent(Theme theme) {
	if (theme.getMessageSource() instanceof HierarchicalMessageSource) {
		HierarchicalMessageSource messageSource = (HierarchicalMessageSource) theme.getMessageSource();
		if (getParentThemeSource() != null && messageSource.getParentMessageSource() == null) {
			Theme parentTheme = getParentThemeSource().getTheme(theme.getName());
			if (parentTheme != null) {
				messageSource.setParentMessageSource(parentTheme.getMessageSource());
			}
		}
	}
}
 
Example 5
Source File: AbstractApplicationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize the MessageSource.
 * Use parent's if none defined in this context.
 */
protected void initMessageSource() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(MESSAGE_SOURCE_BEAN_NAME)) {
		this.messageSource = beanFactory.getBean(MESSAGE_SOURCE_BEAN_NAME, MessageSource.class);
		// Make MessageSource aware of parent MessageSource.
		if (this.parent != null && this.messageSource instanceof HierarchicalMessageSource) {
			HierarchicalMessageSource hms = (HierarchicalMessageSource) this.messageSource;
			if (hms.getParentMessageSource() == null) {
				// Only set parent context as parent MessageSource if no parent MessageSource
				// registered already.
				hms.setParentMessageSource(getInternalParentMessageSource());
			}
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Using MessageSource [" + this.messageSource + "]");
		}
	}
	else {
		// Use empty MessageSource to be able to accept getMessage calls.
		DelegatingMessageSource dms = new DelegatingMessageSource();
		dms.setParentMessageSource(getInternalParentMessageSource());
		this.messageSource = dms;
		beanFactory.registerSingleton(MESSAGE_SOURCE_BEAN_NAME, this.messageSource);
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate MessageSource with name '" + MESSAGE_SOURCE_BEAN_NAME +
					"': using default [" + this.messageSource + "]");
		}
	}
}
 
Example 6
Source File: ResourceBundleThemeSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize the MessageSource of the given theme with the
 * one from the corresponding parent of this ThemeSource.
 * @param theme the Theme to (re-)initialize
 */
protected void initParent(Theme theme) {
	if (theme.getMessageSource() instanceof HierarchicalMessageSource) {
		HierarchicalMessageSource messageSource = (HierarchicalMessageSource) theme.getMessageSource();
		if (getParentThemeSource() != null && messageSource.getParentMessageSource() == null) {
			Theme parentTheme = getParentThemeSource().getTheme(theme.getName());
			if (parentTheme != null) {
				messageSource.setParentMessageSource(parentTheme.getMessageSource());
			}
		}
	}
}
 
Example 7
Source File: AbstractApplicationContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the MessageSource.
 * Use parent's if none defined in this context.
 */
protected void initMessageSource() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(MESSAGE_SOURCE_BEAN_NAME)) {
		this.messageSource = beanFactory.getBean(MESSAGE_SOURCE_BEAN_NAME, MessageSource.class);
		// Make MessageSource aware of parent MessageSource.
		if (this.parent != null && this.messageSource instanceof HierarchicalMessageSource) {
			HierarchicalMessageSource hms = (HierarchicalMessageSource) this.messageSource;
			if (hms.getParentMessageSource() == null) {
				// Only set parent context as parent MessageSource if no parent MessageSource
				// registered already.
				hms.setParentMessageSource(getInternalParentMessageSource());
			}
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Using MessageSource [" + this.messageSource + "]");
		}
	}
	else {
		// Use empty MessageSource to be able to accept getMessage calls.
		DelegatingMessageSource dms = new DelegatingMessageSource();
		dms.setParentMessageSource(getInternalParentMessageSource());
		this.messageSource = dms;
		beanFactory.registerSingleton(MESSAGE_SOURCE_BEAN_NAME, this.messageSource);
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate MessageSource with name '" + MESSAGE_SOURCE_BEAN_NAME +
					"': using default [" + this.messageSource + "]");
		}
	}
}
 
Example 8
Source File: ResourceBundleThemeSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the MessageSource of the given theme with the
 * one from the corresponding parent of this ThemeSource.
 * @param theme the Theme to (re-)initialize
 */
protected void initParent(Theme theme) {
	if (theme.getMessageSource() instanceof HierarchicalMessageSource) {
		HierarchicalMessageSource messageSource = (HierarchicalMessageSource) theme.getMessageSource();
		if (getParentThemeSource() != null && messageSource.getParentMessageSource() == null) {
			Theme parentTheme = getParentThemeSource().getTheme(theme.getName());
			if (parentTheme != null) {
				messageSource.setParentMessageSource(parentTheme.getMessageSource());
			}
		}
	}
}