FELIX-4331 : [Core R5] Support BundleContext and Framework adaptations. Apply patch from David Bosschaert

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1549750 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 4a2ecfe..3dd1ddb 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -1044,7 +1044,11 @@
     public synchronized <A> A adapt(Class<A> type)
     {
         checkAdapt(type);
-        if (type == BundleStartLevel.class)
+        if (type == BundleContext.class)
+        {
+            return (A) m_context;
+        }
+        else if (type == BundleStartLevel.class)
         {
             return (A) getFramework().adapt(FrameworkStartLevelImpl.class)
                 .createBundleStartLevel(this);
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 97dc6e7..b184120 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -18,11 +18,11 @@
  */
 package org.apache.felix.framework;
 
-import org.osgi.framework.launch.Framework;
 import java.io.*;
 import java.net.*;
 import java.security.*;
 import java.util.*;
+
 import org.apache.felix.framework.BundleWiringImpl.BundleClassLoader;
 import org.apache.felix.framework.ServiceRegistry.ServiceRegistryCallbacks;
 import org.apache.felix.framework.cache.BundleArchive;
@@ -63,6 +63,7 @@
 import org.osgi.framework.ServicePermission;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.launch.Framework;
 import org.osgi.framework.startlevel.FrameworkStartLevel;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRevision;
@@ -372,7 +373,7 @@
         }
 
         // Read the security default policy property
-        m_securityDefaultPolicy = "true".equals(getProperty(FelixConstants.SECURITY_DEFAULT_POLICY)); 
+        m_securityDefaultPolicy = "true".equals(getProperty(FelixConstants.SECURITY_DEFAULT_POLICY));
 
         // Create default bundle stream handler.
         m_bundleStreamHandler = new URLHandlersBundleStreamHandler(this);
@@ -484,7 +485,12 @@
     public <A> A adapt(Class<A> type)
     {
         checkAdapt(type);
-        if ((type == FrameworkWiring.class)
+        if ((type == Framework.class)
+            || (type == Felix.class))
+        {
+            return (A) this;
+        }
+        else if ((type == FrameworkWiring.class)
             || (type == FrameworkWiringImpl.class))
         {
             return (A) m_fwkWiring;
@@ -4303,7 +4309,7 @@
         {
             Bundle source = bundleProtectionDomain.getBundle();
 
-            return (m_securityDefaultPolicy && (source == null || source.getBundleId() != 0)) ? 
+            return (m_securityDefaultPolicy && (source == null || source.getBundleId() != 0)) ?
                 bundleProtectionDomain.superImplies(permission) : true;
         }
     }