From 4091689c1844b894bb90a57365e6b188de871c0a Mon Sep 17 00:00:00 2001 From: "stephen@sfnelson.org" Date: Thu, 14 May 2009 21:45:50 +0000 Subject: [PATCH] Switched SPI code to use Java 5-style SPI service loading. Makes stereo Java 5 compatible allowing JNI on Mac OS X. git-svn-id: https://stereo.googlecode.com/svn/trunk@470 c67ee986-0855-0410-825f-15918b819f62 --- MemphisDJ/.classpath | 1 + MemphisDJ/src/Main.java | 10 ++++++---- MemphisDJ/src/music/Library.java | 8 +++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/MemphisDJ/.classpath b/MemphisDJ/.classpath index 3669d84..4a6120f 100644 --- a/MemphisDJ/.classpath +++ b/MemphisDJ/.classpath @@ -4,5 +4,6 @@ + diff --git a/MemphisDJ/src/Main.java b/MemphisDJ/src/Main.java index 4db32b1..11516c7 100644 --- a/MemphisDJ/src/Main.java +++ b/MemphisDJ/src/Main.java @@ -1,5 +1,7 @@ import java.io.IOException; -import java.util.ServiceLoader; +import java.util.Iterator; + +import javax.imageio.spi.ServiceRegistry; import spi.StereoServer; @@ -11,9 +13,9 @@ public class Main { public static void main(String [] args) throws IOException { DJ dj = new DJ("Memphis Stereo"); - ServiceLoader loader = ServiceLoader.load(StereoServer.class); - for (StereoServer server: loader) { - System.out.println(server.getClass()); + for (Iterator it = ServiceRegistry.lookupProviders(StereoServer.class); it.hasNext();) { + StereoServer server = it.next(); + System.out.println("loading server: " + server.getClass()); server.start(dj, args); } } diff --git a/MemphisDJ/src/music/Library.java b/MemphisDJ/src/music/Library.java index c643b08..5ed8161 100644 --- a/MemphisDJ/src/music/Library.java +++ b/MemphisDJ/src/music/Library.java @@ -10,10 +10,12 @@ import interfaces.collection.Source; import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; -import java.util.ServiceLoader; import java.util.Set; +import javax.imageio.spi.ServiceRegistry; + import spi.SourceProvider; import notification.AbstractEventGenerator; @@ -36,8 +38,8 @@ public class Library extends AbstractSetSource addCollection(this.collection()); //library is a collection in the library monitor.nextVersion(); - ServiceLoader loader = ServiceLoader.load(SourceProvider.class); - for (SourceProvider provider: loader) { + for (Iterator it = ServiceRegistry.lookupProviders(SourceProvider.class); it.hasNext();) { + SourceProvider provider = it.next(); System.out.println("using source provider: " + provider.getClass().getName()); provider.create(this); providers.add(provider); -- 2.11.4.GIT