You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2009/04/21 19:56:02 UTC

svn commit: r767240 - /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java

Author: gnodet
Date: Tue Apr 21 17:56:02 2009
New Revision: 767240

URL: http://svn.apache.org/viewvc?rev=767240&view=rev
Log:
Refactor the namespace handler registry to be more flexible wrt the namespace list associated to the service (support for String, String[], Collection<String>, URI, URI[], Collection<URI>)

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=767240&r1=767239&r2=767240&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 Tue Apr 21 17:56:02 2009
@@ -21,6 +21,7 @@
 import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Collection;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.geronimo.blueprint.NamespaceHandlerRegistry;
@@ -85,17 +86,42 @@
 
     public void registerHandler(NamespaceHandler handler, Map properties) throws Exception {
         Object ns = properties != null ? properties.get(NAMESPACE) : null;
-        if (ns instanceof URI[]) {
-            for (URI uri : (URI[]) ns) {
-                if (handlers.containsKey(uri)) {
-                    throw new IllegalArgumentException("A NamespaceHandler service is already registered for namespace " + uri);
-                }
+        URI[] namespaces;
+        if (ns == null) {
+            throw new IllegalArgumentException("NamespaceHandler service does not have an associated " + NAMESPACE + " property defined");
+        } else if (ns instanceof URI[]) {
+            namespaces = (URI[]) ns;
+        } else if (ns instanceof URI) {
+            namespaces = new URI[] { (URI) ns };
+        } else if (ns instanceof String[]) {
+            String[] strings = (String[]) ns;
+            namespaces = new URI[strings.length];
+            for (int i = 0; i < namespaces.length; i++) {
+                namespaces[i] = URI.create(strings[i]);
             }
-            for (URI uri : (URI[]) ns) {
-                handlers.put(uri, handler);
+        } else if (ns instanceof Collection) {
+            Collection col = (Collection) ns;
+            namespaces = new URI[col.size()];
+            int index = 0;
+            for (Object o : col) {
+                if (o instanceof URI) {
+                    namespaces[index++] = (URI) o;
+                } else if (o instanceof String) {
+                    namespaces[index++] = URI.create((String) o);
+                } else {
+                    throw new IllegalArgumentException("NamespaceHandler service has an associated " + NAMESPACE + " property defined which can not be converted to an array of URI");
+                }
             }
         } else {
-            throw new IllegalArgumentException("NamespaceHandler service does not have an associated " + NAMESPACE + " property defined");
+            throw new IllegalArgumentException("NamespaceHandler service has an associated " + NAMESPACE + " property defined which can not be converted to an array of URI");
+        }
+        for (URI uri : namespaces) {
+            if (handlers.containsKey(uri)) {
+                throw new IllegalArgumentException("A NamespaceHandler service is already registered for namespace " + uri);
+            }
+        }
+        for (URI uri : namespaces) {
+            handlers.put(uri, handler);
         }
     }