harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r953364 - in /harmony/enhanced/java/trunk/classlib/modules/imageio/src: main/java/javax/imageio/spi/IIOServiceProvider.java main/java/javax/imageio/spi/ServiceRegistry.java test/java/javax/imageio/spi/ServiceRegistryTest.java
Date Thu, 10 Jun 2010 15:59:08 GMT
Author: tellison
Date: Thu Jun 10 15:59:08 2010
New Revision: 953364

URL: http://svn.apache.org/viewvc?rev=953364&view=rev
Log:
Apply patch for HARMONY-6518 (Implementation of method deregisterServiceProvider(java.lang.Object,
java.lang.Class))

Modified:
    harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIOServiceProvider.java
    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/IIOServiceProvider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIOServiceProvider.java?rev=953364&r1=953363&r2=953364&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIOServiceProvider.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIOServiceProvider.java
Thu Jun 10 15:59:08 2010
@@ -49,9 +49,8 @@ public abstract class IIOServiceProvider
         // the default impl. does nothing
     }
 
-    public void onDeregistration(ServiceRegistry registry, Class<?> category) throws
NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public void onDeregistration(ServiceRegistry registry, Class<?> category) {
+        // the default impl. does nothing
     }
 
     public String getVendorName() {

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=953364&r1=953363&r2=953364&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
Thu Jun 10 15:59:08 2010
@@ -65,9 +65,8 @@ public class ServiceRegistry {
         categories.addProvider(provider, null);
     }
 
-    public <T> boolean deregisterServiceProvider(T provider, Class<T> category)
throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public <T> boolean deregisterServiceProvider(T provider, Class<T> category)
{
+        return categories.removeProvider(provider, category);
     }
 
     public void deregisterServiceProvider(Object provider) throws NotImplementedException
{
@@ -201,6 +200,24 @@ public class ServiceRegistry {
             }
             return rt;
         }
+        
+        boolean removeProvider(Object provider, Class<?> category) {
+            if (provider == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.5E"));
+            }
+            
+            if (!category.isAssignableFrom(provider.getClass())) {
+                throw new ClassCastException();
+            }
+            
+            Object obj = categories.get(category);
+            
+            if (null == obj) {
+                throw new IllegalArgumentException(Messages.getString("imageio.92", category));
+            }
+            
+            return ((ProvidersMap) obj).removeProvider(provider, registry, category);
+        }
     }
 
     private static class ProvidersMap {
@@ -212,6 +229,22 @@ public class ServiceRegistry {
             return providers.put(provider.getClass(), provider) == null;
         }
 
+        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());
+            if ((obj == null) || (obj != provider)) {
+                return false;
+            }
+            
+            if (provider instanceof RegisterableService) {
+                ((RegisterableService) provider).onDeregistration(registry, category);
+            }            
+            
+            return (obj == null ? false : true);
+        }
+
         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=953364&r1=953363&r2=953364&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
Thu Jun 10 15:59:08 2010
@@ -43,6 +43,24 @@ public class ServiceRegistryTest extends
         assertFalse("registerServiceProvider() returns incorrect value if a provider of the
same class was previously registered",
             registry.registerServiceProvider(spiB, CATEGORIES[1]));
     }
+    
+    @SuppressWarnings("unchecked")
+    public void testDeregisterServiceProvider() {
+        Class[] CATEGORIES = new Class[] {
+                javax.imageio.spi.ImageReaderSpi.class};
+
+        ServiceRegistry registry = new ServiceRegistry(Arrays.<Class<?>> asList(CATEGORIES).iterator());
+
+        SampleImageReaderSpi spi = new SampleImageReaderSpi();
+        
+        registry.registerServiceProvider(spi, CATEGORIES[0]);
+        
+        assertTrue("deregisterServiceProvider() returns incorrect value for a registered
provider ",
+                registry.deregisterServiceProvider(spi, CATEGORIES[0]));
+        
+        assertFalse("deregisterServiceProvider() returns incorrect value for a unregistered
provider",
+                registry.deregisterServiceProvider(spi, CATEGORIES[0]));
+    }
 }
 
 class SampleImageReaderSpi extends ImageReaderSpi {



Mime
View raw message