Modified the framework to always create a bundle context for a bundle
when it is started and to invalidate it when it is stopped.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@425320 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 09e1d9e..f30af56 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -52,19 +52,8 @@
m_info = info;
}
- /**
- * This method is a hack to make Felix compatible with Equinox'
- * Declarative Services implementation; this should be revisited
- * in the future.
- * @return the bundle context associated with this bundle.
- **/
private BundleContext getContext()
{
- BundleContext bc = m_info.getContext();
- if (bc == null)
- {
- m_info.setContext(new BundleContextImpl(m_felix, this));
- }
return m_info.getContext();
}
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
index 47b4355..a22d47d 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -1195,17 +1195,15 @@
try
{
+ // Set the bundle's context.
+ info.setContext(new BundleContextImpl(this, bundle));
+
// Set the bundle's activator.
info.setActivator(createBundleActivator(bundle.getInfo()));
// Activate the bundle if it has an activator.
if (bundle.getInfo().getActivator() != null)
{
- if (info.getContext() == null)
- {
- info.setContext(new BundleContextImpl(this, bundle));
- }
-
if (System.getSecurityManager() != null)
{
java.security.AccessController.doPrivileged(
@@ -1229,12 +1227,9 @@
// then reset its state to RESOLVED.
info.setState(Bundle.RESOLVED);
- // Clean up the bundle context, if necessary.
- if (info.getContext() != null)
- {
- ((BundleContextImpl) info.getContext()).invalidate();
- info.setContext(null);
- }
+ // Clean up the bundle context.
+ ((BundleContextImpl) info.getContext()).invalidate();
+ info.setContext(null);
// Unregister any services offered by this bundle.
m_registry.unregisterServices(bundle);
@@ -1555,13 +1550,10 @@
m_logger.log(Logger.LOG_ERROR, "Error stopping bundle.", th);
rethrow = th;
}
-
- // Clean up the bundle context, if necessary.
- if (info.getContext() != null)
- {
- ((BundleContextImpl) info.getContext()).invalidate();
- info.setContext(null);
- }
+
+ // Clean up the bundle context.
+ ((BundleContextImpl) info.getContext()).invalidate();
+ info.setContext(null);
// Unregister any services offered by this bundle.
m_registry.unregisterServices(bundle);