felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1067937 - in /felix/trunk/dependencymanager: annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/ runtime/src/main/java/org/apache/felix/dm/runtime/ test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ tes...
Date Mon, 07 Feb 2011 12:39:15 GMT
Author: pderop
Date: Mon Feb  7 12:39:15 2011
New Revision: 1067937

URL: http://svn.apache.org/viewvc?rev=1067937&view=rev
Log:
FELIX-2828: Allows a ResourceDependency annotation to inject the resource on a class field

Added:
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumerField.java
Modified:
    felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java

Modified: felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java?rev=1067937&r1=1067936&r2=1067937&view=diff
==============================================================================
--- felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
(original)
+++ felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
Mon Feb  7 12:39:15 2011
@@ -648,8 +648,13 @@ public class AnnotationCollector extends
             Verifier.verifyFilter(filter, 0);
             writer.put(EntryParam.filter, filter);
         }
+        
+        if (m_isField)
+        {
+            writer.put(EntryParam.autoConfig, m_field);
+        }
 
-        writer.putString(annotation, EntryParam.added, m_method);
+        writer.putString(annotation, EntryParam.added, (!m_isField) ? m_method : null);
         writer.putString(annotation, EntryParam.changed, null);
         writer.putString(annotation, EntryParam.removed, null);
         writer.putString(annotation, EntryParam.required, null);

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java?rev=1067937&r1=1067936&r2=1067937&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java
Mon Feb  7 12:39:15 2011
@@ -224,13 +224,16 @@ public class DependencyBuilder
         String filter = m_metaData.getString(Params.filter, null);
         boolean required = "true".equals(m_metaData.getString(Params.required, "true"));
         boolean propagate = "true".equals(m_metaData.getString(Params.propagate, "false"));
+        String autoConfigField = m_metaData.getString(Params.autoConfig, null);
 
-        Dependency dp = createResourceDependency(dm, added, changed, removed, required, filter,
propagate, instanceBound);
+        Dependency dp = createResourceDependency(dm, added, changed, removed, required, filter,

+                                                 propagate, autoConfigField, instanceBound);
         return dp;
     }
 
     private Dependency createResourceDependency(DependencyManager dm, String added,
-        String changed, String removed, boolean required, String filter, boolean propagate,
boolean instanceBound)
+        String changed, String removed, boolean required, String filter, boolean propagate,

+        String autoConfigField, boolean instanceBound)
     {
         ResourceDependency rd = dm.createResourceDependency();
         rd.setCallbacks(added, changed, removed);
@@ -239,6 +242,10 @@ public class DependencyBuilder
         {
             rd.setFilter(filter);
         }
+        if (autoConfigField != null)
+        {
+            rd.setAutoConfig(autoConfigField);
+        }
         rd.setPropagate(propagate);
         rd.setInstanceBound(instanceBound);
         return rd;

Added: felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumerField.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumerField.java?rev=1067937&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumerField.java
(added)
+++ felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/resource/ResourceConsumerField.java
Mon Feb  7 12:39:15 2011
@@ -0,0 +1,34 @@
+package org.apache.felix.dm.test.bundle.annotation.resource;
+
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.ResourceDependency;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+
+/**
+ * A Component which as a resource dependency, using a class field.
+ */
+@Component
+public class ResourceConsumerField
+{
+    @ServiceDependency(required=true,filter = "(test=resourceField)")
+    Sequencer m_sequencer;
+    
+    @ResourceDependency(filter = "(&(path=*/test1.txt)(host=localhost))")
+    URL m_resource;
+    
+    @Init
+    void init() 
+    {          
+        if (m_resource != null)
+        {
+            Assert.assertTrue("file://localhost/path/to/test1.txt".equals(m_resource.toString()));
+            m_sequencer.step(1);
+        }
+    }
+}

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java?rev=1067937&r1=1067936&r2=1067937&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java
Mon Feb  7 12:39:15 2011
@@ -76,6 +76,19 @@ public class ResourceAnnotationTest exte
     }
 
     /**
+     * Tests a simple ResourceConsumer using a class field for resource injection
+     */
+    @Test
+    public void testResourceAnnotationAutoConfig(BundleContext context)
+    {
+        DependencyManager m = new DependencyManager(context);
+        Properties props = new Properties() {{ put("test", "resourceField"); }};
+        m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(),
props));
+        super.stopBundle("ResourceTest", context);
+        m_ensure.waitForStep(1, 10000);
+    }
+
+   /**
      * Tests a ResourceAdapter
      * @param context
      */



Mime
View raw message