39 |
|
|
40 |
package java.util; |
package java.util; |
41 |
|
|
42 |
|
import gnu.classpath.VMStackWalker; |
43 |
import java.io.IOException; |
import java.io.IOException; |
44 |
import java.io.InputStream; |
import java.io.InputStream; |
45 |
import java.security.AccessController; |
import java.security.AccessController; |
105 |
private Locale locale; |
private Locale locale; |
106 |
|
|
107 |
/** |
/** |
|
* We override SecurityManager in order to access getClassContext(). |
|
|
*/ |
|
|
private static final class Security extends SecurityManager |
|
|
{ |
|
|
/** |
|
|
* Avoid accessor method of private constructor. |
|
|
*/ |
|
|
Security() |
|
|
{ |
|
|
} |
|
|
|
|
|
/** |
|
|
* Return the ClassLoader of the class which called into this |
|
|
* ResourceBundle, or null if it cannot be determined. |
|
|
*/ |
|
|
ClassLoader getCallingClassLoader() |
|
|
{ |
|
|
Class[] stack = getClassContext(); |
|
|
for (int i = 0; i < stack.length; i++) |
|
|
{ |
|
|
if (stack[i] != Security.class && stack[i] != ResourceBundle.class) |
|
|
return stack[i].getClassLoader(); |
|
|
} |
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
/** A security context for grabbing the correct class loader. */ |
|
|
private static final Security security |
|
|
= (Security) AccessController.doPrivileged(new PrivilegedAction() |
|
|
{ |
|
|
// This will always work since java.util classes have (all) system |
|
|
// permissions. |
|
|
public Object run() |
|
|
{ |
|
|
return new Security(); |
|
|
} |
|
|
} |
|
|
); |
|
|
|
|
|
/** |
|
108 |
* The resource bundle cache. |
* The resource bundle cache. |
109 |
*/ |
*/ |
110 |
private static Map bundleCache; |
private static Map bundleCache; |
215 |
*/ |
*/ |
216 |
public static ResourceBundle getBundle(String baseName) |
public static ResourceBundle getBundle(String baseName) |
217 |
{ |
{ |
218 |
ClassLoader cl = security.getCallingClassLoader(); |
ClassLoader cl = VMStackWalker.getCallingClassLoader(); |
219 |
if (cl == null) |
if (cl == null) |
220 |
cl = ClassLoader.getSystemClassLoader(); |
cl = ClassLoader.getSystemClassLoader(); |
221 |
return getBundle(baseName, Locale.getDefault(), cl); |
return getBundle(baseName, Locale.getDefault(), cl); |
235 |
*/ |
*/ |
236 |
public static ResourceBundle getBundle(String baseName, Locale locale) |
public static ResourceBundle getBundle(String baseName, Locale locale) |
237 |
{ |
{ |
238 |
ClassLoader cl = security.getCallingClassLoader(); |
ClassLoader cl = VMStackWalker.getCallingClassLoader(); |
239 |
if (cl == null) |
if (cl == null) |
240 |
cl = ClassLoader.getSystemClassLoader(); |
cl = ClassLoader.getSystemClassLoader(); |
241 |
return getBundle(baseName, locale, cl); |
return getBundle(baseName, locale, cl); |