More refactoring. (FELIX-851)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@736339 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 5ceb622..4b3ebd3 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -34,7 +34,7 @@
class BundleImpl implements Bundle
{
- private final Felix m_feli;
+ private final Felix m_felix;
private final BundleArchive m_archive;
private IModule[] m_modules = new IModule[0];
@@ -62,30 +62,30 @@
BundleImpl(Felix felix, BundleArchive archive) throws Exception
{
- m_feli = felix;
+ m_felix = felix;
m_archive = archive;
m_state = Bundle.INSTALLED;
m_stale = false;
m_activator = null;
m_context = null;
- // TODO: REFACTOR - Null check is a hHack due to system bundle.
+ // TODO: REFACTOR - Null check is a hack due to system bundle.
if (m_archive != null)
{
- createAndAddModule();
+ addModule(createModule());
}
}
// TODO: REFACTOR - We need this method so the system bundle can override it.
Felix getFramework()
{
- return m_feli;
+ return m_felix;
}
- void reset() throws Exception
+ synchronized void reset() throws Exception
{
m_modules = new IModule[0];
- createAndAddModule();
+ addModule(createModule());
m_state = Bundle.INSTALLED;
m_stale = false;
m_cachedHeaders.clear();
@@ -93,15 +93,6 @@
m_removalPending = false;
}
- // TODO: REFACTOR - This method is sort of a hack. Since the system bundle
- // doesn't have an archive, it can override this method to return its
- // manifest.
- Map getCurrentManifestFromArchive() throws Exception
- {
- return m_archive.getRevision(
- m_archive.getRevisionCount() - 1).getManifestHeader();
- }
-
synchronized BundleActivator getActivator()
{
return m_activator;
@@ -884,7 +875,7 @@
{
// This operation will increase the revision count for the bundle.
m_archive.revise(location, is);
- createAndAddModule();
+ addModule(createModule());
}
synchronized boolean rollbackRevise() throws Exception
@@ -892,7 +883,7 @@
return m_archive.rollbackRevise();
}
- // TODO: REFACTOR - Hack for the system bundle.
+ // TODO: REFACTOR - This module is only visible for the system bundle.
synchronized void addModule(IModule module)
{
((ModuleImpl) module).setBundle(this);
@@ -903,11 +894,12 @@
m_modules = dest;
}
- synchronized void createAndAddModule() throws Exception
+ private synchronized IModule createModule() throws Exception
{
// Get and parse the manifest from the most recent revision to
// create an associated module for it.
- Map headerMap = getCurrentManifestFromArchive();
+ Map headerMap = m_archive.getRevision(
+ m_archive.getRevisionCount() - 1).getManifestHeader();
ManifestParser mp = new ManifestParser(
getFramework().getLogger(), getFramework().getConfig(), headerMap);
@@ -947,8 +939,6 @@
Long.toString(getBundleId()) + "." + Integer.toString(revision),
m_archive.getRevision(revision).getContent(),
headerMap,
-// TODO: REFACTOR - Karl, does this work correctly if the module is updated to
-// an extension bundle or vice versa?
(ExtensionManager.isExtensionBundle(headerMap)) ? null : mp.getCapabilities(),
mp.getRequirements(),
mp.getDynamicRequirements(),
@@ -984,12 +974,7 @@
}
}
- ((ModuleImpl) module).setBundle(this);
-
- IModule[] dest = new IModule[m_modules.length + 1];
- System.arraycopy(m_modules, 0, dest, 0, m_modules.length);
- dest[m_modules.length] = module;
- m_modules = dest;
+ return module;
}
void setProtectionDomain(ProtectionDomain pd)
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java b/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
index dd301ae..1c55726 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
@@ -30,6 +30,7 @@
private final Felix m_felix;
private final BundleImpl m_bundle;
+ // TODO: SECURITY - This should probably take a module, not a bundle.
BundleProtectionDomain(Felix felix, BundleImpl bundle)
throws MalformedURLException
{
diff --git a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
index c8d752d..63d01c0 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -122,8 +122,7 @@
// classloader.
private ExtensionManager()
{
-// TODO: REFACTOR - Karl, is this correct?
- m_module = new ExtensionManagerModule();
+ m_module = null;
m_extensions = new ArrayList();
m_names = new HashSet();
m_sourceToExtensions = new HashMap();
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 75d0b9a..f50c581 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -357,14 +357,6 @@
return this;
}
- // TODO: REFACTOR - This method is sort of a hack. Since the system bundle
- // doesn't have an archive, it can override this method to return its
- // manifest.
- Map getCurrentManifestFromArchive() throws Exception
- {
- return getCurrentModule().getHeaders();
- }
-
public long getBundleId()
{
return 0;
@@ -2061,7 +2053,6 @@
addSecurity(bundle);
-// TODO: REFACTOR - Karl, why do we do this check so late?
if (!bundle.isExtension())
{
Object sm = System.getSecurityManager();
@@ -3081,13 +3072,15 @@
return true;
}
+ // TODO: SECURITY - This should probably take a module, not a bundle.
void addSecurity(final BundleImpl bundle) throws Exception
{
if (m_securityProvider != null)
{
m_securityProvider.checkBundle(bundle);
}
- bundle.setProtectionDomain(new BundleProtectionDomain(this, bundle));
+ bundle.getCurrentModule().setSecurityContext(
+ new BundleProtectionDomain(this, bundle));
}
private BundleActivator createBundleActivator(BundleImpl impl)
@@ -3139,6 +3132,7 @@
// would be incorrect, because this is a refresh operation
// and should not trigger bundle REMOVE events.
IModule[] modules = bundle.getModules();
+// TODO: REFACTOR - It kind of sucks we need to remember this steps.
for (int i = 0; i < modules.length; i++)
{
m_resolverState.removeModule(modules[i]);
@@ -3803,7 +3797,7 @@
// Add new module to resolver state.
// TODO: REFACTOR - It is not clean to have to remember these steps.
m_resolverState.addModule(oldImpl.getCurrentModule());
-// TODO: REFACTOR - Seems like we don't need to repeat this.
+// TODO: REFACTOR - Could we set this when we add the module to the bundle?.
addSecurity(m_bundle);
fireBundleEvent(BundleEvent.UNRESOLVED, m_bundle);
}
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
index c8cfd15..552fab2 100644
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
@@ -101,7 +101,7 @@
// Read the boot delegation property and parse it.
// TODO: REFACTOR - This used to be per framework, now it is per module
-// which doesn't really make sense.
+// which doesn't really make sense. Maybe pass in the arrays.
String s = (m_configMap == null)
? null
: (String) m_configMap.get(Constants.FRAMEWORK_BOOTDELEGATION);