felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r945698 - in /felix/trunk/dependencymanager: core/src/main/java/org/apache/felix/dm/resources/ test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ test/src/test/java/org/apache/felix/dm/test/
Date Tue, 18 May 2010 15:25:32 GMT
Author: marrs
Date: Tue May 18 15:25:32 2010
New Revision: 945698

URL: http://svn.apache.org/viewvc?rev=945698&view=rev
Log:
FELIX-2348 Not all resources have a filter, so the code and the test now handle that case
correctly.

Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java?rev=945698&r1=945697&r2=945698&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
Tue May 18 15:25:32 2010
@@ -40,17 +40,19 @@ public class BundleResourceRepository {
 	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 class BundleResourceRepository {
 	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);
             }
         }

Modified: felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java?rev=945698&r1=945697&r2=945698&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java
(original)
+++ felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java
Tue May 18 15:25:32 2010
@@ -29,7 +29,6 @@ import junit.framework.Assert;
 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 @@ public class ResourceProvider
      */
     @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 @@ public class ResourceProvider
         }
         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 @@ public class ResourceProvider
     {
         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]);
             }

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java?rev=945698&r1=945697&r2=945698&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
Tue May 18 15:25:32 2010
@@ -120,23 +120,25 @@ public class FELIX2348_ResourceAdapterTe
         
         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 @@ public class FELIX2348_ResourceAdapterTe
 
         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]);
                     }
                 }



Mime
View raw message