FELIX-4505 1.3 bind method parameter checking
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1615442 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java b/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java
index f02943d..61af7c1 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/helper/BindMethod.java
@@ -23,6 +23,7 @@
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 @@
}
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 ) )
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java b/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
index f0baef1..d85e42c 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
@@ -29,6 +29,7 @@
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 @@
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,
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java b/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java
index f4d7364..2800d6d 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1.java
@@ -382,4 +382,21 @@
{
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
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java b/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
new file mode 100644
index 0000000..e3f097f
--- /dev/null
+++ b/scr/src/test/java/org/apache/felix/scr/impl/manager/components/T1MapSR.java
@@ -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;
+ }
+
+ }
+
+
+}