harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r954535 - in /harmony/enhanced/java/trunk/classlib/modules/imageio/src: main/java/javax/imageio/spi/ServiceRegistry.java test/java/javax/imageio/spi/ServiceRegistryTest.java
Date Mon, 14 Jun 2010 16:10:26 GMT
Author: tellison
Date: Mon Jun 14 16:10:26 2010
New Revision: 954535

URL: http://svn.apache.org/viewvc?rev=954535&view=rev
Log:
Apply patch for HARMONY-6548 (Implementation of method deregisterServiceProvider(Object))

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=954535&r1=954534&r2=954535&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
Mon Jun 14 16:10:26 2010
@@ -69,9 +69,8 @@ public class ServiceRegistry {
         return categories.removeProvider(provider, category);
     }
 
-    public void deregisterServiceProvider(Object provider) throws NotImplementedException
{
-        // TODO: implement
-        throw new NotImplementedException();
+    public void deregisterServiceProvider(Object provider) {
+        categories.removeProvider(provider);
     }
 
 //    @SuppressWarnings("unchecked")
@@ -233,12 +232,23 @@ public class ServiceRegistry {
             
             Object obj = categories.get(category);
             
-            if (null == obj) {
+            if (obj == null) {
                 throw new IllegalArgumentException(Messages.getString("imageio.92", category));
             }
             
             return ((ProvidersMap) obj).removeProvider(provider, registry, category);
         }
+        
+        void removeProvider(Object provider) {
+            if (provider == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.5E"));
+            }
+            
+            for (Entry<Class<?>, ProvidersMap> e : categories.entrySet()) {
+                ProvidersMap providers = e.getValue();
+                providers.removeProvider(provider, registry, e.getKey());
+            }
+        }
     }
 
     private static class ProvidersMap {
@@ -262,17 +272,19 @@ public class ServiceRegistry {
         boolean removeProvider(Object provider,
                 ServiceRegistry registry, Class<?> category) {
             
-            //TODO remove provider from nodeMap after task HARMONY-6507 has been resolved
-            Object obj = providers.remove(provider.getClass());
+            Object obj = providers.get(provider.getClass());
             if ((obj == null) || (obj != provider)) {
                 return false;
             }
             
+            providers.remove(provider.getClass());
+            nodeMap.remove(provider);
+            
             if (provider instanceof RegisterableService) {
                 ((RegisterableService) provider).onDeregistration(registry, category);
             }            
             
-            return (obj == null ? false : true);
+            return true;
         }
 
         Iterator<Class<?>> getProviderClasses() {

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=954535&r1=954534&r2=954535&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
Mon Jun 14 16:10:26 2010
@@ -126,21 +126,34 @@ public class ServiceRegistryTest extends
     }
     
     @SuppressWarnings("unchecked")
-    public void testDeregisterServiceProvider() {
+    public void testDeregisterServiceProvider() throws Exception {
         Class[] CATEGORIES = new Class[] {
-                javax.imageio.spi.ImageReaderSpi.class};
+                javax.imageio.spi.ImageReaderSpi.class,
+                javax.imageio.spi.SampleImageReaderSpi.class};
 
         ServiceRegistry registry = new ServiceRegistry(Arrays.<Class<?>> asList(CATEGORIES).iterator());
 
         SampleImageReaderSpi spi = new SampleImageReaderSpi();
         
+        // Test deregisterServiceProvider(Object, Class)
         registry.registerServiceProvider(spi, CATEGORIES[0]);
         
-        assertTrue("deregisterServiceProvider() returns incorrect value for a registered
provider ",
+        assertTrue("deregisterServiceProvider(Object, Class) returns incorrect value for
a registered provider ",
                 registry.deregisterServiceProvider(spi, CATEGORIES[0]));
         
-        assertFalse("deregisterServiceProvider() returns incorrect value for a unregistered
provider",
+        assertFalse("deregisterServiceProvider(Object, Class) returns incorrect value for
a unregistered provider",
                 registry.deregisterServiceProvider(spi, CATEGORIES[0]));
+        
+        // Test deregisterServiceProvider(Object)
+        registry.registerServiceProvider(spi, CATEGORIES[0]);
+        registry.registerServiceProvider(spi, CATEGORIES[1]);
+
+        registry.deregisterServiceProvider(spi);
+        
+        assertFalse("deregisterServiceProvider(Object) failed to remove all providers",
+                registry.deregisterServiceProvider(spi, CATEGORIES[0]));
+        assertFalse("deregisterServiceProvider(Object) failed to remove all providers",
+                registry.deregisterServiceProvider(spi, CATEGORIES[1]));
     }
 }
 



Mime
View raw message