harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r954734 - 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, 15 Jun 2010 07:50:02 GMT
Author: aaf
Date: Tue Jun 15 07:50:02 2010
New Revision: 954734

URL: http://svn.apache.org/viewvc?rev=954734&view=rev
Log:
Committed Lang's patch for HARMONY-6552: implemented ServiceRegistry.deregisterAll().

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=954734&r1=954733&r2=954734&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 Jun 15 07:50:02 2010
@@ -96,14 +96,12 @@ public class ServiceRegistry {
         return categories.unsetOrdering(category, firstProvider, secondProvider);
     }
 
-    public void deregisterAll(Class<?> category) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public void deregisterAll(Class<?> category) {
+        categories.removeAll(category);
     }
 
-    public void deregisterAll() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public void deregisterAll() {
+        categories.removeAll();
     }
 
     @Override
@@ -263,6 +261,22 @@ public class ServiceRegistry {
                 providers.removeProvider(provider, registry, e.getKey());
             }
         }
+        
+        void removeAll(Class<?> category) {
+            Object obj = categories.get(category);
+            
+            if (obj == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.92", category));
+            }
+            
+            ((ProvidersMap) obj).clear(registry);         
+        }
+        
+        void removeAll() {
+            for ( Map.Entry<Class<?>, ProvidersMap> e : categories.entrySet())
{
+                removeAll(e.getKey());                
+            }
+        }
     }
 
     private static class ProvidersMap {
@@ -304,6 +318,19 @@ public class ServiceRegistry {
             
             return true;
         }
+        
+        void clear(ServiceRegistry registry) {
+            for (Map.Entry<Class<?>, Object> e : providers.entrySet()) {
+                Object provider = e.getValue();
+                
+                if (provider instanceof RegisterableService) {
+                    ((RegisterableService) provider).onDeregistration(registry, e.getKey());
+                }
+            }
+            
+            providers.clear();
+            nodeMap.clear();
+        }
 
         Iterator<Class<?>> getProviderClasses() {
             return providers.keySet().iterator();

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=954734&r1=954733&r2=954734&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 Jun 15 07:50:02 2010
@@ -30,6 +30,32 @@ import javax.imageio.spi.ImageReaderSpi;
 import javax.imageio.spi.ImageWriterSpi;
 
 public class ServiceRegistryTest extends TestCase {
+
+    public void testDeregisterAll() {
+        Class[] CATEGORIES = new Class[] {
+                ImageReaderSpi.class };
+        
+        ServiceRegistry registry = new ServiceRegistry(Arrays.<Class<?>> asList(CATEGORIES).iterator());
+        
+        ImageReaderSpi reader1 = new Reader1Spi();
+        ImageReaderSpi reader2 = new Reader2Spi();
+        
+        // Register two providers
+        registry.registerServiceProvider(reader1, CATEGORIES[0]);
+        registry.registerServiceProvider(reader2, CATEGORIES[0]);
+        
+        registry.deregisterAll(ImageReaderSpi.class);
+        assertFalse("Reader1 is still regitered, deregisterAll(Class) failed",registry.contains(reader1));
+        assertFalse("Reader2 is still regitered, deregisterAll(Class) failed",registry.contains(reader2));
+        
+        // Re-register two providers
+        registry.registerServiceProvider(reader1, CATEGORIES[0]);
+        registry.registerServiceProvider(reader2, CATEGORIES[0]);
+        
+        registry.deregisterAll();
+        assertFalse("Reader1 is still regitered, deregisterAll() failed",registry.contains(reader1));
+        assertFalse("Reader2 is still regitered, deregisterAll() failed",registry.contains(reader2));
+    }
     
 	public void testContains() {
 		Class[] CATEGORIES = new Class[] {



Mime
View raw message