org.springframework.context.HierarchicalMessageSource Java Examples
The following examples show how to use
org.springframework.context.HierarchicalMessageSource.
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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 #9
Source File: RestHandlerExceptionResolverBuilder.java From spring-rest-exception-handler with Apache License 2.0 | 5 votes |
HierarchicalMessageSource resolveRootMessageSource(MessageSource messageSource) { if (messageSource instanceof HierarchicalMessageSource) { MessageSource parent = ((HierarchicalMessageSource) messageSource).getParentMessageSource(); return parent != null ? resolveRootMessageSource(parent) : (HierarchicalMessageSource) messageSource; } else { return null; } }
Example #10
Source File: RestHandlerExceptionResolverBuilder.java From spring-rest-exception-handler with Apache License 2.0 | 4 votes |
public RestHandlerExceptionResolver build() { if (withDefaultMessageSource) { if (messageSource != null) { // set default message source as top parent HierarchicalMessageSource messages = resolveRootMessageSource(messageSource); if (messages != null) { messages.setParentMessageSource(createDefaultMessageSource()); } } else { messageSource = createDefaultMessageSource(); } } if (withDefaultHandlers) { // add default handlers putAllIfAbsent(exceptionHandlers, getDefaultHandlers()); } // initialize handlers for (RestExceptionHandler handler : exceptionHandlers.values()) { if (messageSource != null && handler instanceof MessageSourceAware) { ((MessageSourceAware) handler).setMessageSource(messageSource); } if (messageInterpolator != null && handler instanceof MessageInterpolatorAware) { ((MessageInterpolatorAware) handler).setMessageInterpolator(messageInterpolator); } } RestHandlerExceptionResolver resolver = new RestHandlerExceptionResolver(); resolver.setExceptionHandlers((Map) exceptionHandlers); if (httpMessageConverters != null) { resolver.setMessageConverters(httpMessageConverters); } if (contentNegotiationManager != null) { resolver.setContentNegotiationManager(contentNegotiationManager); } if (defaultContentType != null) { resolver.setDefaultContentType(defaultContentType); } resolver.afterPropertiesSet(); return resolver; }