• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 16671461024

01 Aug 2025 09:25AM UTC coverage: 81.784% (+0.006%) from 81.778%
16671461024

push

github

TAKETODAY
:white_check_mark:

59515 of 77725 branches covered (76.57%)

Branch coverage included in aggregate %.

140858 of 167278 relevant lines covered (84.21%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.36
today-context/src/main/java/infra/context/support/DelegatingMessageSource.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.context.support;
19

20
import java.util.Locale;
21

22
import infra.context.HierarchicalMessageSource;
23
import infra.context.MessageSource;
24
import infra.context.MessageSourceResolvable;
25
import infra.context.NoSuchMessageException;
26
import infra.lang.Nullable;
27

28
/**
29
 * Empty {@link MessageSource} that delegates all calls to the parent MessageSource.
30
 * If no parent is available, it simply won't resolve any message.
31
 *
32
 * <p>Used as placeholder by AbstractApplicationContext, if the context doesn't
33
 * define its own MessageSource. Not intended for direct use in applications.
34
 *
35
 * @author Juergen Hoeller
36
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
37
 * @see AbstractApplicationContext
38
 * @since 4.0
39
 */
40
public class DelegatingMessageSource extends MessageSourceSupport implements HierarchicalMessageSource {
3✔
41

42
  @Nullable
43
  private MessageSource parentMessageSource;
44

45
  @Override
46
  public void setParentMessageSource(@Nullable MessageSource parent) {
47
    this.parentMessageSource = parent;
3✔
48
  }
1✔
49

50
  @Override
51
  @Nullable
52
  public MessageSource getParentMessageSource() {
53
    return this.parentMessageSource;
3✔
54
  }
55

56
  @Override
57
  @Nullable
58
  public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, @Nullable Locale locale) {
59
    if (this.parentMessageSource != null) {
3✔
60
      return this.parentMessageSource.getMessage(code, args, defaultMessage, locale);
8✔
61
    }
62
    else if (defaultMessage != null) {
2✔
63
      return renderDefaultMessage(defaultMessage, args, locale);
6✔
64
    }
65
    else {
66
      return null;
2✔
67
    }
68
  }
69

70
  @Override
71
  public String getMessage(String code, @Nullable Object[] args, @Nullable Locale locale) throws NoSuchMessageException {
72
    if (this.parentMessageSource != null) {
3✔
73
      return this.parentMessageSource.getMessage(code, args, locale);
7✔
74
    }
75
    else {
76
      if (locale == null) {
2!
77
        throw new NoSuchMessageException(code);
×
78
      }
79
      else {
80
        throw new NoSuchMessageException(code, locale);
6✔
81
      }
82
    }
83
  }
84

85
  @Override
86
  public String getMessage(MessageSourceResolvable resolvable, @Nullable Locale locale) throws NoSuchMessageException {
87
    if (this.parentMessageSource != null) {
3✔
88
      return this.parentMessageSource.getMessage(resolvable, locale);
6✔
89
    }
90
    else {
91
      if (resolvable.getDefaultMessage() != null) {
3✔
92
        return renderDefaultMessage(resolvable.getDefaultMessage(), resolvable.getArguments(), locale);
8✔
93
      }
94
      String[] codes = resolvable.getCodes();
3✔
95
      String code = (codes != null && codes.length > 0 ? codes[0] : "");
10!
96
      if (locale == null) {
2!
97
        throw new NoSuchMessageException(code);
×
98
      }
99
      else {
100
        throw new NoSuchMessageException(code, locale);
6✔
101
      }
102
    }
103
  }
104

105
  @Override
106
  public String toString() {
107
    return this.parentMessageSource != null ? this.parentMessageSource.toString() : "Empty MessageSource";
9✔
108
  }
109

110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc