felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1528874 - in /felix/trunk/ipojo: manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/ manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ manipulator/manipulator/src/ma...
Date Thu, 03 Oct 2013 14:07:02 GMT
Author: clement
Date: Thu Oct  3 14:07:02 2013
New Revision: 1528874

URL: http://svn.apache.org/r1528874
Log:
Fix:
* FELIX-4251 The @Bind annotation should use Class instead of String
* FELIX-4269 Introduce an enumeration to configure binding policy from the annotation

Added:
    felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/BindingPolicy.java
Modified:
    felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
    felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Modified.java
    felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
    felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/AbstractBindVisitor.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/PolicyDependency.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-interceptor-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooConsumer.java

Modified: felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
(original)
+++ felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
Thu Oct  3 14:07:02 2013
@@ -49,9 +49,9 @@ public @interface Bind {
     
     /**
      * Set the required specification.
-     * Default : empty (try to discover)
+     * Default : no specification, will be deduced.
      */
-    String specification() default "";
+    Class specification() default Object.class;
     
     /**
      * Set the dependency id.
@@ -61,16 +61,16 @@ public @interface Bind {
     
     /**
      * Set the binding policy.
-     * Acceptable policy are dynamic, static and dynamic-priority.
+     * Acceptable policies are dynamic, static and dynamic-priority.
      * Default: dynamic.
      */
-    String policy() default "dynamic";
+    BindingPolicy policy() default BindingPolicy.DYNAMIC;
     
     /**
      * Set the comparator.
      * The indicated class must implement {@link Comparator}
      */
-    Class comparator() default Comparator.class;
+    Class<? extends Comparator> comparator() default Comparator.class;
     
     /**
      * Set the from attribute.

Added: felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/BindingPolicy.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/BindingPolicy.java?rev=1528874&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/BindingPolicy.java
(added)
+++ felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/BindingPolicy.java
Thu Oct  3 14:07:02 2013
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.annotations;
+
+/**
+* Binding policies supported by iPOJO.
+*/
+public enum BindingPolicy {
+    DYNAMIC,
+    STATIC,
+    DYNAMIC_PRIORITY;
+}

Modified: felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Modified.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Modified.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Modified.java
(original)
+++ felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Modified.java
Thu Oct  3 14:07:02 2013
@@ -62,16 +62,16 @@ public @interface Modified {
 
     /**
      * Set the binding policy.
-     * Acceptable policy are dynamic, static and dynamic-priority.
+     * Acceptable policies are dynamic, static and dynamic-priority.
      * Default: dynamic.
      */
-    String policy() default "dynamic";
+    BindingPolicy policy() default BindingPolicy.DYNAMIC;
 
     /**
      * Set the comparator.
      * The indicated class must implement {@link Comparator}
      */
-    Class comparator() default Comparator.class;
+    Class<? extends Comparator> comparator() default Comparator.class;
 
     /**
      * Set the from attribute.

Modified: felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
(original)
+++ felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
Thu Oct  3 14:07:02 2013
@@ -75,13 +75,13 @@ public @interface Requires {
      * Acceptable policy are dynamic, static and dynamic-priority.
      * Default: dynamic.
      */
-    String policy() default "dynamic";
+    BindingPolicy policy() default BindingPolicy.DYNAMIC;
 
     /**
      * Set the comparator.
      * The indicated class must implement {@link Comparator}
      */
-    Class comparator() default Comparator.class;
+    Class<?extends Comparator> comparator() default Comparator.class;
 
     /**
      * Set the from attribute.
@@ -92,7 +92,7 @@ public @interface Requires {
      * Set the required service specification.
      * This attribute is required for Collection field.
      */
-    String specification() default "";
+    Class specification() default Object.class;
 
     /**
      * Set to true if the service dependency is injected

Modified: felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
(original)
+++ felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
Thu Oct  3 14:07:02 2013
@@ -52,7 +52,7 @@ public @interface Unbind {
      * Set the required specification.
      * Default : empty (try to discover).
      */
-    String specification() default "";
+    Class specification() default Object.class;
     
     /**
      * Set the dependency id.
@@ -65,13 +65,13 @@ public @interface Unbind {
      * Acceptable policy are dynamic, static and dynamic-priority.
      * Default: dynamic.
      */
-    String policy() default "dynamic";
+    BindingPolicy policy() default BindingPolicy.DYNAMIC;
     
     /**
      * Set the comparator.
      * The indicated class must implement {@link Comparator}
      */
-    Class comparator() default Comparator.class;
+    Class<? extends Comparator> comparator() default Comparator.class;
     
     /**
      * Set the from attribute.

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java
(original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java
Thu Oct  3 14:07:02 2013
@@ -129,8 +129,9 @@ public class RequiresVisitor extends Emp
             m_nullable = value.toString();
             return;
         }
+        // Used by component using the pre 1.11 version of annotations.
         if (name.equals("policy")) {
-            m_policy = value.toString();
+            m_policy = getPolicy(value.toString());
             return;
         }
         if (name.equals("defaultimplementation")) {
@@ -144,7 +145,13 @@ public class RequiresVisitor extends Emp
             return;
         }
         if (name.equals("specification")) {
-            m_specification = value.toString();
+            // Detect whether it's an internal class name.
+            if (value.toString().startsWith("L")  && value.toString().endsWith(";"))
{
+                Type type = Type.getType(value.toString());
+                m_specification = type.getClassName();
+            } else {
+                m_specification = value.toString();
+            }
             return;
         }
         if (name.equals("id")) {
@@ -168,6 +175,13 @@ public class RequiresVisitor extends Emp
         }
     }
 
+    @Override
+    public void visitEnum(String name, String desc, String value) {
+        if (name.equals("policy")) {
+            m_policy = getPolicy(value.toString());
+        }
+    }
+
     /**
      * End of the annotation.
      * Create a "requires" element
@@ -231,4 +245,23 @@ public class RequiresVisitor extends Emp
 
         workbench.getElements().put(requires, null);
     }
+
+    /**
+     * Gets the iPOJO binding policy name from the given value.
+     * @param policy  the read policy
+     * @return the policy name
+     */
+    public static String getPolicy(String policy) {
+        if (policy.equalsIgnoreCase("static")) {
+            return "static";
+        }
+        if (policy.equalsIgnoreCase("dynamic")) {
+            return "dynamic";
+        }
+        // The _ is used in the annotation.
+        if (policy.equalsIgnoreCase("dynamic_priority")) {
+            return "dynamic-priority";
+        }
+        return policy;
+    }
 }
\ No newline at end of file

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/AbstractBindVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/AbstractBindVisitor.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/AbstractBindVisitor.java
(original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/AbstractBindVisitor.java
Thu Oct  3 14:07:02 2013
@@ -20,6 +20,7 @@
 package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.bind;
 
 import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.RequiresVisitor;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
 import org.objectweb.asm.AnnotationVisitor;
@@ -98,11 +99,18 @@ public abstract class AbstractBindVisito
             return;
         }
         if (name.equals("specification")) {
-            m_specification = value.toString();
+            // Detect whether it's an internal class name.
+            if (value.toString().startsWith("L")  && value.toString().endsWith(";"))
{
+                Type type = Type.getType(value.toString());
+                m_specification = type.getClassName();
+            } else {
+                m_specification = value.toString();
+            }
             return;
         }
+        // Still used by component using the old version of the annotations.
         if (name.equals("policy")) {
-            m_policy = value.toString();
+            m_policy = RequiresVisitor.getPolicy(value.toString());
             return;
         }
         if (name.equals("id")) {
@@ -123,6 +131,13 @@ public abstract class AbstractBindVisito
 
     }
 
+    @Override
+    public void visitEnum(String name, String desc, String value) {
+        if (name.equals("policy")) {
+            m_policy = RequiresVisitor.getPolicy(value.toString());
+        }
+    }
+
     public void visitEnd() {
     }
 

Modified: felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/PolicyDependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/PolicyDependency.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/PolicyDependency.java
(original)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/PolicyDependency.java
Thu Oct  3 14:07:02 2013
@@ -19,41 +19,38 @@
 
 package org.apache.felix.ipojo.runtime.core.test.components;
 
-import org.apache.felix.ipojo.annotations.Bind;
-import org.apache.felix.ipojo.annotations.Component;
-import org.apache.felix.ipojo.annotations.Requires;
-import org.apache.felix.ipojo.annotations.Unbind;
+import org.apache.felix.ipojo.annotations.*;
 import org.apache.felix.ipojo.runtime.core.test.services.FooService;
 
 @Component
 public class PolicyDependency {
 
-    @Requires(policy="static")
+    @Requires(policy= BindingPolicy.STATIC)
     public FooService fs;
     
-    @Requires(policy="dynamic-priority")
+    @Requires(policy=BindingPolicy.DYNAMIC_PRIORITY)
     public FooService fs2;
     
-    @Unbind(policy="static")
+    @Unbind(policy=BindingPolicy.STATIC)
     public void unbindBar() {    }
     @Bind
     public void bindBar() {    }
     
     @Unbind
     public void unbindBaz() {    }
-    @Bind(policy="static")
+    @Bind(policy=BindingPolicy.STATIC)
     public void bindBaz() {    }
    
-    @Requires(id="inv")
+    @Requires(id="inv", specification = FooService.class)
     public FooService fs2inv;
-    @Bind(id="inv", policy="static")
+    @Bind(id="inv", policy=BindingPolicy.STATIC)
     public void bindFS2Inv() {   }
     @Unbind(id="inv")
     public void unbindFS2Inv() {   }
     
-    @Unbind(policy="static", id="unbindonly")
+    @Unbind(policy=BindingPolicy.STATIC, id="unbindonly")
     public void unbind() {    }
     
-    @Bind(policy="static", id="bindonly")
+    @Bind(policy=BindingPolicy.STATIC, id="bindonly")
     public void bind() {    }
 }

Modified: felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java
(original)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java
Thu Oct  3 14:07:02 2013
@@ -87,14 +87,14 @@ public class TestDependencyPolicy extend
 
 
     private Element getDependencyById(Element[] deps, String name) {
-        for (int i = 0; i < deps.length; i++) {
-            String na = deps[i].getAttribute("id");
-            String field = deps[i].getAttribute("field");
+        for (Element dep : deps) {
+            String na = dep.getAttribute("id");
+            String field = dep.getAttribute("field");
             if (na != null && na.equalsIgnoreCase(name)) {
-                return deps[i];
+                return dep;
             }
             if (field != null && field.equalsIgnoreCase(name)) {
-                return deps[i];
+                return dep;
             }
         }
         fail("Dependency  " + name + " not found");

Modified: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-interceptor-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooConsumer.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-interceptor-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooConsumer.java?rev=1528874&r1=1528873&r2=1528874&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-interceptor-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooConsumer.java
(original)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-interceptor-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooConsumer.java
Thu Oct  3 14:07:02 2013
@@ -35,7 +35,7 @@ import java.util.Properties;
 @Provides
 public class FooConsumer implements CheckService {
 
-    @Requires(id= "foo", policy = "dynamic-priority", proxy = false)
+    @Requires(id= "foo", policy = BindingPolicy.DYNAMIC_PRIORITY, proxy = false)
     private FooService foo;
 
     private Map<String, Object> props;



Mime
View raw message