felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r960066 - in /felix/trunk/dependencymanager: core/src/main/java/org/apache/felix/dm/ core/src/main/java/org/apache/felix/dm/dependencies/ core/src/main/java/org/apache/felix/dm/impl/ core/src/main/java/org/apache/felix/dm/impl/dependencies/...
Date Fri, 02 Jul 2010 17:27:21 GMT
Author: marrs
Date: Fri Jul  2 17:27:20 2010
New Revision: 960066

URL: http://svn.apache.org/viewvc?rev=960066&view=rev
Log:
Refactored resource dependencies to use URLs instead of the Resource interface we used previously.
Adapted all tests to reflect that.

Added:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceUtil.java
Removed:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/Resource.java
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/StaticResource.java
Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ResourceDependency.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AbstractDecorator.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyActivation.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceHandler.java
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumer.java
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceProvider.java
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ServiceProvider.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ResourceDependencyTest.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/SharingDependenciesWithMultipleServicesTest.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
Fri Jul  2 17:27:20 2010
@@ -41,7 +41,6 @@ import org.apache.felix.dm.impl.dependen
 import org.apache.felix.dm.impl.dependencies.ServiceDependencyImpl;
 import org.apache.felix.dm.impl.dependencies.TemporalServiceDependencyImpl;
 import org.apache.felix.dm.impl.metatype.PropertyMetaDataImpl;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.BundleContext;
 

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ResourceDependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ResourceDependency.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ResourceDependency.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ResourceDependency.java
Fri Jul  2 17:27:20 2010
@@ -18,7 +18,8 @@
  */
 package org.apache.felix.dm.dependencies;
 
-import org.apache.felix.dm.resources.Resource;
+import java.net.URL;
+
 import org.apache.felix.dm.resources.ResourceHandler;
 
 public interface ResourceDependency extends Dependency, ResourceHandler {
@@ -94,7 +95,7 @@ public interface ResourceDependency exte
      */
      public ResourceDependency setAutoConfig(String instanceName);
     
-     public ResourceDependency setResource(Resource resource);
+     public ResourceDependency setResource(URL resource);
 	
      public ResourceDependency setRequired(boolean required);
 

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AbstractDecorator.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AbstractDecorator.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AbstractDecorator.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AbstractDecorator.java
Fri Jul  2 17:27:20 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.dm.impl;
 
+import java.net.URL;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -26,7 +27,6 @@ import java.util.Map;
 
 import org.apache.felix.dm.DependencyManager;
 import org.apache.felix.dm.dependencies.Dependency;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.service.Service;
 import org.apache.felix.dm.service.ServiceStateListener;
 import org.osgi.framework.Bundle;
@@ -173,13 +173,13 @@ public abstract class AbstractDecorator 
     }
 
     // callbacks for resources
