FELIX-1823 Drop support for Framework API 1.3 (R4.0) and depend
on Bundle.getBundleContext and ServiceReference extends Comparable
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@830947 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/pom.xml b/scr/pom.xml
index a342935..b5a80d4 100644
--- a/scr/pom.xml
+++ b/scr/pom.xml
@@ -171,10 +171,12 @@
org.apache.felix.shell; resolution:=optional,
<!--
- Framework version 1.3 (from R4.0) is enough,
- the Bundle.getBundleContext method is guarded
+ Framework version 1.4 (from R4.1) is required
+ because we depend on ServiceReference being
+ Comparable and Bundle.getBundleContext method
+ being available.
-->
- org.osgi.framework;version="[1.3,2)",
+ org.osgi.framework;version="[1.4,2)",
<!--
LogService is optional but if present the
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index e9e7630..767f5d0 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -20,8 +20,6 @@
import java.io.PrintStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -230,7 +228,7 @@
}
// there should be components, load them with a bundle context
- BundleContext context = getBundleContext( bundle );
+ BundleContext context = bundle.getBundleContext();
if ( context == null )
{
log( LogService.LOG_ERROR, m_context.getBundle(), "Cannot get BundleContext of bundle "
@@ -326,79 +324,6 @@
}
- /**
- * Returns the <code>BundleContext</code> of the bundle.
- * <p>
- * This method assumes a <code>getContext</code> method returning a
- * <code>BundleContext</code> instance to be present in the class of the
- * bundle or any of its parent classes.
- *
- * @param bundle The <code>Bundle</code> whose context is to be returned.
- *
- * @return The <code>BundleContext</code> of the bundle or
- * <code>null</code> if no <code>getContext</code> method
- * returning a <code>BundleContext</code> can be found.
- */
- private BundleContext getBundleContext( Bundle bundle )
- {
- try
- {
- return bundle.getBundleContext();
- }
- catch ( SecurityException se )
- {
- // assume we do not have the correct AdminPermission[*,CONTEXT]
- // to call this, so we have to forward this exception
- throw se;
- }
- catch ( Throwable t )
- {
- // ignore any other Throwable, most prominently NoSuchMethodError
- // which is called in a pre-OSGI 4.1 environment
- }
-
- BundleContext context = null;
- for ( Class clazz = bundle.getClass(); context == null && clazz != null; clazz = clazz.getSuperclass() )
- {
- try
- {
- context = getBundleContext( clazz, bundle, "getBundleContext" );
- if ( context == null )
- {
- context = getBundleContext( clazz, bundle, "getContext" );
- }
- }
- catch ( NoSuchMethodException nsme )
- {
- // don't actually care, just try super class
- }
- catch ( Throwable t )
- {
- log( LogService.LOG_ERROR, m_context.getBundle(), "Cannot get BundleContext for "
- + bundle.getSymbolicName(), t );
- }
- }
-
- // return what we found
- return context;
- }
-
-
- private BundleContext getBundleContext( Class clazz, Bundle bundle, String methodName )
- throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
- {
- Method m = clazz.getDeclaredMethod( methodName, null );
- if ( m.getReturnType().equals( BundleContext.class ) )
- {
- m.setAccessible( true );
- return ( BundleContext ) m.invoke( bundle, null );
- }
-
- // method exists but has wrong return type
- return null;
- }
-
-
private static int getLogLevel( BundleContext bundleContext )
{
String levelString = bundleContext.getProperty( "ds.loglevel" );
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
index a5f4f99..afb943a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
@@ -577,21 +577,14 @@
return refs[0];
}
- // is it correct to assume an ordered bound services set ?
- int maxRanking = Integer.MIN_VALUE;
- long minId = Long.MAX_VALUE;
- ServiceReference selectedRef = null;
// find the service with the highest ranking
- for ( int i = 0; refs != null && i < refs.length; i++ )
+ ServiceReference selectedRef = refs[0];
+ for ( int i = 1; i < refs.length; i++ )
{
ServiceReference ref = refs[i];
- int ranking = getServiceRanking( ref );
- long id = getServiceId( ref );
- if ( maxRanking < ranking || ( maxRanking == ranking && id < minId ) )
+ if ( ref.compareTo( selectedRef ) > 0 )
{
- maxRanking = ranking;
- minId = id;
selectedRef = ref;
}
}
@@ -642,46 +635,6 @@
}
- /**
- * Returns the value of the <code>service.ranking</code> service property
- * if the property exists and is of type <code>java.lang.Integer</code>. If
- * the property does not exist or is of another type, zero is returned as
- * the default value for service ranking.
- *
- * @param serviceReference The Service reference whose ranking is to be
- * returned.
- */
- private int getServiceRanking( ServiceReference serviceReference )
- {
- Object nrRankObj = serviceReference.getProperty( Constants.SERVICE_RANKING );
- if ( nrRankObj instanceof Integer )
- {
- return ( ( Integer ) nrRankObj ).intValue();
- }
- return 0;
- }
-
-
- /**
- * Returns the value of the <code>service.id</code> service property.
- *
- * @param serviceReference The Service reference whose service id is to be
- * returned.
- *
- * @throws ClassCastException if the <code>service.id</code> property exists
- * but is not a <code>java.lang.Long</code> value. This is not
- * expected since the framework should guarantee this property and
- * its type.
- * @throws NullPointerException if the <code>service.id</code> property
- * does not exist. This is not expected since the framework should
- * guarantee this property and its type.
- */
- private long getServiceId( ServiceReference serviceReference )
- {
- return ( ( Long ) serviceReference.getProperty( Constants.SERVICE_ID ) ).longValue();
- }
-
-
//---------- bound services maintenance -----------------------------------
/**
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java b/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java
index 509d35b..8563e10 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java
@@ -88,4 +88,11 @@
{
return m_registration;
}
+
+
+ @Override
+ public String toString()
+ {
+ return getClass().getSimpleName() + ": value=" + getValue();
+ }
}