felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r800242 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/helper/ main/java/org/apache/felix/scr/impl/manager/ main/java/org/apache/felix/scr/impl/metadata/ test/java/org/apache/felix/scr/impl/metadata/
Date Mon, 03 Aug 2009 07:46:48 GMT
Author: fmeschbe
Date: Mon Aug  3 07:46:48 2009
New Revision: 800242

URL: http://svn.apache.org/viewvc?rev=800242&view=rev
Log:
FELIX-1437 Include declaration namespace in the decision of which
method signature to accept.

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReflectionHelper.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/UnbindMethod.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.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/metadata/XmlHandlerTest.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReflectionHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReflectionHelper.java?rev=800242&r1=800241&r2=800242&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReflectionHelper.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReflectionHelper.java Mon
Aug  3 07:46:48 2009
@@ -50,14 +50,17 @@
     public static final Class MAP_CLASS = Map.class;
     public static final Class INTEGER_CLASS = Integer.class;
 
-    // Helper used to find the best matching activate and modified methods
-    public static final ActivatorMethodTester ACTIVATE_ACCEPTED_PARAMETERS = new ActivatorMethodTester(
new Class[]
+    // Helper used to find the best matching activate and modified methods (DS 1.1 and newer)
+    public static final MethodTester ACTIVATE_ACCEPTED_PARAMETERS = new ActivatorMethodTester(
new Class[]
         { COMPONENT_CONTEXT_CLASS, BUNDLE_CONTEXT_CLASS, MAP_CLASS } );
 
-    // Helper used to find the best matching deactivate method
-    public static final ActivatorMethodTester DEACTIVATE_ACCEPTED_PARAMETERS = new ActivatorMethodTester(
new Class[]
+    // Helper used to find the best matching deactivate method (DS 1.1 and newer)
+    public static final MethodTester DEACTIVATE_ACCEPTED_PARAMETERS = new ActivatorMethodTester(
new Class[]
         { COMPONENT_CONTEXT_CLASS, BUNDLE_CONTEXT_CLASS, MAP_CLASS, Integer.TYPE, INTEGER_CLASS
} );
 
+    // Helper used to find the best matching activate/deactivate method (DS 1.0)
+    public static final MethodTester ACTIVATOR_10_ACCEPTED_PARAMETERS = new ActivatorMethodTester10();
+
     static
     {
         Method tmpSentinel = null;
@@ -107,15 +110,16 @@
         throws NoSuchMethodException, InvocationTargetException
     {
         // whether we accept package private methods
-        boolean acceptPackage = true;
+        boolean acceptPackage = tester.acceptPackage();
         final String packageName = getPackageName( objectClass );
         final Class[] parameterTypesList = tester.getParameterLists();
 
         for ( Class clazz = objectClass; clazz != null; clazz = clazz.getSuperclass() )
         {
-            // turns false on first package not equal to the package of objectClass
-            acceptPackage &= packageName.equals( getPackageName( clazz ) );
-            final boolean acceptPrivate = clazz == objectClass;
+            // turns false on first package not equal to the package of objectClass (or different
class loader)
+            acceptPackage &= packageName.equals( getPackageName( clazz ) )
+                && clazz.getClassLoader() == objectClass.getClassLoader();
+            final boolean acceptPrivate = tester.acceptPrivate() && clazz == objectClass;
 
             // check parameter types first
             for ( int i = 0; i < parameterTypesList.length; i++ )
@@ -158,7 +162,7 @@
                 try
                 {
                     // find the declared method in this class
-                    return getMethod( clazz, name, null, clazz == objectClass, acceptPackage
);
+                    return getMethod( clazz, name, null, acceptPrivate, acceptPackage );
                 }
                 catch ( NoSuchMethodException nsme )
                 {
@@ -321,6 +325,15 @@
          */
         boolean acceptEmpty();
 
+        /**
+         * Returns <code>true</code> if private methods are allowed at all.
+         */
+        boolean acceptPrivate();
+
+        /**
+         * Returns <code>true</code> if package private methods are allowed at
all.
+         */
+        boolean acceptPackage();
 
         /**
          * Returns <code>true</code> if the method <code>m</code>
is suitable for
@@ -336,6 +349,11 @@
         Class[] getParameterLists();
     }
 
+    /**
+     * The <code>ActivatorMethodTester</code> class implements the {@link MethodTester}
+     * interface to test methods applicable for Components declared with the
+     * SCR 1.1 (or newer) specification namespace.
+     */
     public static final class ActivatorMethodTester implements ReflectionHelper.MethodTester
     {
         private final Class[] parameterLists;
@@ -356,6 +374,18 @@
         }
 
 
+        public boolean acceptPrivate()
+        {
+            return true;
+        }
+
+
+        public boolean acceptPackage()
+        {
+            return true;
+        }
+
+
         public boolean isSuitable( Method m )
         {
             Class[] types = m.getParameterTypes();
@@ -386,4 +416,52 @@
 
     }
 
+
+    /**
+     * The <code>ActivatorMethodTester10</code> class implements the
+     * {@link MethodTester} interface to test methods applicable for Components
+     * declared with the original SCR 1.0 specification namespace.
+     */
+    public static final class ActivatorMethodTester10 implements ReflectionHelper.MethodTester
+    {
+
+        private static final Class[] PARAMETER_LIST =
+            { COMPONENT_CONTEXT_CLASS };
+
+
+        public boolean acceptEmpty()
+        {
+            // DS 1.0 activator methods only accept ComponentContext
+            return false;
+        }
+
+
+        public boolean acceptPrivate()
+        {
+            // DS 1.0 activator methods may only be public or protected
+            return true;
+        }
+
+
+        public boolean acceptPackage()
+        {
+            // DS 1.0 activator methods may only be public or protected
+            return true;
+        }
+
+
+        public boolean isSuitable( Method m )
+        {
+            // DS 1.0 activator methods only accept ComponentContext
+            Class[] types = m.getParameterTypes();
+            return types.length == 1 && types[0] == COMPONENT_CONTEXT_CLASS;
+        }
+
+
+        public Class[] getParameterLists()
+        {
+            return PARAMETER_LIST;
+        }
+    }
+
 }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java?rev=800242&r1=800241&r2=800242&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
Mon Aug  3 07:46:48 2009
@@ -128,13 +128,15 @@
                 m_componentManager.log( level, message, m_componentManager.getComponentMetadata(),
ex );
             }
         };
-        m_bind = new BindMethod( m_dependencyMetadata.getBind(),
+        m_bind = new BindMethod( m_componentManager.getComponentMetadata().isDS11(),
+                                 m_dependencyMetadata.getBind(),
                                  m_componentInstance.getClass(),
                                  m_dependencyMetadata.getName(),
                                  m_dependencyMetadata.getInterface(),
                                  logger
         );
-        m_unbind = new UnbindMethod( m_dependencyMetadata.getUnbind(),
+        m_unbind = new UnbindMethod( m_componentManager.getComponentMetadata().isDS11(),
+                                     m_dependencyMetadata.getUnbind(),
                                      m_componentInstance.getClass(),
                                      m_dependencyMetadata.getName(),
                                      m_dependencyMetadata.getInterface(),

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java?rev=800242&r1=800241&r2=800242&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Mon Aug  3 07:46:48 2009
@@ -190,8 +190,17 @@
         // get the method
         if ( activateMethod == ReflectionHelper.SENTINEL )
         {
-            activateMethod = getMethod( implementationObject, getComponentMetadata().getActivate(),
-                ReflectionHelper.ACTIVATE_ACCEPTED_PARAMETERS );
+            // FELIX-1437: New signatures only with DS 1.1 namespace declaration
+            if ( getComponentMetadata().isDS11() )
+            {
+                activateMethod = getMethod( implementationObject, getComponentMetadata().getActivate(),
+                    ReflectionHelper.ACTIVATE_ACCEPTED_PARAMETERS );
+            }
+            else
+            {
+                activateMethod = getMethod( implementationObject, getComponentMetadata().getActivate(),
+                    ReflectionHelper.ACTIVATOR_10_ACCEPTED_PARAMETERS );
+            }
         }
 
         // 4. Call the activate method, if present
@@ -220,8 +229,17 @@
         // get the method
         if ( deactivateMethod == ReflectionHelper.SENTINEL )
         {
-            deactivateMethod = getMethod( implementationObject, getComponentMetadata().getDeactivate(),
-                ReflectionHelper.DEACTIVATE_ACCEPTED_PARAMETERS );
+            // FELIX-1437: New signatures only with DS 1.1 namespace declaration
+            if ( getComponentMetadata().isDS11() )
+            {
+                deactivateMethod = getMethod( implementationObject, getComponentMetadata().getDeactivate(),
+                    ReflectionHelper.DEACTIVATE_ACCEPTED_PARAMETERS );
+            }
+            else
+            {
+                deactivateMethod = getMethod( implementationObject, getComponentMetadata().getDeactivate(),
+                    ReflectionHelper.ACTIVATOR_10_ACCEPTED_PARAMETERS );
+            }
         }
 
         // 1. Call the deactivate method, if present

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/UnbindMethod.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/UnbindMethod.java?rev=800242&r1=800241&r2=800242&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/UnbindMethod.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/UnbindMethod.java Mon
Aug  3 07:46:48 2009
@@ -25,10 +25,10 @@
 class UnbindMethod extends BindMethod
 {
 
-    UnbindMethod( final String methodName, final Class componentClass, final String referenceName,
-        final String referenceClassName, final Logger logger )
+    UnbindMethod( final boolean isDS11, final String methodName, final Class componentClass,
+        final String referenceName, final String referenceClassName, final Logger logger
)
     {
-        super( methodName, componentClass, referenceName, referenceClassName, logger );
+        super( isDS11, methodName, componentClass, referenceName, referenceClassName, logger
);
     }
 
 

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java?rev=800242&r1=800241&r2=800242&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
Mon Aug  3 07:46:48 2009
@@ -345,6 +345,16 @@
 
 
     /**
+     * Returns <code>true</code> if the metadata declaration has used the
+     * Declarative Services version 1.1 namespace or a later namespace.
+     */
+    public boolean isDS11()
+    {
+        return getNamespaceCode() >= XmlHandler.DS_VERSION_1_1;
+    }
+
+
+    /**
      * Returns the name of the component
      *
      * @return A string containing the name of the component

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=800242&r1=800241&r2=800242&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
Mon Aug  3 07:46:48 2009
@@ -162,7 +162,7 @@
         }
 
         m_policy = policy;
-        
+
         // secondary property
         m_isStatic = POLICY_STATIC.equals( policy );
     }
@@ -354,7 +354,7 @@
         if ( m_name == null )
         {
             // 112.10 name attribute is optional, defaults to interface since DS 1.1
-            if ( componentMetadata.getNamespaceCode() < XmlHandler.DS_VERSION_1_1 )
+            if ( !componentMetadata.isDS11() )
             {
                 throw componentMetadata.validationFailure( "A name must be declared for the
reference" );
             }
@@ -365,7 +365,7 @@
         {
             throw componentMetadata.validationFailure( "An interface must be declared for
the reference" );
         }
-        
+
 
         if ( m_cardinality == null )
         {

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/XmlHandlerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/XmlHandlerTest.java?rev=800242&r1=800241&r2=800242&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/XmlHandlerTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/metadata/XmlHandlerTest.java Mon
Aug  3 07:46:48 2009
@@ -60,6 +60,7 @@
         final ComponentMetadata cm10 = ( ComponentMetadata ) metadataList10.get( 0 );
         cm10.validate( logger );
         assertEquals( "DS Version 1.0", XmlHandler.DS_VERSION_1_0, cm10.getNamespaceCode()
);
+        assertFalse( "DS Version 1.0", cm10.isDS11() );
         assertEquals( "Expected Activate Method not set", "activate", cm10.getActivate()
);
         assertEquals( "Expected Deactivate Method not set", "deactivate", cm10.getDeactivate()
);
         assertNull( "Expected Modified Method not set", cm10.getModified() );
@@ -134,7 +135,8 @@
         // dont validate this, we test the raw reading
 
         // ds namespace
-        assertEquals( "ds name space", XmlHandler.DS_VERSION_1_0, cm10.getNamespaceCode()
);
+        assertEquals( "DS Version 1.0", XmlHandler.DS_VERSION_1_0, cm10.getNamespaceCode()
);
+        assertFalse( "DS Version 1.0", cm10.isDS11() );
 
         // base component attributes
         assertEquals( "component name", true, cm10.isEnabled() );



Mime
View raw message