FELIX-2348 Not all resources have a filter, so the code and the test now handle that case correctly.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@945698 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
index e4d03c5..53b5d67 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
@@ -40,17 +40,19 @@
 	public synchronized void addHandler(ServiceReference ref, ResourceHandler handler) {
 		String filter = (String) ref.getProperty("filter"); // "(&(repository=a)(path=b)(name=*.xml))"
 		Filter filterObject = null;
-		try {
-			filterObject = FrameworkUtil.createFilter(filter);
-		} 
-		catch (InvalidSyntaxException e) {
-			e.printStackTrace();
-			return;
+		if (filter != null) {
+    		try {
+    			filterObject = FrameworkUtil.createFilter(filter);
+    		} 
+    		catch (InvalidSyntaxException e) {
+    			e.printStackTrace();
+    			return;
+    		}
 		}
 		Enumeration entries = m_bundle.findEntries("/", null, true);
 		while (entries.hasMoreElements()) {
 			EntryResource resource = new EntryResource(m_bundle, (URL) entries.nextElement());
-			if (filterObject.match(resource)) {
+			if (filterObject == null || filterObject.match(resource)) {
                 handler.added(resource);
 			}
 		}
@@ -59,17 +61,19 @@
 	public synchronized void removeHandler(ServiceReference ref, ResourceHandler handler) {
 		String filter = (String) ref.getProperty("filter"); // "(&(repository=a)(path=b)(name=*.xml))"
 		Filter filterObject = null;
-		try {
-			filterObject = FrameworkUtil.createFilter(filter);
-		}
-		catch (InvalidSyntaxException e) {
-			e.printStackTrace();
-			return;
+		if (filter != null) {
+    		try {
+    			filterObject = FrameworkUtil.createFilter(filter);
+    		}
+    		catch (InvalidSyntaxException e) {
+    			e.printStackTrace();
+    			return;
+    		}
 		}
 		Enumeration entries = m_bundle.findEntries("/", null, true);
         while (entries.hasMoreElements()) {
             EntryResource resource = new EntryResource(m_bundle, (URL) entries.nextElement());
-            if (filterObject.match(resource)) {
+            if (filterObject == null || filterObject.match(resource)) {
                 handler.removed(resource);
             }
         }
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java
index 779d273..92b239b 100644
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java
@@ -29,7 +29,6 @@
 import org.apache.felix.dm.annotation.api.Destroy;
 import org.apache.felix.dm.annotation.api.Service;
 import org.apache.felix.dm.annotation.api.dependency.ServiceDependency;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.resources.ResourceHandler;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
@@ -72,17 +71,19 @@
      */
     @ServiceDependency(removed = "remove", required=false)
     public void add(Map serviceProperties, ResourceHandler handler)
-    {
+    {        
         String filterString = (String) serviceProperties.get("filter");
-        Filter filter;
-        try
-        {
-            filter = m_context.createFilter(filterString);
-        }
-        catch (InvalidSyntaxException e)
-        {
-            Assert.fail("Could not create filter for resource handler: " + e);
-            return;
+        Filter filter = null;
+        if (filterString != null) {
+            try
+            {
+                filter = m_context.createFilter(filterString);
+            }
+            catch (InvalidSyntaxException e)
+            {
+                Assert.fail("Could not create filter for resource handler: " + e);
+                return;
+            }
         }
         synchronized (m_handlers)
         {
@@ -90,7 +91,7 @@
         }
         for (int i = 0; i < m_resources.length; i++)
         {
-            if (filter.match(m_resources[i].getProperties()))
+            if (filter == null || filter.match(m_resources[i].getProperties()))
             {
                 handler.added(m_resources[i]);
             }
@@ -115,7 +116,7 @@
     {
         for (int i = 0; i < m_resources.length; i++)
         {
-            if (filter.match(m_resources[i].getProperties()))
+            if (filter == null || filter.match(m_resources[i].getProperties()))
             {
                 handler.removed(m_resources[i]);
             }
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
index b4a0d8f..9deeb81 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
@@ -120,23 +120,25 @@
         
         public void add(ServiceReference ref, ResourceHandler handler) {
             String filterString = (String) ref.getProperty("filter");
-            Filter filter;
-            try {
-                filter = m_context.createFilter(filterString);
-            }
-            catch (InvalidSyntaxException e) {
-                Assert.fail("Could not create filter for resource handler: " + e);
-                return;
+            Filter filter = null;
+            if (filterString != null) {
+                try {
+                    filter = m_context.createFilter(filterString);
+                }
+                catch (InvalidSyntaxException e) {
+                    Assert.fail("Could not create filter for resource handler: " + e);
+                    return;
+                }
             }
             synchronized (m_handlers) {
                 m_handlers.put(handler, filter);
             }
-                for (int i = 0; i < m_resources.length; i++) {
-                    if (filter.match(m_resources[i].getProperties())) {
-                        handler.added(m_resources[i]);
-                    }
+            for (int i = 0; i < m_resources.length; i++) {
+                if (filter == null || filter.match(m_resources[i].getProperties())) {
+                    handler.added(m_resources[i]);
                 }
             }
+        }
 
         public void remove(ServiceReference ref, ResourceHandler handler) {
             Filter filter;
@@ -148,7 +150,7 @@
 
         private void removeResources(ResourceHandler handler, Filter filter) {
                 for (int i = 0; i < m_resources.length; i++) {
-                    if (filter.match(m_resources[i].getProperties())) {
+                    if (filter == null || filter.match(m_resources[i].getProperties())) {
                         handler.removed(m_resources[i]);
                     }
                 }