-    public void added(Resource resource) {
+    public void added(URL resource) {
         Service newService = createService(new Object[] { resource });
         m_services.put(resource, newService);
         m_manager.add(newService);
     }
 
-    public void removed(Resource resource) {
+    public void removed(URL resource) {
         Service newService = (Service) m_services.remove(resource);
         if (newService == null) {
             System.out.println("Service should not be null here, dumping stack.");

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
Fri Jul  2 17:27:20 2010
@@ -18,13 +18,13 @@
  */
 package org.apache.felix.dm.impl;
 
+import java.net.URL;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Properties;
 
 import org.apache.felix.dm.DependencyManager;
 import org.apache.felix.dm.dependencies.Dependency;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.service.Service;
 import org.apache.felix.dm.service.ServiceStateListener;
 
@@ -61,7 +61,7 @@ public class ResourceAdapterServiceImpl 
         }
 
         public Service createService(Object[] properties) {
-            Resource resource = (Resource) properties[0]; 
+            URL resource = (URL) properties[0]; 
             Properties props = new Properties();
             if (m_serviceProperties != null) {
                 Enumeration e = m_serviceProperties.keys();

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyActivation.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyActivation.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyActivation.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyActivation.java
Fri Jul  2 17:27:20 2010
@@ -1,7 +1,6 @@
 package org.apache.felix.dm.impl.dependencies;
 
-public interface DependencyActivation
-{
+public interface DependencyActivation {
   public void start(DependencyService service);
   public void stop(DependencyService service);
 }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
Fri Jul  2 17:27:20 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.dm.impl.dependencies;
 
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.List;
@@ -27,7 +28,6 @@ import org.apache.felix.dm.dependencies.
 import org.apache.felix.dm.dependencies.ResourceDependency;
 import org.apache.felix.dm.impl.Logger;
 import org.apache.felix.dm.management.ServiceComponentDependency;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.resources.ResourceHandler;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.BundleContext;
@@ -46,10 +46,10 @@ public class ResourceDependencyImpl exte
     private String m_autoConfigInstance;
     protected List m_services = new ArrayList();
 	private String m_resourceFilter;
-	private Resource m_trackedResource;
+	private URL m_trackedResource;
     private boolean m_isStarted;
     private List m_resources = new ArrayList();
-    private Resource m_resourceInstance;
+    private URL m_resourceInstance;
     private boolean m_propagate;
 	
     public ResourceDependencyImpl(BundleContext context, Logger logger) {
@@ -93,7 +93,7 @@ public class ResourceDependencyImpl exte
 	        Properties props = null;
 	        if (m_resourceFilter != null) {
 	            props = new Properties();
-	            props.setProperty(Resource.FILTER, m_resourceFilter);
+	            props.setProperty(ResourceHandler.FILTER, m_resourceFilter);
 	        }
 	        m_registration = m_context.registerService(ResourceHandler.class.getName(), this,
props);
 	    }
@@ -114,7 +114,7 @@ public class ResourceDependencyImpl exte
 	    }
 	}
 
-	public void added(Resource resource) {
+	public void added(URL resource) {
 	    if (m_trackedResource == null || m_trackedResource.equals(resource)) {
     		long counter;
     		Object[] services;
@@ -139,7 +139,7 @@ public class ResourceDependencyImpl exte
 	    }
 	}
 
-	public void changed(Resource resource) {
+	public void changed(URL resource) {
         if (m_trackedResource == null || m_trackedResource.equals(resource)) {
             Object[] services;
             synchronized (this) {
@@ -152,7 +152,7 @@ public class ResourceDependencyImpl exte
         }
 	}
 
-	public void removed(Resource resource) {
+	public void removed(URL resource) {
         if (m_trackedResource == null || m_trackedResource.equals(resource)) {
     		long counter;
     		Object[] services;
@@ -177,22 +177,22 @@ public class ResourceDependencyImpl exte
         }
 	}
 	
-    public void invokeAdded(DependencyService ds, Resource serviceInstance) {
+    public void invokeAdded(DependencyService ds, URL serviceInstance) {
         invoke(ds, serviceInstance, m_callbackAdded);
     }
 
-    public void invokeChanged(DependencyService ds, Resource serviceInstance) {
+    public void invokeChanged(DependencyService ds, URL serviceInstance) {
         invoke(ds, serviceInstance, m_callbackChanged);
     }
 
-    public void invokeRemoved(DependencyService ds, Resource serviceInstance) {
+    public void invokeRemoved(DependencyService ds, URL serviceInstance) {
         invoke(ds, serviceInstance, m_callbackRemoved);
     }
     
-    private void invoke(DependencyService ds, Resource serviceInstance, String name) {
+    private void invoke(DependencyService ds, URL serviceInstance, String name) {
         if (name != null) {
             ds.invokeCallbackMethod(getCallbackInstances(ds), name,
-                new Class[][] {{ Service.class, Resource.class }, { Service.class, Object.class
}, { Service.class },  { Resource.class }, { Object.class }, {}},
+                new Class[][] {{ Service.class, URL.class }, { Service.class, Object.class
}, { Service.class },  { URL.class }, { Object.class }, {}},
                 new Object[][] {{ ds.getServiceInterface(), serviceInstance }, { ds.getServiceInterface(),
serviceInstance }, { ds.getServiceInterface() }, { serviceInstance }, { serviceInstance },
{}}
             );
         }
@@ -368,7 +368,7 @@ public class ResourceDependencyImpl exte
         }
     }
 
-	public ResourceDependency setResource(Resource resource) {
+	public ResourceDependency setResource(URL resource) {
 		m_trackedResource = resource;
 		return this;
 	}
@@ -388,13 +388,13 @@ public class ResourceDependencyImpl exte
         return m_autoConfig;
     }
     
-    public Resource getResource() {
+    public URL getResource() {
     	return lookupResource();
     }
 
-    private Resource lookupResource() {
+    private URL lookupResource() {
         try {
-            return (Resource) m_resources.get(0);
+            return (URL) m_resources.get(0);
         }
         catch (IndexOutOfBoundsException e) {
             return null;
@@ -410,7 +410,7 @@ public class ResourceDependencyImpl exte
     }
 
     public Class getAutoConfigType() {
-        return Resource.class;
+        return URL.class;
     }
 
     public void invokeAdded(DependencyService service) {
@@ -431,12 +431,13 @@ public class ResourceDependencyImpl exte
     }
     
     public Dictionary getProperties() {
-        Resource resource = lookupResource();
+        URL resource = lookupResource();
         if (resource != null) {
             Properties props = new Properties();
-            props.put(Resource.NAME, resource.getName());
-            props.put(Resource.PATH, resource.getPath());
-            props.put(Resource.REPOSITORY, resource.getRepository());
+            props.setProperty(ResourceHandler.HOST, resource.getHost());
+            props.setProperty(ResourceHandler.PATH, resource.getPath());
+            props.setProperty(ResourceHandler.PROTOCOL, resource.getProtocol());
+            props.setProperty(ResourceHandler.PORT, Integer.toString(resource.getPort()));
             return props;
         }
         else {
@@ -459,7 +460,7 @@ public class ResourceDependencyImpl exte
             sb.append(m_resourceFilter);
         }
         if (m_trackedResource != null) {
-            sb.append(m_trackedResource.getID());
+            sb.append(m_trackedResource.toString());
         }
         return sb.toString();
     }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceHandler.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceHandler.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceHandler.java
Fri Jul  2 17:27:20 2010
@@ -18,14 +18,28 @@
  */
 package org.apache.felix.dm.resources;
 
+import java.net.URL;
+
 /** 
  * Service interface for anybody wanting to be notified of changes to resources. 
  */
 public interface ResourceHandler {
+    /** Name of the property that's used to describe the filter condition for a resource.
*/
+    public static final String FILTER = "filter";
+    
+    /** The host part of the URL. */
+    public static final String HOST = "host";
+    /** The path part of the URL. */
+    public static final String PATH = "path";
+    /** The protocol part of the URL. */
+    public static final String PROTOCOL = "protocol";
+    /** The port part of the URL. */
+    public static final String PORT = "port";
+
     /** Invoked whenever a new resource is added. */
-	public void added(Resource resource);
+	public void added(URL resource);
 	/** Invoked whenever an existing resource changes. */
-	public void changed(Resource resource);
+	public void changed(URL resource);
 	/** Invoked whenever an existing resource is removed. */
-	public void removed(Resource resource);
+	public void removed(URL resource);
 }

Added: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceUtil.java?rev=960066&view=auto
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceUtil.java
(added)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/ResourceUtil.java
Fri Jul  2 17:27:20 2010
@@ -0,0 +1,16 @@
+package org.apache.felix.dm.resources;
+
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Properties;
+
+public class ResourceUtil {
+    public static Dictionary createProperties(URL url) {
+        Properties props = new Properties();
+        props.setProperty(ResourceHandler.PROTOCOL, url.getProtocol());
+        props.setProperty(ResourceHandler.HOST, url.getHost());
+        props.setProperty(ResourceHandler.PORT, Integer.toString(url.getPort()));
+        props.setProperty(ResourceHandler.PATH, url.getPath());
+        return props;
+    }
+}

Modified: felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumer.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumer.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumer.java
(original)
+++ felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumer.java
Fri Jul  2 17:27:20 2010
@@ -18,6 +18,8 @@
 */
 package org.apache.felix.dm.test.bundle.annotation.resource;
 
+import java.net.URL;
+
 import junit.framework.Assert;
 
 import org.apache.felix.dm.annotation.api.ResourceDependency;
@@ -25,7 +27,6 @@ import org.apache.felix.dm.annotation.ap
 import org.apache.felix.dm.annotation.api.ServiceDependency;
 import org.apache.felix.dm.annotation.api.Start;
 import org.apache.felix.dm.annotation.api.Stop;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
 
 /**
@@ -45,30 +46,28 @@ public class ResourceConsumer
         System.out.println("ResourceConsumer.start: sequencer=" + m_sequencer);
     }
     
-    @ResourceDependency(required = false, filter = "(&(path=/test)(name=*.txt)(repository=TestRepository))")
-    public void add(Resource resource)
+    @ResourceDependency(required = false, filter = "(&(path=/path/to/*.txt)(host=localhost))")
+    public void add(URL resource)
     {
-        System.out.println("ResourceConsumer.add: resource=" + resource.getName() + ", m_sequencer="
+ m_sequencer);
-        if (match(resource, "test1.txt", "/test", "TestRepository"))
+        System.out.println("ResourceConsumer.add: resource=" + resource + ", m_sequencer="
+ m_sequencer);
+        if (match(resource, "file://localhost/path/to/test1.txt"))
         {
             m_resourcesSeen ++;
             return;
         }
 
-        if (match(resource, "test2.txt", "/test", "TestRepository"))
+        if (match(resource, "file://localhost/path/to/test2.txt"))
         {
             m_resourcesSeen ++;
             return;
         }
 
-        Assert.fail("Got unexpected resource: " + resource.getName() + "/" + resource.getPath()
-            + "/" + resource.getRepository());
+        Assert.fail("Got unexpected resource: " + resource);
     }
 
-    private boolean match(Resource resource, String name, String path, String repo)
+    private boolean match(URL resource, String url)
     {
-        return name.equals(resource.getName()) && path.equals(resource.getPath())
-            && repo.equals(resource.getRepository());
+        return url.equals(resource.toString());
     }
     
     @Stop

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=960066&r1=960065&r2=960066&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
Fri Jul  2 17:27:20 2010
@@ -18,8 +18,7 @@
 */
 package org.apache.felix.dm.test.bundle.annotation.resource;
 
-import java.io.IOException;
-import java.io.InputStream;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -30,6 +29,7 @@ import org.apache.felix.dm.annotation.ap
 import org.apache.felix.dm.annotation.api.Service;
 import org.apache.felix.dm.annotation.api.ServiceDependency;
 import org.apache.felix.dm.resources.ResourceHandler;
+import org.apache.felix.dm.resources.ResourceUtil;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
 import org.osgi.framework.InvalidSyntaxException;
@@ -42,28 +42,16 @@ public class ResourceProvider
 {
     private volatile BundleContext m_context;
     private final Map m_handlers = new HashMap();
-    private StaticResource[] m_resources = {
-            new StaticResource("test1.txt", "/test", "TestRepository")
-            {
-                public InputStream openStream() throws IOException
-                {
-                    return null;
-                };
-            }, new StaticResource("test2.txt", "/test", "TestRepository")
-            {
-                public InputStream openStream() throws IOException
-                {
-                    return null;
-                };
-            }, new StaticResource("README.doc", "/", "TestRepository")
-            {
-                public InputStream openStream() throws IOException
-                {
-                    Assert.fail("resource should not have matched the filter");
-                    return null;
-                };
-            } };
-
+    private URL[] m_resources;
+    
+    public ResourceProvider() throws Exception {
+        m_resources = new URL[] {
+            new URL("file://localhost/path/to/test1.txt"),
+            new URL("file://localhost/path/to/test2.txt"),
+            new URL("file://localhost/path/to/README.doc")
+            };
+    }
+    
     /**
      * Handles a new Resource consumer
      * @param serviceProperties
@@ -91,7 +79,7 @@ public class ResourceProvider
         }
         for (int i = 0; i < m_resources.length; i++)
         {
-            if (filter == null || filter.match(m_resources[i].getProperties()))
+            if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i])))
             {
                 handler.added(m_resources[i]);
             }
@@ -116,7 +104,7 @@ public class ResourceProvider
     {
         for (int i = 0; i < m_resources.length; i++)
         {
-            if (filter == null || filter.match(m_resources[i].getProperties()))
+            if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i])))
             {
                 handler.removed(m_resources[i]);
             }

Modified: felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ServiceProvider.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ServiceProvider.java
(original)
+++ felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ServiceProvider.java
Fri Jul  2 17:27:20 2010
@@ -18,25 +18,26 @@
 */
 package org.apache.felix.dm.test.bundle.annotation.resource;
 
+import java.net.URL;
+
 import junit.framework.Assert;
 
 import org.apache.felix.dm.annotation.api.Property;
 import org.apache.felix.dm.annotation.api.ResourceAdapterService;
 import org.apache.felix.dm.annotation.api.ServiceDependency;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
 
 /**
  * Our ServiceInterface provider, which service is activated by a ResourceAdapter.
  */
 @ResourceAdapterService(
-    filter = "(&(path=/test)(name=test1.txt)(repository=TestRepository))", 
+    filter = "(&(path=/path/to/test1.txt)(host=localhost))", 
     properties = {@Property(name="foo", value="bar")},
     propagate = true)
 public class ServiceProvider implements ServiceInterface
 {
     // Injected by reflection
-    Resource m_resource;
+    URL m_resource;
         
     @ServiceDependency(filter="(test=adapter)")
     Sequencer m_sequencer;
@@ -44,9 +45,7 @@ public class ServiceProvider implements 
     public void run()
     {
         Assert.assertNotNull("Resource has not been injected in the adapter", m_resource);
-        Assert.assertEquals("ServiceProvider did not get expected resource", "test1.txt",
m_resource.getName());
-        Assert.assertEquals("ServiceProvider did not get expected resource", "/test", m_resource.getPath());
-        Assert.assertEquals("ServiceProvider did not get expected resource", "TestRepository",
m_resource.getRepository());
+        Assert.assertEquals("ServiceProvider did not get expected resource", "file://localhost/path/to/test1.txt",
m_resource.toString());
         m_sequencer.step(2);
     }
 }

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=960066&r1=960065&r2=960066&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
Fri Jul  2 17:27:20 2010
@@ -22,21 +22,20 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Dictionary;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Map.Entry;
 
 import junit.framework.Assert;
 
 import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.resources.ResourceHandler;
+import org.apache.felix.dm.resources.ResourceUtil;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
@@ -60,18 +59,18 @@ public class FELIX2348_ResourceAdapterTe
     }    
 
     @Test
-    public void testBasicResourceAdapter(BundleContext context) {
+    public void testBasicResourceAdapter(BundleContext context) throws Exception {
         DependencyManager m = new DependencyManager(context);
         // helper class that ensures certain steps get executed in sequence
         Ensure e = new Ensure();
-        m.add(m.createResourceAdapterService("(&(path=/test)(name=*.txt)(repository=TestRepository))",
false, null, "changed")
+        m.add(m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))",
false, null, "changed")
               .setImplementation(new ResourceAdapter(e)));
         m.add(m.createService().setImplementation(new ResourceProvider(e)).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add",
"remove")));
         e.waitForStep(3, 5000);
      }
     
     static class ResourceAdapter {
-        protected Resource m_resource; // injected by reflection.
+        protected URL m_resource; // injected by reflection.
         private Ensure m_ensure;
         
         ResourceAdapter(Ensure e) {
@@ -83,19 +82,14 @@ public class FELIX2348_ResourceAdapterTe
             Assert.assertNotNull("resource not injected", m_resource);
             m_ensure.step(2);
             try {
-                InputStream in= m_resource.openStream();
-                ByteArrayOutputStream out = new ByteArrayOutputStream();
-                int c;
-                while ((c = in.read()) != -1) {
-                    out.write(c);
-                }
-                String msg = new String(out.toByteArray(), "UTF8");
-                Assert.assertEquals("resource", msg);
-            } catch (Throwable t) {
-                t.printStackTrace();
-                Assert.fail();
+                InputStream in = m_resource.openStream();
+            } 
+            catch (FileNotFoundException e) {
+                m_ensure.step(3);
+            }
+            catch (IOException e) {
+                Assert.fail("We should not have gotten this exception.");
             }
-            m_ensure.step(3);
         }
     }
     
@@ -103,16 +97,13 @@ public class FELIX2348_ResourceAdapterTe
         private volatile BundleContext m_context;
         private final Ensure m_ensure;
         private final Map m_handlers = new HashMap();
-        private StaticResource[] m_resources = {
-            new StaticResource("test1.txt", "/test", "TestRepository") {
-                public InputStream openStream() throws IOException {
-                    return new ByteArrayInputStream("resource".getBytes("UTF8"));
-                };
-            }
-        };
+        private URL[] m_resources;
 
-        public ResourceProvider(Ensure ensure) {
+        public ResourceProvider(Ensure ensure) throws MalformedURLException {
             m_ensure = ensure;
+            m_resources = new URL[] {
+                new URL("file://localhost/path/to/file1.txt")
+            };
         }
         
         public void add(ServiceReference ref, ResourceHandler handler) {
@@ -131,7 +122,7 @@ public class FELIX2348_ResourceAdapterTe
                 m_handlers.put(handler, filter);
             }
             for (int i = 0; i < m_resources.length; i++) {
-                if (filter == null || filter.match(m_resources[i].getProperties())) {
+                if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i])))
{
                     handler.added(m_resources[i]);
                 }
             }
@@ -147,7 +138,7 @@ public class FELIX2348_ResourceAdapterTe
 
         private void removeResources(ResourceHandler handler, Filter filter) {
                 for (int i = 0; i < m_resources.length; i++) {
-                    if (filter == null || filter.match(m_resources[i].getProperties())) {
+                    if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i])))
{
                         handler.removed(m_resources[i]);
                     }
                 }
@@ -165,47 +156,4 @@ public class FELIX2348_ResourceAdapterTe
             System.out.println("DESTROY..." + m_handlers.size());
         }
     }
-    
-    static class StaticResource implements Resource {
-        private String m_id;
-        private String m_name;
-        private String m_path;
-        private String m_repository;
-
-        public StaticResource(String name, String path, String repository) {
-            m_id = repository + ":" + path + "/" + name;
-            m_name = name;
-            m_path = path;
-            m_repository = repository;
-        }
-        
-        public String getID() {
-            return m_id;
-        }
-
-        public String getName() {
-            return m_name;
-        }
-
-        public String getPath() {
-            return m_path;
-        }
-
-        public String getRepository() {
-            return m_repository;
-        }
-        
-        public Dictionary getProperties() {
-            return new Properties() {{
-                put(Resource.ID, getID());
-                put(Resource.NAME, getName());
-                put(Resource.PATH, getPath());
-                put(Resource.REPOSITORY, getRepository());
-            }};
-        }
-
-        public InputStream openStream() throws IOException {
-            return null;
-        }
-    }
 }

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ResourceDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ResourceDependencyTest.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ResourceDependencyTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ResourceDependencyTest.java
Fri Jul  2 17:27:20 2010
@@ -22,22 +22,20 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.Dictionary;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Map.Entry;
 
 import junit.framework.Assert;
 
 import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.resources.ResourceHandler;
+import org.apache.felix.dm.resources.ResourceUtil;
 import org.apache.felix.dm.service.Service;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -67,16 +65,16 @@ public class ResourceDependencyTest exte
         // helper class that ensures certain steps get executed in sequence
         Ensure e = new Ensure();
         // create a service provider and consumer
-        ResourceConsumer c = new ResourceConsumer();
+        ResourceConsumer c = new ResourceConsumer(e);
         Service consumer = m.createService()
             .setImplementation(c)
             .add(m.createResourceDependency()
-                .setFilter("(&(path=/test)(name=*.txt)(repository=TestRepository))")
+                .setFilter("(&(path=/path/to/*.txt)(host=localhost))")
                 .setCallbacks("add", "remove"));
         Service dynamicProxyConsumer = m.createService()
             .setFactory(new ResourceConsumerFactory(e), "create")
             .add(m.createResourceDependency()
-                    .setFilter("(name=*.doc)")
+                    .setFilter("(path=*.doc)")
                     .setCallbacks("add", null)); 
         Service resourceProvider = m.createService()
             .setImplementation(new ResourceProvider(e))
@@ -110,16 +108,17 @@ public class ResourceDependencyTest exte
     
     static class ResourceConsumer {
         private volatile int m_counter;
-        public void add(Resource resource) {
+        private Ensure m_ensure;
+        
+        public ResourceConsumer(Ensure ensure) {
+            m_ensure = ensure;
+        }
+        
+        public void add(URL resource) {
             m_counter++;
-            try {
-                resource.openStream();
-            }
-            catch (IOException e) {
-                e.printStackTrace();
-            }
+            m_ensure.step();
         }
-        public void remove(Resource resource) {
+        public void remove(URL resource) {
             m_counter--;
         }
         public void ensure() {
@@ -131,29 +130,20 @@ public class ResourceDependencyTest exte
         private volatile BundleContext m_context;
         private final Ensure m_ensure;
         private final Map m_handlers = new HashMap();
-        private StaticResource[] m_resources = {
-            new StaticResource("test1.txt", "/test", "TestRepository") {
-                public InputStream openStream() throws IOException {
-                    m_ensure.step(1);
-                    return null;
-                };
-            },
-            new StaticResource("test2.txt", "/test", "TestRepository") {
-                public InputStream openStream() throws IOException {
-                    m_ensure.step(2);
-                    return null;
-                };
-            },
-            new StaticResource("README.doc", "/", "TestRepository") {
-                public InputStream openStream() throws IOException {
-                    Assert.fail("resource should not have matched the filter");
-                    return null;
-                };
-            }
-        };
-
+        private URL[] m_resources;
+        
         public ResourceProvider(Ensure ensure) {
             m_ensure = ensure;
+            try {
+                m_resources = new URL[] {
+                    new URL("file://localhost/path/to/file1.txt"),
+                    new URL("file://localhost/path/to/file2.txt"),
+                    new URL("file://localhost/path/to/file3.doc")
+                };
+            }
+            catch (MalformedURLException e) {
+                throw new IllegalStateException(e);
+            }
         }
         
         public void add(ServiceReference ref, ResourceHandler handler) {
@@ -170,7 +160,7 @@ public class ResourceDependencyTest exte
                 m_handlers.put(handler, filter);
             }
                 for (int i = 0; i < m_resources.length; i++) {
-                    if (filter.match(m_resources[i].getProperties())) {
+                    if (filter.match(ResourceUtil.createProperties(m_resources[i]))) {
                         handler.added(m_resources[i]);
                     }
                 }
@@ -186,7 +176,7 @@ public class ResourceDependencyTest exte
 
         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.match(ResourceUtil.createProperties(m_resources[i]))) {
                         handler.removed(m_resources[i]);
                     }
                 }
@@ -205,49 +195,6 @@ public class ResourceDependencyTest exte
         }
     }
     
-    static class StaticResource implements Resource {
-        private String m_id;
-        private String m_name;
-        private String m_path;
-        private String m_repository;
-
-        public StaticResource(String name, String path, String repository) {
-            m_id = repository + ":" + path + "/" + name;
-            m_name = name;
-            m_path = path;
-            m_repository = repository;
-        }
-        
-        public String getID() {
-            return m_id;
-        }
-
-        public String getName() {
-            return m_name;
-        }
-
-        public String getPath() {
-            return m_path;
-        }
-
-        public String getRepository() {
-            return m_repository;
-        }
-        
-        public Dictionary getProperties() {
-            return new Properties() {{
-                put(Resource.ID, getID());
-                put(Resource.NAME, getName());
-                put(Resource.PATH, getPath());
-                put(Resource.REPOSITORY, getRepository());
-            }};
-        }
-
-        public InputStream openStream() throws IOException {
-            return null;
-        }
-    }
-    
     static class ResourceConsumerFactory {
         private final Ensure m_ensure;
         public ResourceConsumerFactory(Ensure ensure) {
@@ -255,7 +202,7 @@ public class ResourceDependencyTest exte
         }
         public Object create() {
             System.out.println("create");
-            ResourceConsumer resourceConsumer = new ResourceConsumer();
+            ResourceConsumer resourceConsumer = new ResourceConsumer(m_ensure);
             // create a dynamic proxy for the ResourceProvider
             return Proxy.newProxyInstance(resourceConsumer.getClass().getClassLoader(), resourceConsumer.getClass().getInterfaces(),
new DynamicProxyHandler(resourceConsumer, m_ensure));
         }
@@ -270,7 +217,7 @@ public class ResourceDependencyTest exte
             m_ensure = ensure;
         }
 
-        public void add(Resource resource) {
+        public void add(URL resource) {
             m_ensure.step(4);
             System.out.println("Add resource: " + resource);
         }

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/SharingDependenciesWithMultipleServicesTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/SharingDependenciesWithMultipleServicesTest.java?rev=960066&r1=960065&r2=960066&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/SharingDependenciesWithMultipleServicesTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/SharingDependenciesWithMultipleServicesTest.java
Fri Jul  2 17:27:20 2010
@@ -22,8 +22,7 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 
-import java.io.IOException;
-import java.io.InputStream;
+import java.net.URL;
 import java.util.Dictionary;
 import java.util.Properties;
 
@@ -32,8 +31,8 @@ import org.apache.felix.dm.dependencies.
 import org.apache.felix.dm.dependencies.ConfigurationDependency;
 import org.apache.felix.dm.dependencies.ResourceDependency;
 import org.apache.felix.dm.dependencies.ServiceDependency;
-import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.resources.ResourceHandler;
+import org.apache.felix.dm.resources.ResourceUtil;
 import org.apache.felix.dm.service.Service;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -132,12 +131,12 @@ public class SharingDependenciesWithMult
     }
     
     @Test
-    public void testShareResourceDependencyWithMultipleServices(BundleContext context) {
+    public void testShareResourceDependencyWithMultipleServices(BundleContext context) throws
Exception {
         DependencyManager m = new DependencyManager(context);
         // helper class that ensures certain steps get executed in sequence
         Ensure e = new Ensure();
         // create a service provider and consumer
-        ResourceDependency dependency = m.createResourceDependency().setFilter("(" + Resource.REPOSITORY
+ "=TestRepository)").setRequired(true);
+        ResourceDependency dependency = m.createResourceDependency().setFilter("(" + ResourceHandler.HOST
+ "=localhost)").setRequired(true);
         Service consumer1 = m.createService().setImplementation(new ResourceConsumer(e, 1)).add(dependency);
         Service consumer2 = m.createService().setImplementation(new ResourceConsumer(e, 2)).add(dependency);
         Service resourceProvider = m.createService().setImplementation(new ResourceProvider()).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add",
"remove"));;
@@ -250,17 +249,22 @@ public class SharingDependenciesWithMult
     
     static class ResourceProvider {
         private volatile BundleContext m_context;
-        private StaticResource[] m_resources = {
-            new StaticResource("test1.txt", "/test", "TestRepository"),
-            new StaticResource("test2.txt", "/test", "TestRepository")
-        };
+        private URL[] m_resources;
+        
+        public ResourceProvider() throws Exception {
+            m_resources = new URL[] {
+                new URL("file://localhost/path/to/test1.txt"),
+                new URL("file://localhost/path/to/test2.txt")        
+                };
+            
+        }
 
         public void add(ServiceReference ref, ResourceHandler handler) {
             String filterString = (String) ref.getProperty("filter");
             try {
                 Filter filter = m_context.createFilter(filterString);
                 for (int i = 0; i < m_resources.length; i++) {
-                    if (filter.match(m_resources[i].getProperties())) {
+                    if (filter.match(ResourceUtil.createProperties(m_resources[i]))) {
                         handler.added(m_resources[i]);
                     }
                 }
@@ -275,7 +279,7 @@ public class SharingDependenciesWithMult
             try {
                 Filter filter = m_context.createFilter(filterString);
                 for (int i = 0; i < m_resources.length; i++) {
-                    if (filter.match(m_resources[i].getProperties())) {
+                    if (filter.match(ResourceUtil.createProperties(m_resources[i]))) {
                         handler.removed(m_resources[i]);
                     }
                 }
@@ -285,46 +289,4 @@ public class SharingDependenciesWithMult
             }
         }
     }
-    
-    static class StaticResource implements Resource {
-        private String m_id;
-        private String m_name;
-        private String m_path;
-        private String m_repository;
-
-        public StaticResource(String name, String path, String repository) {
-            m_id = repository + ":" + path + "/" + name;
-            m_name = name;
-            m_path = path;
-            m_repository = repository;
-        }
-        
-        public String getID() {
-            return m_id;
-        }
-
-        public String getName() {
-            return m_name;
-        }
-
-        public String getPath() {
-            return m_path;
-        }
-
-        public String getRepository() {
-            return m_repository;
-        }
-        
-        public Dictionary getProperties() {
-            return new Properties() {{
-                put(Resource.NAME, getName());
-                put(Resource.PATH, getPath());
-                put(Resource.REPOSITORY, getRepository());
-            }};
-        }
-
-        public InputStream openStream() throws IOException {
-            return null;
-        }
-    }
 }



Mime
View raw message