39 |
|
|
40 |
package java.util; |
package java.util; |
41 |
|
|
|
import gnu.classpath.VMStackWalker; |
|
42 |
import java.io.IOException; |
import java.io.IOException; |
43 |
import java.io.InputStream; |
import java.io.InputStream; |
44 |
import java.security.AccessController; |
import java.security.AccessController; |
104 |
private Locale locale; |
private Locale locale; |
105 |
|
|
106 |
/** |
/** |
107 |
|
* We override SecurityManager in order to access getClassContext(). |
108 |
|
*/ |
109 |
|
private static final class Security extends SecurityManager |
110 |
|
{ |
111 |
|
/** |
112 |
|
* Avoid accessor method of private constructor. |
113 |
|
*/ |
114 |
|
Security() |
115 |
|
{ |
116 |
|
} |
117 |
|
|
118 |
|
/** |
119 |
|
* Return the ClassLoader of the class which called into this |
120 |
|
* ResourceBundle, or null if it cannot be determined. |
121 |
|
*/ |
122 |
|
ClassLoader getCallingClassLoader() |
123 |
|
{ |
124 |
|
Class[] stack = getClassContext(); |
125 |
|
for (int i = 0; i < stack.length; i++) |
126 |
|
{ |
127 |
|
if (stack[i] != Security.class && stack[i] != ResourceBundle.class) |
128 |
|
return stack[i].getClassLoader(); |
129 |
|
} |
130 |
|
|
131 |
|
return null; |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
/** A security context for grabbing the correct class loader. */ |
136 |
|
private static final Security security |
137 |
|
= (Security) AccessController.doPrivileged(new PrivilegedAction() |
138 |
|
{ |
139 |
|
// This will always work since java.util classes have (all) system |
140 |
|
// permissions. |
141 |
|
public Object run() |
142 |
|
{ |
143 |
|
return new Security(); |
144 |
|
} |
145 |
|
} |
146 |
|
); |
147 |
|
|
148 |
|
/** |
149 |
* The resource bundle cache. |
* The resource bundle cache. |
150 |
*/ |
*/ |
151 |
private static Map bundleCache; |
private static Map bundleCache; |
256 |
*/ |
*/ |
257 |
public static ResourceBundle getBundle(String baseName) |
public static ResourceBundle getBundle(String baseName) |
258 |
{ |
{ |
259 |
ClassLoader cl = VMStackWalker.getCallingClassLoader(); |
ClassLoader cl = security.getCallingClassLoader(); |
260 |
if (cl == null) |
if (cl == null) |
261 |
cl = ClassLoader.getSystemClassLoader(); |
cl = ClassLoader.getSystemClassLoader(); |
262 |
return getBundle(baseName, Locale.getDefault(), cl); |
return getBundle(baseName, Locale.getDefault(), cl); |
276 |
*/ |
*/ |
277 |
public static ResourceBundle getBundle(String baseName, Locale locale) |
public static ResourceBundle getBundle(String baseName, Locale locale) |
278 |
{ |
{ |
279 |
ClassLoader cl = VMStackWalker.getCallingClassLoader(); |
ClassLoader cl = security.getCallingClassLoader(); |
280 |
if (cl == null) |
if (cl == null) |
281 |
cl = ClassLoader.getSystemClassLoader(); |
cl = ClassLoader.getSystemClassLoader(); |
282 |
return getBundle(baseName, locale, cl); |
return getBundle(baseName, locale, cl); |