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

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

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 org.jspecify.annotations.Nullable;
21

22
import java.util.Locale;
23

24
import infra.context.HierarchicalMessageSource;
25
import infra.context.MessageSource;
26
import infra.context.MessageSourceResolvable;
27
import infra.context.NoSuchMessageException;
28

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

43
  @Nullable
44
  private MessageSource parentMessageSource;
45

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

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

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

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

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

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

111
}
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