You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2009/10/29 14:48:37 UTC

svn commit: r830947 - in /felix/trunk/scr: ./ src/main/java/org/apache/felix/scr/impl/ src/main/java/org/apache/felix/scr/impl/manager/ src/test/java/org/apache/felix/scr/integration/components/

Author: fmeschbe
Date: Thu Oct 29 13:48:37 2009
New Revision: 830947

URL: http://svn.apache.org/viewvc?rev=830947&view=rev
Log:
FELIX-1823 Drop support for Framework API 1.3 (R4.0) and depend
on Bundle.getBundleContext and ServiceReference extends Comparable

Modified:
    felix/trunk/scr/pom.xml
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java

Modified: felix/trunk/scr/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/pom.xml?rev=830947&r1=830946&r2=830947&view=diff
==============================================================================
--- felix/trunk/scr/pom.xml (original)
+++ felix/trunk/scr/pom.xml Thu Oct 29 13:48:37 2009
@@ -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

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java?rev=830947&r1=830946&r2=830947&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java Thu Oct 29 13:48:37 2009
@@ -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" );

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=830947&r1=830946&r2=830947&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 Thu Oct 29 13:48:37 2009
@@ -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 -----------------------------------
 
     /**

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java?rev=830947&r1=830946&r2=830947&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java Thu Oct 29 13:48:37 2009
@@ -88,4 +88,11 @@
     {
         return m_registration;
     }
+
+
+    @Override
+    public String toString()
+    {
+        return getClass().getSimpleName() + ": value=" + getValue();
+    }
 }