Applied patches in FELIX-2911 with some small changes. Should compile without problems now.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1091200 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/deviceaccess/pom.xml b/deviceaccess/pom.xml
index 7ee6498..b752f2c 100644
--- a/deviceaccess/pom.xml
+++ b/deviceaccess/pom.xml
@@ -23,8 +23,8 @@
 

   <parent>

     <groupId>org.apache.felix</groupId>

-    <artifactId>felix</artifactId>

-    <version>1.0.5-SNAPSHOT</version>

+    <artifactId>felix-parent</artifactId>

+    <version>2-SNAPSHOT</version>

     <relativePath>../pom/pom.xml</relativePath>

   </parent>

 

@@ -38,33 +38,32 @@
       Implementation of the OSGi Device Access Specification 1.1

   </description>

 

-  <dependencies>

-    <dependency>

-      <groupId>${pom.groupId}</groupId>

-      <artifactId>org.apache.felix.framework</artifactId>

-      <version>1.6.0</version>

-      <scope>test</scope>

-    </dependency>

-    <dependency>

-      <groupId>${pom.groupId}</groupId>

-      <artifactId>org.osgi.core</artifactId>

-      <version>1.0.0</version>

-      <scope>provided</scope>

-    </dependency>

-    <dependency>

-      <groupId>${pom.groupId}</groupId>

-      <artifactId>org.osgi.compendium</artifactId>

-      <version>1.0.0</version>

-      <scope>provided</scope>

-    </dependency>

-    <dependency>

-      <groupId>${pom.groupId}</groupId>

-      <artifactId>org.apache.felix.dependencymanager</artifactId>

-      <version>2.0.1</version>

-      <scope>provided</scope>

-    </dependency>

-  </dependencies>

-

+	 <dependencies>

+	   <dependency>

+	       <groupId>org.osgi</groupId>

+	       <artifactId>org.osgi.core</artifactId>

+	         <version>4.2.0</version>

+	       <scope>provided</scope>

+	   </dependency>

+	   <dependency>

+	       <groupId>org.osgi</groupId>

+	       <artifactId>org.osgi.compendium</artifactId>

+	         <version>4.2.0</version>

+	       <scope>provided</scope>

+	   </dependency>

+	   <dependency>

+	     <groupId>${pom.groupId}</groupId>

+	     <artifactId>org.apache.felix.framework</artifactId>

+	     <version>1.6.0</version>

+	     <scope>test</scope>

+	   </dependency>

+	   <dependency>

+	     <groupId>${pom.groupId}</groupId>

+	     <artifactId>org.apache.felix.dependencymanager</artifactId>

+	     <version>3.0.0-SNAPSHOT</version>

+	     <scope>provided</scope>

+	   </dependency>

+	 </dependencies>

   <build>

     <plugins>

       <plugin>

diff --git a/deviceaccess/src/main/java/org/apache/felix/das/Activator.java b/deviceaccess/src/main/java/org/apache/felix/das/Activator.java
index d43fca5..1bd6698 100644
--- a/deviceaccess/src/main/java/org/apache/felix/das/Activator.java
+++ b/deviceaccess/src/main/java/org/apache/felix/das/Activator.java
@@ -19,21 +19,18 @@
 package org.apache.felix.das;
 
 
+import org.apache.felix.das.util.Util;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-
 import org.osgi.service.device.Device;
 import org.osgi.service.device.Driver;
 import org.osgi.service.device.DriverLocator;
 import org.osgi.service.device.DriverSelector;
 import org.osgi.service.log.LogService;
 
