src/share/classes/com/sun/naming/internal/VersionHelper12.java
Print this page
@@ -33,11 +33,10 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Enumeration;
-import java.util.Hashtable;
import java.util.NoSuchElementException;
import java.util.Properties;
import javax.naming.*;
@@ -56,41 +55,41 @@
private boolean getSystemPropsFailed = false;
VersionHelper12() {} // Disallow external from creating one of these.
- public Class loadClass(String className) throws ClassNotFoundException {
+ public Class<?> loadClass(String className) throws ClassNotFoundException {
ClassLoader cl = getContextClassLoader();
return Class.forName(className, true, cl);
}
/**
* Package private.
*/
- Class loadClass(String className, ClassLoader cl)
+ Class<?> loadClass(String className, ClassLoader cl)
throws ClassNotFoundException {
return Class.forName(className, true, cl);
}
/**
* @param className A non-null fully qualified class name.
* @param codebase A non-null, space-separated list of URL strings.
*/
- public Class loadClass(String className, String codebase)
+ public Class<?> loadClass(String className, String codebase)
throws ClassNotFoundException, MalformedURLException {
ClassLoader cl;
ClassLoader parent = getContextClassLoader();
cl = URLClassLoader.newInstance(getUrlArray(codebase), parent);
return Class.forName(className, true, cl);
}
String getJndiProperty(final int i) {
- return (String) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
+ return AccessController.doPrivileged(
+ new PrivilegedAction<String>() {
+ public String run() {
try {
return System.getProperty(PROPS[i]);
} catch (SecurityException e) {
return null;
}
@@ -101,13 +100,13 @@
String[] getJndiProperties() {
if (getSystemPropsFailed) {
return null; // after one failure, don't bother trying again
}
- Properties sysProps = (Properties) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
+ Properties sysProps = AccessController.doPrivileged(
+ new PrivilegedAction<Properties>() {
+ public Properties run() {
try {
return System.getProperties();
} catch (SecurityException e) {
getSystemPropsFailed = true;
return null;
@@ -123,24 +122,24 @@
jProps[i] = sysProps.getProperty(PROPS[i]);
}
return jProps;
}
- InputStream getResourceAsStream(final Class c, final String name) {
- return (InputStream) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
+ InputStream getResourceAsStream(final Class<?> c, final String name) {
+ return AccessController.doPrivileged(
+ new PrivilegedAction<InputStream>() {
+ public InputStream run() {
return c.getResourceAsStream(name);
}
}
);
}
InputStream getJavaHomeLibStream(final String filename) {
- return (InputStream) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
+ return AccessController.doPrivileged(
+ new PrivilegedAction<InputStream>() {
+ public InputStream run() {
try {
String javahome = System.getProperty("java.home");
if (javahome == null) {
return null;
}
@@ -153,18 +152,17 @@
}
}
);
}
- NamingEnumeration getResources(final ClassLoader cl, final String name)
- throws IOException
- {
- Enumeration urls;
+ NamingEnumeration<InputStream> getResources(final ClassLoader cl,
+ final String name) throws IOException {
+ Enumeration<URL> urls;
try {
- urls = (Enumeration) AccessController.doPrivileged(
- new PrivilegedExceptionAction() {
- public Object run() throws IOException {
+ urls = AccessController.doPrivileged(
+ new PrivilegedExceptionAction<Enumeration<URL>>() {
+ public Enumeration<URL> run() throws IOException {
return (cl == null)
? ClassLoader.getSystemResources(name)
: cl.getResources(name);
}
}
@@ -174,13 +172,13 @@
}
return new InputStreamEnumeration(urls);
}
ClassLoader getContextClassLoader() {
- return (ClassLoader) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
+ return AccessController.doPrivileged(
+ new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
}
);
}
@@ -191,31 +189,31 @@
* an enumeration of their InputStreams. Each operation on the URL
* enumeration is performed within a doPrivileged block.
* This is used to enumerate the resources under a foreign codebase.
* This class is not MT-safe.
*/
- class InputStreamEnumeration implements NamingEnumeration {
+ class InputStreamEnumeration implements NamingEnumeration<InputStream> {
- private final Enumeration urls;
+ private final Enumeration<URL> urls;
- private Object nextElement = null;
+ private InputStream nextElement = null;
- InputStreamEnumeration(Enumeration urls) {
+ InputStreamEnumeration(Enumeration<URL> urls) {
this.urls = urls;
}
/*
* Returns the next InputStream, or null if there are no more.
* An InputStream that cannot be opened is skipped.
*/
- private Object getNextElement() {
+ private InputStream getNextElement() {
return AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
+ new PrivilegedAction<InputStream>() {
+ public InputStream run() {
while (urls.hasMoreElements()) {
try {
- return ((URL)urls.nextElement()).openStream();
+ return urls.nextElement().openStream();
} catch (IOException e) {
// skip this URL
}
}
return null;
@@ -234,21 +232,21 @@
public boolean hasMoreElements() {
return hasMore();
}
- public Object next() {
+ public InputStream next() {
if (hasMore()) {
- Object res = nextElement;
+ InputStream res = nextElement;
nextElement = null;
return res;
} else {
throw new NoSuchElementException();
}
}
- public Object nextElement() {
+ public InputStream nextElement() {
return next();
}
public void close() {
}