felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1237274 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/helper/ main/java/org/apache/felix/scr/impl/metadata/ test/java/org/apache/felix/scr/impl/helper/ test/java/org/apache/felix/scr/impl/metadata/instances/ test/java/org/...
Date Sun, 29 Jan 2012 13:06:32 GMT
Author: fmeschbe
Date: Sun Jan 29 13:06:31 2012
New Revision: 1237274

URL: http://svn.apache.org/viewvc?rev=1237274&view=rev
Log:
FELIX-3325 Apply patch by David Jencks (thanks!) to fix some issues with method resolution
and code completeness in ReferenceMetadata.

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ActivateMethod.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BaseMethod.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances/BaseObject.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances2/Level2Object.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ActivateMethod.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ActivateMethod.java?rev=1237274&r1=1237273&r2=1237274&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ActivateMethod.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ActivateMethod.java Sun
Jan 29 13:06:31 2012
@@ -87,7 +87,10 @@ public class ActivateMethod extends Base
                 try
                 {
                     // find the declared method in this class
-                    return getMethod( targetClass, getMethodName(), null, acceptPrivate,
acceptPackage );
+                    Method m = getMethod( targetClass, getMethodName(), null, acceptPrivate,
acceptPackage );
+                    if ( m != null ) {
+                        return m;
+                    }
                 }
                 catch ( SuitableMethodNotAccessibleException smnae )
                 {
@@ -188,7 +191,7 @@ public class ActivateMethod extends Base
 
         // rethrow if we looked for all method signatures and only found
         // one or more which would be suitable but not accessible
-        if ( ex != null )
+        if ( singleParameterMethod == null && ex != null )
         {
             throw ex;
         }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BaseMethod.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BaseMethod.java?rev=1237274&r1=1237273&r2=1237274&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BaseMethod.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BaseMethod.java Sun Jan
29 13:06:31 2012
@@ -351,6 +351,10 @@ abstract class BaseMethod
                 getComponentManager().log( LogService.LOG_WARNING, buf.toString(), cdfe );
             }
         }
+        catch ( SuitableMethodNotAccessibleException e)
+        {
+            throw e;
+        }
         catch ( Throwable throwable )
         {
             // unexpected problem accessing the method, don't let everything
@@ -358,7 +362,7 @@ abstract class BaseMethod
             throw new InvocationTargetException( throwable, "Unexpected problem trying to
get method " + name );
         }
 
-        // cuaght and ignored exception, assume no method and continue search
+        // caught and ignored exception, assume no method and continue search
         return null;
     }
 

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java?rev=1237274&r1=1237273&r2=1237274&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
Sun Jan 29 13:06:31 2012
@@ -428,6 +428,8 @@ public class ReferenceMetadata
                     null );
             m_updated = null;
         }
+
+        m_validated = true;
     }
 
 }
\ No newline at end of file

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java?rev=1237274&r1=1237273&r2=1237274&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
Sun Jan 29 13:06:31 2012
@@ -208,6 +208,34 @@ public class ActivateMethodTest extends 
         ensureMethodNotFoundMethod( level3, "activate_suitable" );
     }
 
+    public void test_unsuitable_method_selection() throws Exception
+    {
+        //check that finding an unsuitable method does not prevent finding
+        // a lower precedence suitable method.
+
+        checkMethod( level2, "activate_comp_unsuitable" );
+
+        checkMethod( level3, "activate_comp_unsuitable" );
+    }
+
+    public void test_precedence() throws Exception
+    {
+        //All tested methods are only in base.  They differ in argurments and visibility.
+        //R4.2 compendium  112.5.8
+        //private method, arg ComponentContext
+        checkMethod( base, "activate_precedence_1", "activate_precedence_1_comp" );
+        //package method, arg BundleContext
+        checkMethod( level1, "activate_precedence_1", "activate_precedence_1_bundleContext"
);
+        //protected method, arg Map
+        checkMethod( level2, "activate_precedence_1", "activate_precedence_1_map" );
+
+        //private method, arg Map
+        checkMethod( base, "activate_precedence_2", "activate_precedence_2_map" );
+        //package method, args ComponentContext and Map
+        checkMethod( level1, "activate_precedence_2", "activate_precedence_2_comp_bundleContext"
);
+        //protected method, no args
+        checkMethod( level2, "activate_precedence_2", "activate_precedence_2_empty" );
+    }
 
     //---------- internal
 
@@ -221,6 +249,20 @@ public class ActivateMethodTest extends 
      */
     private void checkMethod( BaseObject obj, String methodName )
     {
+        checkMethod( obj, methodName, methodName );
+    }
+
+    /**
+     * Checks whether a method with the given name can be found for the
+     * activate/deactivate method parameter list and whether the method returns
+     * the expected description when called.
+     *
+     * @param obj
+     * @param methodName
+     * @param methodDesc
+     */
+    private void checkMethod( BaseObject obj, String methodName, String methodDesc )
+    {
         ComponentMetadata metadata = new ComponentMetadata( 0 )
         {
             public boolean isDS11()
@@ -234,7 +276,7 @@ public class ActivateMethodTest extends 
         Method m = get(am, "m_method");
         assertNotNull( m );
         assertEquals( methodName, m.getName() );
-        assertEquals( methodName, obj.getCalledMethod() );
+        assertEquals( methodDesc, obj.getCalledMethod() );
     }
 
 

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances/BaseObject.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances/BaseObject.java?rev=1237274&r1=1237273&r2=1237274&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances/BaseObject.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances/BaseObject.java
Sun Jan 29 13:06:31 2012
@@ -19,6 +19,8 @@
 package org.apache.felix.scr.impl.metadata.instances;
 
 
+import java.util.Map;
+
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
 
@@ -68,4 +70,38 @@ public class BaseObject
     {
         setCalledMethod( "activate_suitable" );
     }
+
+    //precedence rules
+
+    private void activate_precedence_1( ComponentContext ctx )
+    {
+        setCalledMethod("activate_precedence_1_comp");
+    }
+
+    void activate_precedence_1( BundleContext bundleContext )
+    {
+        setCalledMethod("activate_precedence_1_bundleContext");
+    }
+
+    protected void activate_precedence_1( Map map)
+    {
+        setCalledMethod("activate_precedence_1_map");
+    }
+
+    private void activate_precedence_2( Map map )
+    {
+        setCalledMethod("activate_precedence_2_map");
+    }
+
+    void activate_precedence_2( ComponentContext ctx, BundleContext bundle )
+    {
+        setCalledMethod("activate_precedence_2_comp_bundleContext");
+    }
+
+    protected void activate_precedence_2()
+    {
+        setCalledMethod("activate_precedence_2_empty");
+    }
+
+
 }

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances2/Level2Object.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances2/Level2Object.java?rev=1237274&r1=1237273&r2=1237274&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances2/Level2Object.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/instances2/Level2Object.java
Sun Jan 29 13:06:31 2012
@@ -52,4 +52,14 @@ public class Level2Object extends Level1
     {
         setCalledMethod( "activate_suitable" );
     }
+
+    private void activate_comp_unsuitable( ComponentContext ctx )
+    {
+        setCalledMethod( "activate_comp_unsuitable" );
+    }
+
+    protected void activate_comp_unsuitable( Map map )
+    {
+        setCalledMethod( "activate_comp_unsuitable" );
+    }
 }



Mime
View raw message