-import org.apache.felix.dependencymanager.DependencyActivatorBase;
-import org.apache.felix.dependencymanager.DependencyManager;
-import org.apache.felix.dependencymanager.Service;
-
-import org.apache.felix.das.util.Util;
-
 
 /**
  * TODO: add javadoc
@@ -71,37 +68,39 @@
         // the real device manager
         startDeviceManager();
 
-        // the analyzers to inform the user (and me) if something is wrong
-        // startAnalyzers();
-
     }
 
 
-    private void startDeviceManager()
-    {
+    private void startDeviceManager() {
 
-        final String driverFilter = Util.createFilterString( "(&(%s=%s)(%s=%s))", new String[]
-            { Constants.OBJECTCLASS, Driver.class.getName(), org.osgi.service.device.Constants.DRIVER_ID, "*" } );
+        final String driverFilter = Util.createFilterString( "(%s=%s)", new String[]
+            { org.osgi.service.device.Constants.DRIVER_ID, "*" } );
 
-        final String deviceFilter = Util.createFilterString( "(|(%s=%s)(%s=%s))", new String[]
-            { Constants.OBJECTCLASS, Device.class.getName(), org.osgi.service.device.Constants.DEVICE_CATEGORY, "*" } );
+        final String deviceFilter = Util.createFilterString( "(|(%s=%s)(&(%s=%s)(%s=%s)))", new String[]
+            { 
+        	Constants.OBJECTCLASS, Device.class.getName(), 
+        	Constants.OBJECTCLASS, "*", 
+        	org.osgi.service.device.Constants.DEVICE_CATEGORY, "*" 
+        	} );
 
-        Service svc = createService();
+        Component svc = createComponent();
 
         svc.setImplementation( m_deviceManager );
 
         svc.add( createServiceDependency().setService( LogService.class ).setRequired( false ) );
 
-        svc.add( createServiceDependency().setService( DriverSelector.class ).setRequired( false )
-            .setAutoConfig( false ) );
+        svc.add( createServiceDependency().setService( DriverSelector.class ).setRequired( false ).setAutoConfig( false )
+    		.setCallbacks( "selectorAdded", "selectorRemoved" ) );
 
         svc.add( createServiceDependency().setService( DriverLocator.class ).setRequired( false ).setAutoConfig( false )
             .setCallbacks( "locatorAdded", "locatorRemoved" ) );
-        svc.add( createServiceDependency().setService( Driver.class, driverFilter ).setRequired( false ).setCallbacks(
-            "driverAdded", "driverRemoved" ) );
-        svc.add( createServiceDependency().setService( Device.class, deviceFilter ).setRequired( false ).setCallbacks(
-            "deviceAdded", "deviceModified", "deviceRemoved" ) );
-
+        
+        svc.add( createServiceDependency().setService( Driver.class, driverFilter ).setRequired( false )
+    		.setCallbacks( "driverAdded", "driverRemoved" ) );
+        
+        svc.add( createServiceDependency().setService( deviceFilter ).setRequired( false )
+    		.setCallbacks( "deviceAdded", "deviceModified", "deviceRemoved" ) );
+        
         m_manager.add( svc );
 
     }
diff --git a/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java b/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
index 8dcd9a5..928278a 100644
--- a/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
+++ b/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
@@ -53,7 +54,9 @@
 
 
 /**
- * TODO: add javadoc
+ * This class represents the Apache Felix implementation of the device access specification.
+ * It is based on version 1.1 of the spec.
+ * 
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
@@ -63,13 +66,13 @@
     private final long DEFAULT_TIMEOUT_SEC = 1;
 
     // the logger
-    private LogService m_log;
+    private volatile LogService m_log;
 
     // the bundle context
     private final BundleContext m_context;
 
     // the driver selector
-    private DriverSelector m_selector;
+    private volatile DriverSelector m_selector;
 
     // the driver locators
     private List<DriverLocator> m_locators;
@@ -86,11 +89,19 @@
     // used to add delayed actions
     private ScheduledExecutorService m_delayed;
 
+    //the devices filter
     private Filter m_deviceImplFilter;
 
+    //the drivers filter
     private Filter m_driverImplFilter;
 
 
+    /**
+     * Public constructor. Used by the Activator in this <code>Bundle</code>
+     * to instantiate one instance.
+     * 
+     * @param context the <code>BundleContext</code>
+     */
     public DeviceManager( BundleContext context )
     {
         m_context = context;
@@ -165,6 +176,19 @@
 
     // callback methods
 
+    public void selectorAdded( DriverSelector selector )
+    {
+        m_selector = selector;
+        debug( "driver selector appeared" );
+    }
+
+
+    public void selectorRemoved( DriverSelector selector )
+    {
+        m_selector = null;
+        debug( "driver selector lost" );
+    }
+    
     public void locatorAdded( DriverLocator locator )
     {
         m_locators.add( locator );
@@ -185,6 +209,9 @@
         m_drivers.put( ref, new DriverAttributes( ref, driver ) );
 
         debug( "driver appeared: " + Util.showDriver( ref ) );
+        
+        //immediately check for idle devices
+//        submit( new CheckForIdleDevices() );
     }
 
 
@@ -532,7 +559,7 @@
             // if there are no driver locators
             // we'll have to do with the drivers that where
             // added 'manually'
-            List<String> driverIds = m_driverLoader.findDrivers( m_locators, dict );
+            Set<String> driverIds = m_driverLoader.findDrivers( m_locators, dict );
 
             // remove the driverIds that are already available
             for ( DriverAttributes da : m_drivers.values() )
@@ -542,6 +569,7 @@
             driverIds.removeAll( m_drivers.keySet() );
             try
             {
+            	debug("entering attach phase for " + Util.showDevice( m_ref ) );
                 return driverAttachment( dict, driverIds.toArray( new String[0] ) );
             }
             finally
@@ -564,7 +592,7 @@
             // now load the drivers
             List<ServiceReference> driverRefs = m_driverLoader.loadDrivers( m_locators, driverIds );
             // these are the possible driver references that have been added
-            // add the to the list of included drivers
+            // add them to the list of included drivers
             for ( ServiceReference serviceReference : driverRefs )
             {
                 DriverAttributes da = m_drivers.get( serviceReference );
@@ -582,8 +610,10 @@
                 try
                 {
                     int match = driver.match( m_ref );
-                    if ( match <= Device.MATCH_NONE )
+                    if ( match <= Device.MATCH_NONE ) 
+                    {
                         continue;
+                    }
                     mi.add( match, driver );
                 }
                 catch ( Throwable t )
@@ -593,15 +623,20 @@
             }
 
             // get the best match
-            Match bestMatch;
+            Match bestMatch = null;
 
             // local copy
             final DriverSelector selector = m_selector;
+            
             if ( selector != null )
             {
                 bestMatch = mi.selectBestMatch( m_ref, selector );
+                if (bestMatch != null) {
+                	debug(String.format("DriverSelector (%s) found best match: %s", selector.getClass().getName(), Util.showDriver(bestMatch.getDriver())));
+                }
             }
-            else
+            
+            if (bestMatch == null) 
             {
                 bestMatch = mi.getBestMatch();
             }
diff --git a/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java b/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java
index eef7a71..0197f32 100644
--- a/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java
+++ b/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java
@@ -50,7 +50,7 @@
         }
         if ( String.class.isInstance( driverId ) )
         {
-            String value = String.class.cast( driverId );
+            String value = (String)( driverId );
             if ( value.length() == 0 )
             {
                 m_log.log( LogService.LOG_ERROR, "invalid driver: empty driver id: " + Util.showDriver( ref ) );
diff --git a/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java b/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java
index 199b8ec..321b2ad 100644
--- a/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java
+++ b/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java
@@ -24,7 +24,9 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Dictionary;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.felix.das.DriverAttributes;
 import org.apache.felix.das.Log;
@@ -65,9 +67,9 @@
 
 
     @SuppressWarnings("all")
-    public List<String> findDrivers( Collection<DriverLocator> locators, Dictionary dict )
+    public Set<String> findDrivers( Collection<DriverLocator> locators, Dictionary dict )
     {
-        final List<String> list = new ArrayList<String>();
+        final Set<String> list = new HashSet<String>();
         for ( DriverLocator locator : locators )
         {
             list.addAll( findDrivers( locator, dict ) );
diff --git a/deviceaccess/src/test/java/org/apache/felix/das/ActivatorTest.java b/deviceaccess/src/test/java/org/apache/felix/das/ActivatorTest.java
deleted file mode 100644
index bb1656f..0000000
--- a/deviceaccess/src/test/java/org/apache/felix/das/ActivatorTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.das;
-
-import org.apache.felix.dependencymanager.DependencyManager;
-import org.apache.felix.dependencymanager.Service;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.osgi.framework.BundleContext;
-
-
-
-/**
- * 
- * Tests the Activator.
- * 
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class ActivatorTest {
-
-	
-	
-	private Activator m_activator;
-	
-	@Mock
-	private BundleContext m_context;
-	
-	@Mock
-	private DependencyManager m_manager;
-	
-	@Before
-	public void before() {
-
-		MockitoAnnotations.initMocks(this);
-		m_activator = new Activator();
-		
-	}
-
-	
-	
-	
-	@Test
-	public void VerifyActivatorInit() throws Exception {
-		
-		m_activator.init(m_context, m_manager);
-		
-		Mockito.verify(m_manager).add(Mockito.isA(Service.class));
-		
-	}
-	
-	/**
-	 * Verify we do not actively perform any actions during the destroy.
-	 * 
-	 * @throws Exception
-	 */
-	@Test
-	public void VerifyActivatorDestroy() throws Exception {
-		
-		m_activator.destroy(m_context, m_manager);
-		
-		Mockito.verifyZeroInteractions(m_context);
-		Mockito.verifyZeroInteractions(m_manager);
-		
-	}
-	
-	
-}
diff --git a/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java b/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java
index c0acf3e..aaaa591 100644
--- a/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java
+++ b/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java
@@ -100,6 +100,8 @@
 
         Mockito.when( m_context.getService( ref ) ).thenReturn( impl );
 
+        Mockito.when( ref.getUsingBundles() ).thenReturn( new Bundle[0] );
+        
         m_references.put( impl, ref );
 
         return ref;
diff --git a/deviceaccess/src/test/java/org/apache/felix/das/Utils.java b/deviceaccess/src/test/java/org/apache/felix/das/Utils.java
index 9398e13..6d2d9a3 100644
--- a/deviceaccess/src/test/java/org/apache/felix/das/Utils.java
+++ b/deviceaccess/src/test/java/org/apache/felix/das/Utils.java
@@ -49,7 +49,7 @@
     }
 
 
-    public static void inject( Object target, Class<?> clazz, Object injectable )
+    public static void inject( Object target, Class clazz, Object injectable )
     {
 
         Field[] fields = target.getClass().getDeclaredFields();
diff --git a/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java b/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java
index e44c37e..88423d9 100644
--- a/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java
+++ b/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java
@@ -1,3 +1,21 @@
+/*
+ * 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.das.util;
 
 
diff --git a/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java b/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java
index 789e2dd..d2dca9a 100644
--- a/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java
+++ b/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java
@@ -24,6 +24,7 @@
 import java.util.Dictionary;
 import java.util.List;
 import java.util.Properties;
+import java.util.Set;
 
 import org.apache.felix.das.DeviceManager;
 import org.junit.Assert;
@@ -90,7 +91,7 @@
         List<DriverLocator> locators = new ArrayList<DriverLocator>();
 
 
-        List<String> driverIds = m_loader.findDrivers( locators, new Properties() );
+        Set<String> driverIds = m_loader.findDrivers( locators, new Properties() );
         Assert.assertTrue( "should be an empty list", driverIds.size() == 0 );
         
     }
@@ -113,7 +114,7 @@
         locators.add( dl );
 
         Properties dict = new Properties();
-        List<String> driverIds = m_loader.findDrivers( locators, dict );
+        Set<String> driverIds = m_loader.findDrivers( locators, dict );
 
         Assert.assertEquals( "should not be an empty list", 2, driverIds.size());
 
@@ -144,7 +145,7 @@
 
         
         Properties dict = new Properties();
-        List<String> driverIds = m_loader.findDrivers( locators, dict );
+        Set<String> driverIds = m_loader.findDrivers( locators, dict );
 
         Assert.assertEquals( "should not be an empty list", 4, driverIds.size() );
 
@@ -163,7 +164,7 @@
 
         Mockito.when( dl.findDrivers( Mockito.eq( dict ) ) ).thenThrow( new RuntimeException( "test exception" ) );
 
-        List<String> driverIds = m_loader.findDrivers( locators, dict );
+        Set<String> driverIds = m_loader.findDrivers( locators, dict );
 
         Assert.assertTrue( "should be an empty list", driverIds.size() == 0 );
 
diff --git a/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java b/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java
index c19a690..918d32d 100644
--- a/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java
+++ b/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java
@@ -60,7 +60,8 @@
     @Before
     public void before() throws Exception
     {
-
+    	System.setProperty("org.osgi.vendor.framework", "org.apache.felix.framework");
+    	
     	MockitoAnnotations.initMocks(this);
     	
         m_devA = new DeviceAnalyzer( m_context );