summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-02-16 00:25:45 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-02-16 00:25:45 +0000
commitc3fbc9234248aa0d0bc6f59b669434085c34beeb (patch)
treeb8854ae447fea5cbdf6c26c1d7d4b15a49747121
parent129437cde065631c40d9492186ef9abe73fa186c (diff)
downloadclasspath-c3fbc9234248aa0d0bc6f59b669434085c34beeb.tar.gz
2008-02-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
* gnu/classpath/ServiceFactory.java: Use generics. * gnu/classpath/ServiceProviderLoadingAction.java: Likewise.
-rw-r--r--ChangeLog7
-rw-r--r--gnu/classpath/ServiceFactory.java46
-rw-r--r--gnu/classpath/ServiceProviderLoadingAction.java16
3 files changed, 40 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 76548d8a6..1d38c34f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * gnu/classpath/ServiceFactory.java:
+ Use generics.
+ * gnu/classpath/ServiceProviderLoadingAction.java:
+ Likewise.
+
2008-02-15 Andrew John Hughes <gnu_andrew@member.fsf.org>
PR classpath/34579:
diff --git a/gnu/classpath/ServiceFactory.java b/gnu/classpath/ServiceFactory.java
index daf996c23..6c9728e0c 100644
--- a/gnu/classpath/ServiceFactory.java
+++ b/gnu/classpath/ServiceFactory.java
@@ -48,6 +48,7 @@ import java.security.PrivilegedActionException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.List;
import java.util.NoSuchElementException;
import java.util.ServiceConfigurationError;
import java.util.logging.Level;
@@ -222,8 +223,8 @@ public final class ServiceFactory
* @throws IllegalArgumentException if <code>spi</code> is
* <code>null</code>.
*/
- public static Iterator lookupProviders(Class spi,
- ClassLoader loader)
+ public static <P> Iterator<P> lookupProviders(Class<P> spi,
+ ClassLoader loader)
{
return lookupProviders(spi, loader, false);
}
@@ -266,12 +267,12 @@ public final class ServiceFactory
* @throws IllegalArgumentException if <code>spi</code> is
* <code>null</code>.
*/
- public static Iterator lookupProviders(Class spi,
- ClassLoader loader,
- boolean error)
+ public static <P> Iterator<P> lookupProviders(Class<P> spi,
+ ClassLoader loader,
+ boolean error)
{
String resourceName;
- Enumeration urls;
+ Enumeration<URL> urls;
if (spi == null)
throw new IllegalArgumentException();
@@ -295,11 +296,14 @@ public final class ServiceFactory
throw new ServiceConfigurationError("Failed to access + " +
resourceName, ioex);
else
- return Collections.EMPTY_LIST.iterator();
+ {
+ List<P> empty = Collections.emptyList();
+ return empty.iterator();
+ }
}
- return new ServiceIterator(spi, urls, loader, error,
- AccessController.getContext());
+ return new ServiceIterator<P>(spi, urls, loader, error,
+ AccessController.getContext());
}
@@ -318,7 +322,7 @@ public final class ServiceFactory
*
* @see #lookupProviders(Class, ClassLoader)
*/
- public static Iterator lookupProviders(Class spi)
+ public static <P> Iterator<P> lookupProviders(Class<P> spi)
{
ClassLoader ctxLoader;
@@ -335,14 +339,14 @@ public final class ServiceFactory
*
* @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
*/
- private static final class ServiceIterator
- implements Iterator
+ private static final class ServiceIterator<P>
+ implements Iterator<P>
{
/**
* The service provider interface (usually an interface, sometimes
* an abstract class) which the services must implement.
*/
- private final Class spi;
+ private final Class<P> spi;
/**
@@ -350,7 +354,7 @@ public final class ServiceFactory
* <code>META-INF/services/&lt;org.foo.SomeService&gt;</code>,
* as returned by {@link ClassLoader#getResources(String)}.
*/
- private final Enumeration urls;
+ private final Enumeration<URL> urls;
/**
@@ -389,7 +393,7 @@ public final class ServiceFactory
* {@link #next()}, or <code>null</code> if the iterator has
* already returned all service providers.
*/
- private Object nextProvider;
+ private P nextProvider;
/**
* True if a {@link ServiceConfigurationError} should be thrown
@@ -420,7 +424,7 @@ public final class ServiceFactory
* @param securityContext the security context to use when loading
* and initializing service providers.
*/
- ServiceIterator(Class spi, Enumeration urls, ClassLoader loader,
+ ServiceIterator(Class<P> spi, Enumeration<URL> urls, ClassLoader loader,
boolean error, AccessControlContext securityContext)
{
this.spi = spi;
@@ -436,9 +440,9 @@ public final class ServiceFactory
* @throws NoSuchElementException if {@link #hasNext} returns
* <code>false</code>.
*/
- public Object next()
+ public P next()
{
- Object result;
+ P result;
if (!hasNext())
throw new NoSuchElementException();
@@ -461,7 +465,7 @@ public final class ServiceFactory
}
- private Object loadNextServiceProvider()
+ private P loadNextServiceProvider()
{
String line;
@@ -523,7 +527,7 @@ public final class ServiceFactory
* active when calling lookupProviders.
*/
return AccessController.doPrivileged(
- new ServiceProviderLoadingAction(spi, line, loader),
+ new ServiceProviderLoadingAction<P>(spi, line, loader),
securityContext);
}
catch (Exception ex)
@@ -577,7 +581,7 @@ public final class ServiceFactory
if (!urls.hasMoreElements())
return;
- currentURL = (URL) urls.nextElement();
+ currentURL = urls.nextElement();
try
{
reader = new BufferedReader(new InputStreamReader(
diff --git a/gnu/classpath/ServiceProviderLoadingAction.java b/gnu/classpath/ServiceProviderLoadingAction.java
index 9f9dc51cb..51f5a2fa9 100644
--- a/gnu/classpath/ServiceProviderLoadingAction.java
+++ b/gnu/classpath/ServiceProviderLoadingAction.java
@@ -54,15 +54,15 @@ import java.security.PrivilegedExceptionAction;
*
* @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
*/
-final class ServiceProviderLoadingAction
- implements PrivilegedExceptionAction
+final class ServiceProviderLoadingAction<P>
+ implements PrivilegedExceptionAction<P>
{
/**
* The interface to which the loaded service provider implementation
* must conform. Usually, this is a Java interface type, but it
* might also be an abstract class or even a concrete class.
*/
- private final Class spi;
+ private final Class<P> spi;
/**
@@ -97,7 +97,7 @@ final class ServiceProviderLoadingAction
* <code>providerName</code> or <code>loader</code> is
* <code>null</code>.
*/
- ServiceProviderLoadingAction(Class spi, String providerName,
+ ServiceProviderLoadingAction(Class<P> spi, String providerName,
ClassLoader loader)
{
if (spi == null || providerName == null || loader == null)
@@ -130,13 +130,13 @@ final class ServiceProviderLoadingAction
* no-argument constructor; or if there some other problem with
* creating a new instance of the service provider.
*/
- public Object run()
+ public P run()
throws Exception
{
- Class loadedClass;
- Object serviceProvider;
+ Class<P> loadedClass;
+ P serviceProvider;
- loadedClass = loader.loadClass(providerName);
+ loadedClass = (Class<P>) loader.loadClass(providerName);
serviceProvider = loadedClass.newInstance();
// Ensure that the loaded provider is actually implementing