geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r767892 - /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java
Date Thu, 23 Apr 2009 11:22:18 GMT
Author: gnodet
Date: Thu Apr 23 11:22:18 2009
New Revision: 767892

URL: http://svn.apache.org/viewvc?rev=767892&view=rev
Log:
Clean a bit the NamespaceHandlerRegistryImpl class

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java?rev=767892&r1=767891&r2=767892&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java
Thu Apr 23 11:22:18 2009
@@ -19,16 +19,13 @@
 package org.apache.geronimo.blueprint.namespace;
 
 import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Collection;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.Map;
 
 import org.apache.geronimo.blueprint.NamespaceHandlerRegistry;
 import org.osgi.framework.BundleContext;
@@ -36,8 +33,8 @@
 import org.osgi.service.blueprint.namespace.NamespaceHandler;
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
-import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Default implementation of the NamespaceHandlerRegistry.
@@ -103,15 +100,9 @@
         for (URI uri : namespaces) {
             if (handlers.containsKey(uri)) {
                 LOGGER.warn("Ignoring NamespaceHandler for namespace {}, as another handler
has already been registered for the same namespace", uri);
-                continue;
-            }
-            handlers.put(uri, handler);
-            for (Listener listener : listeners.keySet()) {
-                try {
-                    listener.namespaceHandlerRegistered(uri);
-                } catch (Throwable t) {
-                    LOGGER.debug("Unexpected exception when notifying a NamespaceHandler
listener", t);
-                }
+            } else {
+                handlers.put(uri, handler);
+                callListeners(uri, true);
             }
         }
     }
@@ -123,12 +114,20 @@
                 continue;
             }
             handlers.remove(uri);
-            for (Listener listener : listeners.keySet()) {
-                try {
+            callListeners(uri, false);
+        }
+    }
+
+    private void callListeners(URI uri, boolean registered) {
+        for (Listener listener : listeners.keySet()) {
+            try {
+                if (registered) {
+                    listener.namespaceHandlerRegistered(uri);
+                } else {
                     listener.namespaceHandlerUnregistered(uri);
-                } catch (Throwable t) {
-                    LOGGER.debug("Unexpected exception when notifying a NamespaceHandler
listener", t);
                 }
+            } catch (Throwable t) {
+                LOGGER.debug("Unexpected exception when notifying a NamespaceHandler listener",
t);
             }
         }
     }
@@ -144,8 +143,8 @@
         } else if (ns instanceof String[]) {
             String[] strings = (String[]) ns;
             List<URI> namespaces = new ArrayList<URI>(strings.length);
-            for (int i = 0; i < strings.length; i++) {
-                namespaces.add(URI.create(strings[i]));
+            for (String string : strings) {
+                namespaces.add(URI.create(string));
             }
             return namespaces;
         } else if (ns instanceof Collection) {



Mime
View raw message