felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1615442 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/helper/ test/java/org/apache/felix/scr/impl/helper/ test/java/org/apache/felix/scr/impl/manager/components/
Date Sun, 03 Aug 2014 19:28:05 GMT
Author: djencks
Date: Sun Aug  3 19:28:05 2014
New Revision: 1615442

URL: http://svn.apache.org/r1615442
Log:
FELIX-4505 1.3 bind method parameter checking

Added:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
  (with props)
Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java?rev=1615442&r1=1615441&r2=1615442&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java Sun Aug
 3 19:28:05 2014
@@ -23,6 +23,7 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.felix.scr.impl.Activator;
 import org.apache.felix.scr.impl.manager.ComponentContextImpl;
@@ -251,7 +252,70 @@ public class BindMethod extends BaseMeth
             }
             if ( getDSVersion().isDS13() )
             {
-                //TODO
+                for (Method m: targetClass.getDeclaredMethods())
+                {
+                    if (getMethodName().equals(m.getName())) {
+                        Class<?>[] parameterTypes = m.getParameterTypes();
+                        boolean matches = true;
+                        boolean specialMatch = true;
+                        for (Class<?> paramType: parameterTypes) {
+                            if (paramType == SERVICE_REFERENCE_CLASS)
+                            {
+                                if (specialMatch && parameterClass == SERVICE_REFERENCE_CLASS)
+                                {
+                                    specialMatch = false;
+                                    m_paramTypes.add(ParamType.serviceType);
+                                }
+                                else
+                                {
+                                    m_paramTypes.add(ParamType.serviceReference);
+                                }
+                            }
+                            else if (paramType == SERVICE_OBJECTS_CLASS)
+                            {
+                                if (specialMatch && parameterClass == SERVICE_OBJECTS_CLASS)
+                                {
+                                    specialMatch = false;
+                                    m_paramTypes.add(ParamType.serviceType);
+                                }
+                                else
+                                {
+                                    m_paramTypes.add(ParamType.serviceObjects);
+                                }
+                            }
+                            else if (paramType == Map.class)
+                            {
+                                if (specialMatch && parameterClass == Map.class)
+                                {
+                                    specialMatch = false;
+                                    m_paramTypes.add(ParamType.serviceType);
+                                }
+                                else
+                                {
+                                    m_paramTypes.add(ParamType.map);
+                                }
+                            }
+                            else if (paramType.isAssignableFrom( parameterClass ) )
+                            {
+                                m_paramTypes.add(ParamType.serviceType);
+                            }
+                            else
+                            {
+                                matches = false;
+                                m_paramTypes.clear();
+                                break;
+                            }
+                        }
+                        if (matches)
+                        {
+                            if ( accept( m, acceptPrivate, acceptPackage, returnValue() )
)
+                            {
+                                return m;
+                            }
+                            suitableMethodNotAccessible = true;
+                        }
+                    }
+                }
             }
         }
         else if ( logger.isLogEnabled( LogService.LOG_WARNING ) )

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java?rev=1615442&r1=1615441&r2=1615442&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java Sun
Aug  3 19:28:05 2014
@@ -29,6 +29,7 @@ import org.apache.felix.scr.impl.manager
 import org.apache.felix.scr.impl.manager.SingleRefPair;
 import org.apache.felix.scr.impl.manager.components.FakeService;
 import org.apache.felix.scr.impl.manager.components.T1;
+import org.apache.felix.scr.impl.manager.components.T1MapSR;
 import org.apache.felix.scr.impl.manager.components.T1a;
 import org.apache.felix.scr.impl.manager.components.T3;
 import org.apache.felix.scr.impl.manager.components2.T2;
@@ -429,6 +430,17 @@ public class BindMethodTest extends Test
         testMethod( "suitable", new T1a(), DSVersion.DS10, "suitableT1" );
         testMethod( "suitable", new T1a(), DSVersion.DS11, "suitableT1" );
     }
+    
+    public void test_13()
+    {
+        //single map param
+        testMethod( "packageT1Map", new T1(), DSVersion.DS12, null);
+        testMethod( "packageT1Map", new T1(), DSVersion.DS13, "packageT1Map");
+        
+        //map, sr
+        testMethod( "packageT1MapSR", new T1MapSR(), DSVersion.DS12, null);
+        testMethod( "packageT1MapSR", new T1MapSR(), DSVersion.DS13, "packageT1MapSR");
+    }
 
 
     private void testMethod( final String methodName, final T1 component, final DSVersion
dsVersion,

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java?rev=1615442&r1=1615441&r2=1615442&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java Sun
Aug  3 19:28:05 2014
@@ -382,4 +382,21 @@ public class T1
     {
         callPerformed = "suitableT1";
     }
+    
+    void packageT1Map(Map props)
+    {
+        if ( props != null && !props.isEmpty())
+        {
+            callPerformed = "packageT1Map";
+        }
+        else if ( props == null)
+        {
+            callPerformed = "packageT1Map with null props";
+        }
+        else
+        {
+            callPerformed = "packageT1Map with empty props";
+        }
+    }
+    
 }
\ No newline at end of file

Added: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java?rev=1615442&view=auto
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
(added)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
Sun Aug  3 19:28:05 2014
@@ -0,0 +1,42 @@
+/*
+ * 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.scr.impl.manager.components;
+
+import java.util.Map;
+
+import org.osgi.framework.ServiceReference;
+
+public class T1MapSR extends T1
+{
+    
+    void packageT1MapSR( Map props, ServiceReference sr)
+    {
+        if ( props != null && !props.isEmpty() && sr != null )
+        {
+            callPerformed = "packageT1MapSR";
+        }
+        else
+        {
+            callPerformed = "packageT1MapSR error: props: " + props + " SR " + sr;
+        }
+
+    }
+
+
+}

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message