1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.clirr.core;
21
22 import java.util.ResourceBundle;
23 import java.util.Locale;
24 import java.util.Enumeration;
25
26 /***
27 * ResourceBundle that implements the default locale by delegating to the english bundle.
28 * This solves the bug described in
29 * https://sourceforge.net/tracker/index.php?func=detail&aid=594469&group_id=29721&atid=397078
30 * without having to duplicate any resource bundles, leading to a simpler build and a smaller jar.
31 *
32 * @author lkuehne
33 */
34 public class EventMessages extends ResourceBundle
35 {
36 /***
37 * The base name of the resource bundle from which message descriptions
38 * are read.
39 */
40 public static final String RESOURCE_NAME = EventMessages.class.getName();
41
42 private ResourceBundle delegate = null;
43
44 /***
45 * Control variable used in synchronized blocks that delegate to the {@link #delegate} bundle.
46 * The delegate bundle has "this" as it's parent.
47 * To prevent infinite loops in the lookup process when searching for
48 * non-existent keys we set isUsingDelegate to true to break out of the loop.
49 */
50 private boolean isUsingDelegate = false;
51
52 /***
53 * Constructor.
54 * @deprecated Typical user code never calls this directly but uses
55 * {@link java.util.ResourceBundle#getBundle(java.lang.String)} or one of it's variants instead.
56 */
57 public EventMessages()
58 {
59 }
60
61 private ResourceBundle getDelegate()
62 {
63 if (delegate == null)
64 {
65 delegate = ResourceBundle.getBundle(RESOURCE_NAME, Locale.ENGLISH);
66 }
67 return delegate;
68 }
69
70 /*** @see java.util.ResourceBundle#handleGetObject */
71 protected final synchronized Object handleGetObject(String key)
72 {
73 try
74 {
75 if (isUsingDelegate)
76 {
77
78
79 return null;
80 }
81 else
82 {
83 isUsingDelegate = true;
84 return getDelegate().getObject(key);
85 }
86 }
87 finally
88 {
89 isUsingDelegate = false;
90 }
91 }
92
93 /*** @see java.util.ResourceBundle#getKeys */
94 public final synchronized Enumeration getKeys()
95 {
96 try
97 {
98 if (isUsingDelegate)
99 {
100
101
102 return null;
103 }
104 else
105 {
106 isUsingDelegate = true;
107 return getDelegate().getKeys();
108 }
109 }
110 finally
111 {
112 isUsingDelegate = false;
113 }
114 }
115
116 /*** @see java.util.ResourceBundle#getLocale */
117 public final Locale getLocale()
118 {
119 return getDelegate().getLocale();
120 }
121
122 }