Performed some refactoring on the module loader layer to simplify the
structure to some degree by creating a IModuleDefinition that can be
used to store and access the module metadata.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@424730 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
index 0a24187..c7a6920 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
@@ -16,7 +16,6 @@
*/
package org.apache.felix.framework;
-import org.apache.felix.framework.searchpolicy.IR4SearchPolicy;
import org.apache.felix.framework.searchpolicy.R4Export;
import org.apache.felix.moduleloader.IModule;
import org.osgi.framework.Bundle;
@@ -86,8 +85,7 @@
public boolean isRemovalPending()
{
- return ((IR4SearchPolicy)
- m_exportingModule.getContentLoader().getSearchPolicy()).isRemovalPending();
+ return m_exportingModule.isRemovalPending();
}
public String toString()
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 97e1f00..9724413 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
@@ -343,15 +343,16 @@
BundleInfo info = new BundleInfo(
m_logger, new SystemBundleArchive(), null);
systembundle = new SystemBundle(this, info, activatorList);
- systembundle.getInfo().addModule(m_factory.createModule("0"));
+ // Create a module for the system bundle.
+ IModuleDefinition md = new ModuleDefinition(
+ systembundle.getExports(), null, null, null);
+ systembundle.getInfo().addModule(m_factory.createModule("0", md));
systembundle.getContentLoader().setSearchPolicy(
new R4SearchPolicy(
m_policyCore, systembundle.getInfo().getCurrentModule()));
m_factory.setContentLoader(
systembundle.getInfo().getCurrentModule(),
systembundle.getContentLoader());
- m_policyCore.setExports(
- systembundle.getInfo().getCurrentModule(), systembundle.getExports());
m_installedBundleMap.put(
systembundle.getInfo().getLocation(), systembundle);
@@ -1434,8 +1435,8 @@
// Mark previous the bundle's old module for removal since
// it can no longer be used to resolve other modules per the spec.
- IModule module = info.getModules()[info.getModules().length - 2];
- m_policyCore.setRemovalPending(module, true);
+ ((ModuleImpl) info.getModules()[info.getModules().length - 2])
+ .setRemovalPending(true);
fireBundleEvent(BundleEvent.UPDATED, bundle);
}
@@ -1652,7 +1653,7 @@
// Mark current module for removal since it can no longer
// be used to resolve other modules per the spec.
- m_policyCore.setRemovalPending(target.getInfo().getCurrentModule(), true);
+ ((ModuleImpl) target.getInfo().getCurrentModule()).setRemovalPending(true);
// Put bundle in uninstalled bundle array.
rememberUninstalledBundle(bundle);
@@ -2432,7 +2433,7 @@
IModule[] modules = bundle.getInfo().getModules();
for (int modIdx = 0; modIdx < modules.length; modIdx++)
{
- R4Export[] exports = m_policyCore.getExports(modules[modIdx]);
+ R4Export[] exports = modules[modIdx].getDefinition().getExports();
if ((exports != null) && (exports.length > 0))
{
for (int expIdx = 0; expIdx < exports.length; expIdx++)
@@ -2477,12 +2478,12 @@
IModule[] modules = importer.getInfo().getModules();
for (int modIdx = 0; modIdx < modules.length; modIdx++)
{
- R4Wire wire = Util.getWire(modules[modIdx], ep.getName());
+ IWire wire = Util.getWire(modules[modIdx], ep.getName());
// If the resolving module is associated with the
// exporting bundle, then add current bundle to
// import list.
- if ((wire != null) && exporterInfo.hasModule(wire.getExportingModule()))
+ if ((wire != null) && exporterInfo.hasModule(wire.getExporter()))
{
// Add the bundle to the list of importers.
list.add(bundles[bundleIdx]);
@@ -2694,27 +2695,27 @@
// Now that we have all of the metadata associated with the
// module, we need to create the module itself. This is somewhat
// complicated because a module is constructed out of several
- // interrelated pieces (e.g., content loader, search policy,
- // url policy). We need to create all of these pieces and bind
- // them together.
+ // interrelated pieces (e.g., module definition, content loader,
+ // search policy, url policy). We need to create all of these
+ // pieces and bind them together.
- // First, create the module.
- IModule module = m_factory.createModule(
- Long.toString(targetId) + "." + Integer.toString(revision));
-
- // Attach the R4 search policy metadata to the module.
- m_policyCore.setExports(module, mp.getExports());
- m_policyCore.setImports(module, mp.getImports());
- m_policyCore.setDynamicImports(module, mp.getDynamicImports());
- m_policyCore.setLibraries(module,
+ // Create the module definition for the new module.
+ IModuleDefinition md = new ModuleDefinition(
+ mp.getExports(),
+ mp.getImports(),
+ mp.getDynamicImports(),
mp.getLibraries(
m_cache,
targetId,
revision,
m_config.get(Constants.FRAMEWORK_OS_NAME),
m_config.get(Constants.FRAMEWORK_PROCESSOR)));
+
+ // Create the module using the module definition.
+ IModule module = m_factory.createModule(
+ Long.toString(targetId) + "." + Integer.toString(revision), md);
- // Create the content loader associated with the module archive.
+ // Create the content loader from the module archive.
IContentLoader contentLoader = new ContentLoaderImpl(
m_logger,
m_cache.getArchive(targetId).getRevision(revision).getContent(),
@@ -3740,8 +3741,8 @@
java.security.PermissionCollection pc =
java.security.Policy.getPolicy().getPermissions(cs);
- R4Import[] imports = m_policyCore.getImports(
- m_bundle.getInfo().getCurrentModule());
+ R4Import[] imports =
+ m_bundle.getInfo().getCurrentModule().getDefinition().getImports();
for (int i = 0;i < imports.length; i++)
{
@@ -3755,8 +3756,8 @@
}
}
// Check export permission for all exports of the current module.
- R4Export[] implicitImports = m_policyCore.getExports(
- m_bundle.getInfo().getCurrentModule());
+ R4Export[] implicitImports =
+ m_bundle.getInfo().getCurrentModule().getDefinition().getExports();
for (int i = 0;i < implicitImports.length; i++)
{
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
index 76814db..c024951 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
@@ -16,8 +16,8 @@
*/
package org.apache.felix.framework;
-import org.apache.felix.framework.searchpolicy.R4Wire;
import org.apache.felix.framework.util.Util;
+import org.apache.felix.moduleloader.IWire;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
@@ -119,10 +119,10 @@
String pkgName =
Util.getClassPackage(className);
// Get package wiring from service requester.
- R4Wire requesterWire = Util.getWire(
+ IWire requesterWire = Util.getWire(
((BundleImpl) requester).getInfo().getCurrentModule(), pkgName);
// Get package wiring from service provider.
- R4Wire providerWire = Util.getWire(
+ IWire providerWire = Util.getWire(
((BundleImpl) m_bundle).getInfo().getCurrentModule(), pkgName);
// There are three situations that may occur here:
@@ -168,7 +168,7 @@
// same source module.
else
{
- allow = providerWire.getExportingModule().equals(requesterWire.getExportingModule());
+ allow = providerWire.getExporter().equals(requesterWire.getExporter());
}
return allow;
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/IR4SearchPolicy.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/IR4SearchPolicy.java
deleted file mode 100644
index 08ac520..0000000
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/IR4SearchPolicy.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2006 The Apache Software Foundation
- *
- * Licensed 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.framework.searchpolicy;
-
-import org.apache.felix.moduleloader.ISearchPolicy;
-
-/**
- * <p>
- * This interface extends the search policy interface with specific
- * methods related to implementing an R4 search policy. For the most
- * part, this interface is really implementation specific and should
- * not be used by any except the R4 search policy implementation or
- * those that are very sure they know what they are doing. For example,
- * just blindly calling the various setter methods will likely not
- * provide the desired results.
- * </p>
-**/
-public interface IR4SearchPolicy extends ISearchPolicy
-{
- public R4Export[] getExports();
- public void setExports(R4Export[] exports);
-
- public R4Import[] getImports();
- public void setImports(R4Import[] imports);
-
- public R4Import[] getDynamicImports();
- public void setDynamicImports(R4Import[] imports);
-
- public R4Library[] getLibraries();
- public void setLibraries(R4Library[] libraries);
-
- public R4Wire[] getWires();
- public void setWires(R4Wire[] wires);
-
- public boolean isResolved();
- public void setResolved(boolean resolved);
- public void resolve() throws ResolveException;
-
- public boolean isRemovalPending();
- public void setRemovalPending(boolean removePending);
-
- public void addResolverListener(ResolveListener l);
- public void removeResolverListener(ResolveListener l);
-}
\ No newline at end of file
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
new file mode 100644
index 0000000..2386acf
--- /dev/null
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.framework.searchpolicy;
+
+import org.apache.felix.moduleloader.IModuleDefinition;
+
+public class ModuleDefinition implements IModuleDefinition
+{
+ public R4Export[] m_exports = null;
+ public R4Import[] m_imports = null;
+ public R4Import[] m_dynamicImports = null;
+ public R4Library[] m_libraries = null;
+
+ public ModuleDefinition(
+ R4Export[] exports, R4Import[] imports,
+ R4Import[] dynamicImports, R4Library[] libraries)
+ {
+ m_exports = exports;
+ m_imports = imports;
+ m_dynamicImports = dynamicImports;
+ m_libraries = libraries;
+ }
+
+ public R4Export[] getExports()
+ {
+// TODO: ML - These should probably all return copies of the array.
+ return m_exports;
+ }
+
+ public R4Import[] getImports()
+ {
+ return m_imports;
+ }
+
+ public R4Import[] getDynamicImports()
+ {
+ return m_dynamicImports;
+ }
+
+ public R4Library[] getLibraries()
+ {
+ return m_libraries;
+ }
+}
\ No newline at end of file
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
index 972c542..ad77760 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
@@ -20,7 +20,7 @@
import org.apache.felix.moduleloader.*;
-public class R4SearchPolicy implements IR4SearchPolicy
+public class R4SearchPolicy implements ISearchPolicy
{
private R4SearchPolicyCore m_policyCore = null;
private IModule m_module = null;
@@ -53,91 +53,6 @@
return m_policyCore.findLibrary(m_module, name);
}
- public R4Export[] getExports()
- {
- return m_policyCore.getExports(m_module);
- }
-
- public void setExports(R4Export[] exports)
- {
- m_policyCore.setExports(m_module, exports);
- }
-
- public R4Import[] getImports()
- {
- return m_policyCore.getImports(m_module);
- }
-
- public void setImports(R4Import[] imports)
- {
- m_policyCore.setImports(m_module, imports);
- }
-
- public R4Import[] getDynamicImports()
- {
- return m_policyCore.getDynamicImports(m_module);
- }
-
- public void setDynamicImports(R4Import[] imports)
- {
- m_policyCore.setDynamicImports(m_module, imports);
- }
-
- public R4Library[] getLibraries()
- {
- return m_policyCore.getLibraries(m_module);
- }
-
- public void setLibraries(R4Library[] libraries)
- {
- m_policyCore.setLibraries(m_module, libraries);
- }
-
- public R4Wire[] getWires()
- {
- return m_policyCore.getWires(m_module);
- }
-
- public void setWires(R4Wire[] wires)
- {
- m_policyCore.setWires(m_module, wires);
- }
-
- public boolean isResolved()
- {
- return m_policyCore.isResolved(m_module);
- }
-
- public void setResolved(boolean resolved)
- {
- m_policyCore.setResolved(m_module, resolved);
- }
-
- public void resolve() throws ResolveException
- {
- m_policyCore.resolve(m_module);
- }
-
- public boolean isRemovalPending()
- {
- return m_policyCore.isRemovalPending(m_module);
- }
-
- public void setRemovalPending(boolean removalPending)
- {
- m_policyCore.setRemovalPending(m_module, removalPending);
- }
-
- public void addResolverListener(ResolveListener l)
- {
- m_policyCore.addResolverListener(l);
- }
-
- public void removeResolverListener(ResolveListener l)
- {
- m_policyCore.removeResolverListener(l);
- }
-
public String toString()
{
return m_module.toString();
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
index 7b6694c..e4e0cb0 100755
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
@@ -90,160 +90,13 @@
}
}
- public synchronized R4Export[] getExports(IModule module)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- return (data == null) ? null : data.m_exports;
- }
-
- public synchronized void setExports(IModule module, R4Export[] exports)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- if (data == null)
- {
- data = new ModuleData(module);
- m_moduleDataMap.put(module, data);
- }
- data.m_exports = exports;
-
- // When a module is added and its exports are set, create an
- // aggregated list of available exports to simplify later
- // processing when resolving bundles.
-
- // Add exports to available package map.
- for (int i = 0; (exports != null) && (i < exports.length); i++)
- {
- IModule[] modules = (IModule[]) m_availPkgMap.get(exports[i].getName());
-
- // We want to add the module into the list of available
- // exporters in sorted order (descending version and
- // ascending bundle identifier). Insert using a simple
- // binary search algorithm.
- if (modules == null)
- {
- modules = new IModule[] { module };
- }
- else
- {
- int top = 0, bottom = modules.length - 1, middle = 0;
- Version middleVersion = null;
- while (top <= bottom)
- {
- middle = (bottom - top) / 2 + top;
- middleVersion = Util.getExportPackage(
- modules[middle], exports[i].getName()).getVersion();
- // Sort in reverse version order.
- int cmp = middleVersion.compareTo(exports[i].getVersion());
- if (cmp < 0)
- {
- bottom = middle - 1;
- }
- else if (cmp == 0)
- {
- // Sort further by ascending bundle ID.
- long middleId = Util.getBundleIdFromModuleId(modules[middle].getId());
- long exportId = Util.getBundleIdFromModuleId(module.getId());
- if (middleId < exportId)
- {
- top = middle + 1;
- }
- else
- {
- bottom = middle - 1;
- }
- }
- else
- {
- top = middle + 1;
- }
- }
-
- IModule[] newMods = new IModule[modules.length + 1];
- System.arraycopy(modules, 0, newMods, 0, top);
- System.arraycopy(modules, top, newMods, top + 1, modules.length - top);
- newMods[top] = module;
- modules = newMods;
- }
-
- m_availPkgMap.put(exports[i].getName(), modules);
- }
- }
-
- public synchronized R4Import[] getImports(IModule module)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- return (data == null) ? null : data.m_imports;
- }
-
- public synchronized void setImports(IModule module, R4Import[] imports)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- if (data == null)
- {
- data = new ModuleData(module);
- m_moduleDataMap.put(module, data);
- }
- data.m_imports = imports;
- }
-
- public synchronized R4Import[] getDynamicImports(IModule module)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- return (data == null) ? null : data.m_dynamicImports;
- }
-
- public synchronized void setDynamicImports(IModule module, R4Import[] imports)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- if (data == null)
- {
- data = new ModuleData(module);
- m_moduleDataMap.put(module, data);
- }
- data.m_dynamicImports = imports;
- }
-
- public synchronized R4Library[] getLibraries(IModule module)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- return (data == null) ? null : data.m_libraries;
- }
-
- public synchronized void setLibraries(IModule module, R4Library[] libraries)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- if (data == null)
- {
- data = new ModuleData(module);
- m_moduleDataMap.put(module, data);
- }
- data.m_libraries = libraries;
- }
-
- public synchronized R4Wire[] getWires(IModule module)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- return (data == null) ? null : data.m_wires;
- }
-
- public synchronized void setWires(IModule module, R4Wire[] wires)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- if (data == null)
- {
- data = new ModuleData(module);
- m_moduleDataMap.put(module, data);
- }
- data.m_wires = wires;
- }
-
- public synchronized boolean isResolved(IModule module)
+ protected synchronized boolean isResolved(IModule module)
{
ModuleData data = (ModuleData) m_moduleDataMap.get(module);
return (data == null) ? false : data.m_resolved;
}
- public synchronized void setResolved(IModule module, boolean resolved)
+ protected synchronized void setResolved(IModule module, boolean resolved)
{
ModuleData data = (ModuleData) m_moduleDataMap.get(module);
if (data == null)
@@ -254,23 +107,6 @@
data.m_resolved = resolved;
}
- public synchronized boolean isRemovalPending(IModule module)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- return (data == null) ? false : data.m_removalPending;
- }
-
- public synchronized void setRemovalPending(IModule module, boolean removalPending)
- {
- ModuleData data = (ModuleData) m_moduleDataMap.get(module);
- if (data == null)
- {
- data = new ModuleData(module);
- m_moduleDataMap.put(module, data);
- }
- data.m_removalPending = removalPending;
- }
-
public Object[] definePackage(IModule module, String pkgName)
{
R4Package pkg = Util.getExportPackage(module, pkgName);
@@ -438,7 +274,7 @@
throws ClassNotFoundException, ResourceNotFoundException
{
// We delegate to the module's wires to find the class or resource.
- R4Wire[] wires = getWires(module);
+ IWire[] wires = module.getWires();
for (int i = 0; (wires != null) && (i < wires.length); i++)
{
// If we find the class or resource, then return it.
@@ -461,7 +297,7 @@
// At this point, the module's imports were searched and so was the
// the module's content. Now we make an attempt to load the
// class/resource via a dynamic import, if possible.
- R4Wire wire = attemptDynamicImport(module, pkgName);
+ IWire wire = attemptDynamicImport(module, pkgName);
// If the dynamic import was successful, then this initial
// time we must directly return the result from dynamically
@@ -522,7 +358,7 @@
return null;
}
- private R4Wire attemptDynamicImport(IModule module, String pkgName)
+ private IWire attemptDynamicImport(IModule module, String pkgName)
{
R4Wire wire = null;
IModule candidate = null;
@@ -588,7 +424,7 @@
// wiring attribute.
if (candidate != null)
{
- R4Wire[] wires = getWires(module);
+ IWire[] wires = module.getWires();
R4Wire[] newWires = null;
if (wires == null)
{
@@ -606,7 +442,7 @@
module, candidate,
Util.getExportPackage(candidate, impMatch.getName()));
newWires[newWires.length - 1] = wire;
- setWires(module, newWires);
+ ((ModuleImpl) module).setWires(newWires);
m_logger.log(Logger.LOG_DEBUG, "WIRE: " + newWires[newWires.length - 1]);
}
}
@@ -623,7 +459,7 @@
{
// Check the dynamic import specs for a match of
// the target package.
- R4Import[] dynamics = getDynamicImports(module);
+ R4Import[] dynamics = module.getDefinition().getDynamicImports();
R4Import impMatch = null;
for (int i = 0; (impMatch == null) && (dynamics != null)
&& (i < dynamics.length); i++)
@@ -669,7 +505,7 @@
// TODO: This "matching" algorithm does not fully
// match the spec and should be improved.
- R4Library[] libs = getLibraries(module);
+ R4Library[] libs = module.getDefinition().getLibraries();
for (int i = 0; (libs != null) && (i < libs.length); i++)
{
String path = libs[i].getPath(name);
@@ -802,7 +638,7 @@
// Loop through each import and calculate its resolving
// set of candidates.
- R4Import[] imports = getImports(module);
+ R4Import[] imports = module.getDefinition().getImports();
for (int impIdx = 0; (imports != null) && (impIdx < imports.length); impIdx++)
{
// Get the candidates from the "in use" and "available"
@@ -927,7 +763,7 @@
{
// The spec says that we cannot consider modules that
// are pending removal, so ignore them.
- if (includeRemovalPending || !isRemovalPending(modules[modIdx]))
+ if (includeRemovalPending || !modules[modIdx].isRemovalPending())
{
// Get the modules export package for the target package.
R4Export export = Util.getExportPackage(
@@ -1001,7 +837,7 @@
// of the root module that is not also imported; uses constraints
// for exported packages that are also imported will be taken
// care of as part of normal import package processing.
- R4Export[] exports = getExports(rootModule);
+ R4Export[] exports = rootModule.getDefinition().getExports();
Map usesMap = new HashMap();
for (int i = 0; (exports != null) && (i < exports.length); i++)
{
@@ -1124,11 +960,11 @@
// Get the actual exporter from the wire or if there
// is no wire, then get the export is from the module
// itself.
- R4Wire wire = Util.getWire(module, uses[usesIdx]);
+ IWire wire = Util.getWire(module, uses[usesIdx]);
if (wire != null)
{
usesMap = calculateUsesDependencies(
- resolverMap, wire.getExportingModule(), wire.getExport(), usesMap);
+ resolverMap, wire.getExporter(), wire.getExport(), usesMap);
}
else
{
@@ -1224,7 +1060,7 @@
{
Map.Entry entry = (Map.Entry) iter.next();
IModule module = (IModule) entry.getKey();
- R4Wire[] wires = (R4Wire[]) entry.getValue();
+ IWire[] wires = (IWire[]) entry.getValue();
// Set the module's resolved and wiring attribute.
setResolved(module, true);
@@ -1232,7 +1068,7 @@
// only modules may not have wires.
if (wires.length > 0)
{
- setWires(module, wires);
+ ((ModuleImpl) module).setWires(wires);
}
// Remove the wire's exporting module from the "available"
@@ -1245,7 +1081,7 @@
m_logger.log(Logger.LOG_DEBUG, "WIRE: " + wires[wireIdx]);
// First remove the wire module from "available" package map.
IModule[] modules = (IModule[]) m_availPkgMap.get(wires[wireIdx].getExport().getName());
- modules = removeModuleFromArray(modules, wires[wireIdx].getExportingModule());
+ modules = removeModuleFromArray(modules, wires[wireIdx].getExporter());
m_availPkgMap.put(wires[wireIdx].getExport().getName(), modules);
// Also remove any exported packages from the "available"
@@ -1256,7 +1092,7 @@
// to a different module. If the exported package is not
// actually exported, then we just want to remove it
// completely, since it cannot be used.
- if (wires[wireIdx].getExportingModule() != module)
+ if (wires[wireIdx].getExporter() != module)
{
modules = (IModule[]) m_availPkgMap.get(wires[wireIdx].getExport().getName());
modules = removeModuleFromArray(modules, module);
@@ -1265,7 +1101,7 @@
// Add the module of the wire to the "in use" package map.
modules = (IModule[]) m_inUsePkgMap.get(wires[wireIdx].getExport().getName());
- modules = addModuleToArray(modules, wires[wireIdx].getExportingModule());
+ modules = addModuleToArray(modules, wires[wireIdx].getExporter());
m_inUsePkgMap.put(wires[wireIdx].getExport().getName(), modules);
}
}
@@ -1282,7 +1118,7 @@
}
List nodeList = (List) resolverMap.get(module);
- R4Wire[] wires = new R4Wire[nodeList.size()];
+ IWire[] wires = new IWire[nodeList.size()];
// Put the module in the wireMap with an empty wire array;
// we do this early so we can use it to detect cycles.
@@ -1459,6 +1295,71 @@
public void moduleAdded(ModuleEvent event)
{
+ synchronized (m_factory)
+ {
+ // When a module is added, create an aggregated list of available
+ // exports to simplify later processing when resolving bundles.
+ IModule module = event.getModule();
+ R4Export[] exports = module.getDefinition().getExports();
+
+ // Add exports to available package map.
+ for (int i = 0; (exports != null) && (i < exports.length); i++)
+ {
+ IModule[] modules = (IModule[]) m_availPkgMap.get(exports[i].getName());
+
+ // We want to add the module into the list of available
+ // exporters in sorted order (descending version and
+ // ascending bundle identifier). Insert using a simple
+ // binary search algorithm.
+ if (modules == null)
+ {
+ modules = new IModule[] { module };
+ }
+ else
+ {
+ int top = 0, bottom = modules.length - 1, middle = 0;
+ Version middleVersion = null;
+ while (top <= bottom)
+ {
+ middle = (bottom - top) / 2 + top;
+ middleVersion = Util.getExportPackage(
+ modules[middle], exports[i].getName()).getVersion();
+ // Sort in reverse version order.
+ int cmp = middleVersion.compareTo(exports[i].getVersion());
+ if (cmp < 0)
+ {
+ bottom = middle - 1;
+ }
+ else if (cmp == 0)
+ {
+ // Sort further by ascending bundle ID.
+ long middleId = Util.getBundleIdFromModuleId(modules[middle].getId());
+ long exportId = Util.getBundleIdFromModuleId(module.getId());
+ if (middleId < exportId)
+ {
+ top = middle + 1;
+ }
+ else
+ {
+ bottom = middle - 1;
+ }
+ }
+ else
+ {
+ top = middle + 1;
+ }
+ }
+
+ IModule[] newMods = new IModule[modules.length + 1];
+ System.arraycopy(modules, 0, newMods, 0, top);
+ System.arraycopy(modules, top, newMods, top + 1, modules.length - top);
+ newMods[top] = module;
+ modules = newMods;
+ }
+
+ m_availPkgMap.put(exports[i].getName(), modules);
+ }
+ }
}
public void moduleRemoved(ModuleEvent event)
@@ -1472,7 +1373,7 @@
synchronized (m_factory)
{
// Remove exports from package maps.
- R4Export[] exports = getExports(event.getModule());
+ R4Export[] exports = event.getModule().getDefinition().getExports();
for (int i = 0; (exports != null) && (i < exports.length); i++)
{
// Remove from "available" package map.
@@ -1601,13 +1502,7 @@
private static class ModuleData
{
public IModule m_module = null;
- public R4Export[] m_exports = null;
- public R4Import[] m_imports = null;
- public R4Import[] m_dynamicImports = null;
- public R4Library[] m_libraries = null;
- public R4Wire[] m_wires = null;
public boolean m_resolved = false;
- public boolean m_removalPending = false;
public ModuleData(IModule module)
{
m_module = module;
@@ -1648,7 +1543,7 @@
long impId = Util.getBundleIdFromModuleId(module.getId());
// Next, check to see if the module imports the package.
- R4Wire[] wires = getWires(module);
+ IWire[] wires = module.getWires();
for (int i = 0; (wires != null) && (i < wires.length); i++)
{
if (wires[i].getExport().getName().equals(pkgName))
@@ -1656,7 +1551,7 @@
imported = true;
long expId = Util.getBundleIdFromModuleId(
- wires[i].getExportingModule().getId());
+ wires[i].getExporter().getId());
StringBuffer sb = new StringBuffer("****\n****\n");
sb.append("Package '");
@@ -1684,7 +1579,7 @@
// whether or not there is an exporter available.
if (!imported)
{
- R4Import[] imports = getImports(module);
+ R4Import[] imports = module.getDefinition().getImports();
for (int i = 0; (imports != null) && (i < imports.length); i++)
{
if (imports[i].getName().equals(pkgName) && imports[i].isOptional())
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
index 5f5e361..c630036 100755
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
@@ -21,7 +21,7 @@
import org.apache.felix.framework.util.Util;
import org.apache.felix.moduleloader.*;
-public class R4Wire
+public class R4Wire implements IWire
{
private IModule m_importer = null;
private IModule m_exporter = null;
@@ -34,21 +34,33 @@
m_export = export;
}
- public IModule getImportingModule()
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getImportingModule()
+ */
+ public IModule getImporter()
{
return m_importer;
}
- public IModule getExportingModule()
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getExportingModule()
+ */
+ public IModule getExporter()
{
return m_exporter;
}
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getExport()
+ */
public R4Export getExport()
{
return m_export;
}
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
+ */
public Class getClass(String name) throws ClassNotFoundException
{
Class clazz = null;
@@ -83,6 +95,9 @@
return clazz;
}
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getResource(java.lang.String)
+ */
public URL getResource(String name) throws ResourceNotFoundException
{
URL url = null;
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java
index a9ce699..7f443bc 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java
@@ -23,6 +23,7 @@
import org.apache.felix.framework.Logger;
import org.apache.felix.framework.searchpolicy.*;
import org.apache.felix.moduleloader.IModule;
+import org.apache.felix.moduleloader.IWire;
public class Util
{
@@ -190,8 +191,7 @@
public static R4Export getExportPackage(IModule m, String name)
{
- R4Export[] pkgs =
- ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getExports();
+ R4Export[] pkgs = m.getDefinition().getExports();
for (int i = 0; (pkgs != null) && (i < pkgs.length); i++)
{
if (pkgs[i].getName().equals(name))
@@ -204,8 +204,7 @@
public static R4Import getImportPackage(IModule m, String name)
{
- R4Import[] pkgs =
- ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getImports();
+ R4Import[] pkgs = m.getDefinition().getImports();
for (int i = 0; (pkgs != null) && (i < pkgs.length); i++)
{
if (pkgs[i].getName().equals(name))
@@ -216,10 +215,9 @@
return null;
}
- public static R4Wire getWire(IModule m, String name)
+ public static IWire getWire(IModule m, String name)
{
- R4Wire[] wires =
- ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getWires();
+ IWire[] wires = m.getWires();
for (int i = 0; (wires != null) && (i < wires.length); i++)
{
if (wires[i].getExport().getName().equals(name))
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java
index 84a6db6..bb14f76 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java
@@ -21,7 +21,11 @@
public interface IModule
{
public String getId();
+ public IModuleDefinition getDefinition();
public IContentLoader getContentLoader();
+ public IWire[] getWires();
+
+ public boolean isRemovalPending();
public Class getClass(String name);
public URL getResource(String name);
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java
new file mode 100644
index 0000000..b1b0c06
--- /dev/null
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.moduleloader;
+
+import org.apache.felix.framework.searchpolicy.*;
+
+public interface IModuleDefinition
+{
+ public R4Export[] getExports();
+ public R4Import[] getImports();
+ public R4Import[] getDynamicImports();
+ public R4Library[] getLibraries();
+}
\ No newline at end of file
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java
index a920baa..d59cd1b 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java
@@ -21,7 +21,7 @@
public IModule[] getModules();
public IModule getModule(String id);
- public IModule createModule(String id);
+ public IModule createModule(String id, IModuleDefinition md);
public void removeModule(IModule module);
public void setContentLoader(IModule module, IContentLoader contentLoader);
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java
new file mode 100644
index 0000000..f042946
--- /dev/null
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.moduleloader;
+
+import java.net.URL;
+
+import org.apache.felix.framework.searchpolicy.R4Export;
+
+public interface IWire
+{
+ public IModule getImporter();
+ public IModule getExporter();
+ public R4Export getExport();
+ public Class getClass(String name) throws ClassNotFoundException;
+ public URL getResource(String name) throws ResourceNotFoundException;
+}
\ No newline at end of file
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java
index 84cfd67..fbf8e9e 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java
@@ -45,7 +45,7 @@
return (IModule) m_moduleMap.get(id);
}
- public IModule createModule(String id)
+ public IModule createModule(String id, IModuleDefinition md)
{
IModule module = null;
@@ -55,7 +55,7 @@
{
if (m_moduleMap.get(id) == null)
{
- module = new ModuleImpl(m_logger, id);
+ module = new ModuleImpl(m_logger, id, md);
m_moduleMap.put(id, module);
}
else
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
index e7f6536..4786c52 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
@@ -24,12 +24,16 @@
{
private Logger m_logger = null;
private String m_id = null;
+ private boolean m_removalPending = false;
+ private IModuleDefinition m_md = null;
private IContentLoader m_contentLoader = null;
+ private IWire[] m_wires = null;
- ModuleImpl(Logger logger, String id)
+ ModuleImpl(Logger logger, String id, IModuleDefinition md)
{
m_logger = logger;
m_id = id;
+ m_md = md;
}
public String getId()
@@ -37,6 +41,11 @@
return m_id;
}
+ public IModuleDefinition getDefinition()
+ {
+ return m_md;
+ }
+
public IContentLoader getContentLoader()
{
return m_contentLoader;
@@ -47,6 +56,26 @@
m_contentLoader = contentLoader;
}
+ public IWire[] getWires()
+ {
+ return m_wires;
+ }
+
+ public void setWires(IWire[] wires)
+ {
+ m_wires = wires;
+ }
+
+ public boolean isRemovalPending()
+ {
+ return m_removalPending;
+ }
+
+ public void setRemovalPending(boolean removalPending)
+ {
+ m_removalPending = removalPending;
+ }
+
public Class getClass(String name)
{
try