FELIX-3734 Fix two issues related to MetaTypeProvider tracking:
  - don't return MetaTypeInformation for fragment bundles
  - use the MetaTypeService implementation bundle context to
      track services
  - the latter allows to downgrade the OSGi Core Reference to 4.0 again

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1402162 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/metatype/pom.xml b/metatype/pom.xml
index a19ea1b..7d18099 100644
--- a/metatype/pom.xml
+++ b/metatype/pom.xml
@@ -38,7 +38,7 @@
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
-            <version>4.1.0</version>
+            <version>4.0.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java
index 618a6df..7b97c20 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java
@@ -26,12 +26,14 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+
 import org.apache.felix.metatype.DefaultMetaTypeProvider;
 import org.apache.felix.metatype.Designate;
 import org.apache.felix.metatype.DesignateObject;
 import org.apache.felix.metatype.MetaData;
 import org.apache.felix.metatype.OCD;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.metatype.MetaTypeInformation;
 import org.osgi.service.metatype.MetaTypeProvider;
 import org.osgi.service.metatype.ObjectClassDefinition;
@@ -64,14 +66,14 @@
     private Set locales;
 
 
-    protected MetaTypeInformationImpl( Bundle bundle )
+    protected MetaTypeInformationImpl( final BundleContext serviceBundleContext, Bundle bundle )
     {
         this.bundle = bundle;
         this.pids = new HashSet();
         this.factoryPids = new HashSet();
         this.metaTypeProviders = new HashMap();
 
-        this.providerTacker = new MetaTypeProviderTracker( bundle.getBundleContext(), this );
+        this.providerTacker = new MetaTypeProviderTracker( serviceBundleContext, this );
         this.providerTacker.open();
     }
 
diff --git a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java
index a43bcd6..107550a 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java
@@ -41,7 +41,7 @@
     public Object addingService( ServiceReference reference )
     {
         // only care for services of our bundle
-        if ( !this.context.getBundle().equals( reference.getBundle() ) )
+        if ( !this.mti.getBundle().equals( reference.getBundle() ) )
         {
             return null;
         }
diff --git a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
index b4ee2fb..b52e4eb 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
@@ -30,6 +30,7 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Constants;
 import org.osgi.framework.SynchronousBundleListener;
 import org.osgi.service.log.LogService;
 import org.osgi.service.metatype.MetaTypeInformation;
@@ -116,6 +117,12 @@
      */
     public MetaTypeInformation getMetaTypeInformation( Bundle bundle )
     {
+        // no information for fragments
+        if ( bundle.getHeaders().get( Constants.FRAGMENT_HOST ) != null )
+        {
+            return null;
+        }
+
         MetaTypeInformation mti;
         synchronized ( this.bundleMetaTypeInformation )
         {
@@ -165,7 +172,7 @@
             return null;
         }
 
-        MetaTypeInformationImpl cmti = new MetaTypeInformationImpl( bundle );
+        MetaTypeInformationImpl cmti = new MetaTypeInformationImpl( bundleContext, bundle );
         while ( docs.hasMoreElements() )
         {
             URL doc = ( URL ) docs.nextElement();
diff --git a/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java b/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java
index 82ab35a..e573cc6 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java
@@ -19,6 +19,7 @@
 package org.apache.felix.metatype.internal;
 
 
+import java.util.Arrays;
 import java.util.Collection;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -76,7 +77,7 @@
      */
     public ServiceMetaTypeInformation( BundleContext bundleContext, Bundle bundle )
     {
-        super( bundle );
+        super( bundleContext, bundle );
 
         this.bundleContext = bundleContext;