harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r986224 - in /harmony/enhanced/java/trunk/classlib/modules/imageio/src: main/java/javax/imageio/spi/ServiceRegistry.java test/java/javax/imageio/spi/ServiceRegistryTest.java
Date Tue, 17 Aug 2010 07:49:38 GMT
Author: hindessm
Date: Tue Aug 17 07:49:38 2010
New Revision: 986224

URL: http://svn.apache.org/viewvc?rev=986224&view=rev
Log:
Applying patch from "[#HARMONY-6619] Implement
ServiceRegistry.getServiceProviderByClass()".

Modified:
    harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
    harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java?rev=986224&r1=986223&r2=986224&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
Tue Aug 17 07:49:38 2010
@@ -84,9 +84,8 @@ public class ServiceRegistry {
         return (Iterator<T>) categories.getProviders(category, useOrdering);
     }
 
-    public <T> T getServiceProviderByClass(Class<T> providerClass) throws NotImplementedException
{
-        // TODO: implement
-        throw new NotImplementedException();
+    public <T> T getServiceProviderByClass(Class<T> providerClass) {
+        return categories.getServiceProviderByClass(providerClass);
     }
 
     public <T> boolean setOrdering(Class<T> category, T firstProvider, T secondProvider)
{
@@ -173,6 +172,18 @@ public class ServiceRegistry {
             }
             return providers.getProviders(useOrdering);
         }
+        
+        <T> T getServiceProviderByClass(Class<T> providerClass) {
+        	for (Map.Entry<Class<?>, ProvidersMap> e : categories.entrySet()) {
+        		if (e.getKey().isAssignableFrom(providerClass)) {
+        			T provider = e.getValue().getServiceProviderByClass(providerClass);
+        			if (provider != null) {
+        				return provider;
+        			}
+        		}
+        	}
+        	return null;
+        }
 
         Iterator<Class<?>> list() {
             return categories.keySet().iterator();
@@ -343,6 +354,11 @@ public class ServiceRegistry {
             return providers.values().iterator();
         }
         
+        @SuppressWarnings("unchecked")
+		<T> T getServiceProviderByClass(Class<T> providerClass) {
+        	return (T)providers.get(providerClass);
+        }
+        
         public <T> boolean setOrdering(T firstProvider, T secondProvider) {
             if (firstProvider == secondProvider) {
                 throw new IllegalArgumentException(Messages.getString("imageio.98"));

Modified: harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java?rev=986224&r1=986223&r2=986224&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java
Tue Aug 17 07:49:38 2010
@@ -165,6 +165,18 @@ public class ServiceRegistryTest extends
         // Return false if this ordering is not set
         assertFalse("Failed to check if the ordering is not set", registry.unsetOrdering(CATEGORIES[0],
reader2, reader));
     }
+    
+    public void testGetServiceProviderByClass() {
+    	Class[] CATEGORIES = new Class[] {
+                ImageReaderSpi.class };
+        
+        ServiceRegistry registry = new ServiceRegistry(Arrays.<Class<?>> asList(CATEGORIES).iterator());
+        ImageReaderSpi reader = new SampleImageReaderSpi();
+        registry.registerServiceProvider(reader, CATEGORIES[0]);
+        
+        ImageReaderSpi provider = registry.getServiceProviderByClass(SampleImageReaderSpi.class);
+        assertEquals(reader, provider);
+    }
 
     public void testRegistryServiceProvider() throws Exception {
         Class[] CATEGORIES = new Class[] {



Mime
View raw message