Author: rickhall
Date: Wed Jan 20 16:44:13 2010
New Revision: 901272
URL: http://svn.apache.org/viewvc?rev=901272&view=rev
Log:
Break a lot more stuff.
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/Resolver.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolverStateImpl.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/StatefulResolver.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/ParsedHeaderClause.java
Removed:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/searchpolicy/
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/moduleloader/ICapability.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/moduleloader/IModule.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/moduleloader/IRequirement.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/moduleloader/IWire.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java
Modified:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/Util.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
Modified:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java?rev=901272&r1=901271&r2=901272&view=diff
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java
(original)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java
Wed Jan 20 16:44:13 2010
@@ -18,7 +18,6 @@
*/
package org.apache.felix.framework;
-import org.apache.felix.framework.searchpolicy.*;
import org.apache.felix.moduleloader.*;
import java.io.IOException;
import java.io.InputStream;
@@ -32,6 +31,7 @@
import java.security.SecureClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -42,15 +42,23 @@
import java.util.Vector;
import org.apache.felix.framework.Felix.FelixResolver;
import org.apache.felix.framework.cache.JarContent;
+import org.apache.felix.framework.candidateset.Attribute;
+import org.apache.felix.framework.candidateset.Capability;
+import org.apache.felix.framework.candidateset.Directive;
+import org.apache.felix.framework.candidateset.Module;
+import org.apache.felix.framework.candidateset.Requirement;
+import org.apache.felix.framework.candidateset.Wire;
+import org.apache.felix.framework.resolver.ResolveException;
+import org.apache.felix.framework.resolver.WireImpl;
import org.apache.felix.framework.util.CompoundEnumeration;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.framework.util.SecureAction;
import org.apache.felix.framework.util.SecurityManagerEx;
import org.apache.felix.framework.util.Util;
-import org.apache.felix.framework.util.manifestparser.Capability;
+import org.apache.felix.framework.util.manifestparser.CapabilityImpl;
import org.apache.felix.framework.util.manifestparser.ManifestParser;
import org.apache.felix.framework.util.manifestparser.R4Library;
-import org.apache.felix.framework.util.manifestparser.Requirement;
+import org.apache.felix.framework.util.manifestparser.RequirementImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleReference;
@@ -58,7 +66,7 @@
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
-public class ModuleImpl implements IModule
+public class ModuleImpl implements Module
{
private final Logger m_logger;
private final Map m_configMap;
@@ -73,24 +81,24 @@
private final String m_symbolicName;
private final Version m_version;
- private final ICapability[] m_capabilities;
- private ICapability[] m_cachedCapabilities = null;
- private final IRequirement[] m_requirements;
- private IRequirement[] m_cachedRequirements = null;
- private final IRequirement[] m_dynamicRequirements;
- private IRequirement[] m_cachedDynamicRequirements = null;
- private final R4Library[] m_nativeLibraries;
+ private final List<Capability> m_capabilities;
+ private List<Capability> m_cachedCapabilities = null;
+ private final List<Requirement> m_requirements;
+ private List<Requirement> m_cachedRequirements = null;
+ private final List<Requirement> m_dynamicRequirements;
+ private List<Requirement> m_cachedDynamicRequirements = null;
+ private final List<R4Library> m_nativeLibraries;
private final int m_declaredActivationPolicy;
- private final String[] m_activationIncludes;
- private final String[] m_activationExcludes;
+ private final List<String> m_activationIncludes;
+ private final List<String> m_activationExcludes;
private final Bundle m_bundle;
- private IModule[] m_fragments = null;
- private IWire[] m_wires = null;
- private IModule[] m_dependentHosts = new IModule[0];
- private IModule[] m_dependentImporters = new IModule[0];
- private IModule[] m_dependentRequirers = new IModule[0];
+ private List<Module> m_fragments = null;
+ private List<Wire> m_wires = null;
+ private List<Module> m_dependentHosts = new ArrayList<Module>(0);
+ private List<Module> m_dependentImporters = new ArrayList<Module>(0);
+ private List<Module> m_dependentRequirers = new ArrayList<Module>(0);
private volatile boolean m_isResolved = false;
private IContent[] m_contentPath;
@@ -252,110 +260,108 @@
return m_version;
}
- public synchronized ICapability[] getCapabilities()
+ public synchronized List<Capability> getCapabilities()
{
if (m_cachedCapabilities == null)
{
List capList = (m_capabilities == null)
- ? new ArrayList() : new
ArrayList(Arrays.asList(m_capabilities));
+ ? new ArrayList<Capability>()
+ : new ArrayList<Capability>(m_capabilities);
for (int fragIdx = 0;
- (m_fragments != null) && (fragIdx < m_fragments.length);
+ (m_fragments != null) && (fragIdx < m_fragments.size());
fragIdx++)
{
- ICapability[] caps = m_fragments[fragIdx].getCapabilities();
+ List<Capability> caps =
m_fragments.get(fragIdx).getCapabilities();
for (int capIdx = 0;
- (caps != null) && (capIdx < caps.length);
+ (caps != null) && (capIdx < caps.size());
capIdx++)
{
- if
(caps[capIdx].getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
+ if
(caps.get(capIdx).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
capList.add(
- new Capability(
+ new CapabilityImpl(
this,
- caps[capIdx].getNamespace(),
- ((Capability) caps[capIdx]).getDirectives(),
- ((Capability) caps[capIdx]).getAttributes()));
+ caps.get(capIdx).getNamespace(),
+ caps.get(capIdx).getDirectives(),
+ caps.get(capIdx).getAttributes()));
}
}
}
- m_cachedCapabilities = (ICapability[])
- capList.toArray(new ICapability[capList.size()]);
+ m_cachedCapabilities = Collections.unmodifiableList(capList);
}
return m_cachedCapabilities;
}
- public synchronized IRequirement[] getRequirements()
+ public synchronized List<Requirement> getRequirements()
{
if (m_cachedRequirements == null)
{
- List reqList = (m_requirements == null)
+ List<Requirement> reqList = (m_requirements == null)
? new ArrayList() : new
ArrayList(Arrays.asList(m_requirements));
for (int fragIdx = 0;
- (m_fragments != null) && (fragIdx < m_fragments.length);
+ (m_fragments != null) && (fragIdx < m_fragments.size());
fragIdx++)
{
- IRequirement[] reqs = m_fragments[fragIdx].getRequirements();
+ List<Requirement> reqs =
m_fragments.get(fragIdx).getRequirements();
for (int reqIdx = 0;
- (reqs != null) && (reqIdx < reqs.length);
+ (reqs != null) && (reqIdx < reqs.size());
reqIdx++)
{
- if
(reqs[reqIdx].getNamespace().equals(ICapability.PACKAGE_NAMESPACE)
- ||
reqs[reqIdx].getNamespace().equals(ICapability.MODULE_NAMESPACE))
+ if
(reqs.get(reqIdx).getNamespace().equals(Capability.PACKAGE_NAMESPACE)
+ ||
reqs.get(reqIdx).getNamespace().equals(Capability.MODULE_NAMESPACE))
{
- reqList.add(reqs[reqIdx]);
+ reqList.add(reqs.get(reqIdx));
}
}
}
- m_cachedRequirements = (IRequirement[])
- reqList.toArray(new IRequirement[reqList.size()]);
+ m_cachedRequirements = Collections.unmodifiableList(reqList);
}
return m_cachedRequirements;
}
- public synchronized IRequirement[] getDynamicRequirements()
+ public synchronized List<Requirement> getDynamicRequirements()
{
if (m_cachedDynamicRequirements == null)
{
- List reqList = (m_dynamicRequirements == null)
+ List<Requirement> reqList = (m_dynamicRequirements == null)
? new ArrayList() : new
ArrayList(Arrays.asList(m_dynamicRequirements));
for (int fragIdx = 0;
- (m_fragments != null) && (fragIdx < m_fragments.length);
+ (m_fragments != null) && (fragIdx < m_fragments.size());
fragIdx++)
{
- IRequirement[] reqs =
m_fragments[fragIdx].getDynamicRequirements();
+ List<Requirement> reqs =
m_fragments.get(fragIdx).getDynamicRequirements();
for (int reqIdx = 0;
- (reqs != null) && (reqIdx < reqs.length);
+ (reqs != null) && (reqIdx < reqs.size());
reqIdx++)
{
- if
(reqs[reqIdx].getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
+ if
(reqs.get(reqIdx).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
- reqList.add(reqs[reqIdx]);
+ reqList.add(reqs.get(reqIdx));
}
}
}
- m_cachedDynamicRequirements = (IRequirement[])
- reqList.toArray(new IRequirement[reqList.size()]);
+ m_cachedDynamicRequirements =
Collections.unmodifiableList(reqList);
}
return m_cachedDynamicRequirements;
}
- public synchronized R4Library[] getNativeLibraries()
+ public synchronized List<R4Library> getNativeLibraries()
{
- R4Library[] result = null;
+ List<R4Library> result = null;
if (m_isResolved)
{
- List nativeList = (m_nativeLibraries == null)
+ List<R4Library> nativeList = (m_nativeLibraries == null)
? new ArrayList() : new
ArrayList(Arrays.asList(m_nativeLibraries));
for (int fragIdx = 0;
- (m_fragments != null) && (fragIdx < m_fragments.length);
+ (m_fragments != null) && (fragIdx < m_fragments.size());
fragIdx++)
{
- R4Library[] libs = m_fragments[fragIdx].getNativeLibraries();
+ List<R4Library> libs =
m_fragments.get(fragIdx).getNativeLibraries();
for (int reqIdx = 0;
- (libs != null) && (reqIdx < libs.length);
+ (libs != null) && (reqIdx < libs.size());
reqIdx++)
{
- nativeList.add(libs[reqIdx]);
+ nativeList.add(libs.get(reqIdx));
}
}
@@ -364,7 +370,7 @@
// could not be found when resolving the bundle.
result = (nativeList.size() == 0)
? null
- : (R4Library[]) nativeList.toArray(new
R4Library[nativeList.size()]);
+ : Collections.unmodifiableList(nativeList);
}
else
{
@@ -395,20 +401,20 @@
// by default, otherwise try to find one match.
boolean included = (m_activationIncludes == null);
for (int i = 0;
- (!included) && (m_activationIncludes != null) && (i <
m_activationIncludes.length);
+ (!included) && (m_activationIncludes != null) && (i <
m_activationIncludes.size());
i++)
{
- included = m_activationIncludes[i].equals(pkgName);
+ included = m_activationIncludes.get(i).equals(pkgName);
}
// If there are no exclude filters then no classes are excluded
// by default, otherwise try to find one match.
boolean excluded = false;
for (int i = 0;
- (!excluded) && (m_activationExcludes != null) && (i <
m_activationExcludes.length);
+ (!excluded) && (m_activationExcludes != null) && (i <
m_activationExcludes.size());
i++)
{
- excluded = m_activationExcludes[i].equals(pkgName);
+ excluded = m_activationExcludes.get(i).equals(pkgName);
}
return included && !excluded;
}
@@ -427,40 +433,40 @@
return m_id;
}
- public synchronized IWire[] getWires()
+ public synchronized List<Wire> getWires()
{
return m_wires;
}
- public synchronized void setWires(IWire[] wires)
+ public synchronized void setWires(List<Wire> wires)
{
// Remove module from old wire modules' dependencies,
// since we are no longer dependent on any the moduels
// from the old wires.
- for (int i = 0; (m_wires != null) && (i < m_wires.length); i++)
+ for (int i = 0; (m_wires != null) && (i < m_wires.size()); i++)
{
- if
(m_wires[i].getCapability().getNamespace().equals(ICapability.MODULE_NAMESPACE))
+ if
(m_wires.get(i).getCapability().getNamespace().equals(Capability.MODULE_NAMESPACE))
{
- ((ModuleImpl)
m_wires[i].getExporter()).removeDependentRequirer(this);
+ ((ModuleImpl)
m_wires.get(i).getExporter()).removeDependentRequirer(this);
}
- else if
(m_wires[i].getCapability().getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
+ else if
(m_wires.get(i).getCapability().getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
- ((ModuleImpl)
m_wires[i].getExporter()).removeDependentImporter(this);
+ ((ModuleImpl)
m_wires.get(i).getExporter()).removeDependentImporter(this);
}
}
m_wires = wires;
// Add ourself as a dependent to the new wires' modules.
- for (int i = 0; (m_wires != null) && (i < m_wires.length); i++)
+ for (int i = 0; (m_wires != null) && (i < m_wires.size()); i++)
{
- if
(m_wires[i].getCapability().getNamespace().equals(ICapability.MODULE_NAMESPACE))
+ if
(m_wires.get(i).getCapability().getNamespace().equals(Capability.MODULE_NAMESPACE))
{
- ((ModuleImpl)
m_wires[i].getExporter()).addDependentRequirer(this);
+ ((ModuleImpl)
m_wires.get(i).getExporter()).addDependentRequirer(this);
}
- else if
(m_wires[i].getCapability().getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
+ else if
(m_wires.get(i).getCapability().getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
- ((ModuleImpl)
m_wires[i].getExporter()).addDependentImporter(this);
+ ((ModuleImpl)
m_wires.get(i).getExporter()).addDependentImporter(this);
}
}
}
@@ -506,13 +512,13 @@
calculateContentPath(this, m_content, contentList, true);
for (int i = 0; (m_fragmentContents != null) && (i <
m_fragmentContents.length); i++)
{
- calculateContentPath(m_fragments[i], m_fragmentContents[i],
contentList, false);
+ calculateContentPath(m_fragments.get(i), m_fragmentContents[i],
contentList, false);
}
return (IContent[]) contentList.toArray(new
IContent[contentList.size()]);
}
private List calculateContentPath(
- IModule module, IContent content, List contentList, boolean
searchFragments)
+ Module module, IContent content, List contentList, boolean
searchFragments)
throws Exception
{
// Creating the content path entails examining the bundle's
@@ -526,25 +532,25 @@
// Find class path meta-data.
String classPath = (String)
module.getHeaders().get(FelixConstants.BUNDLE_CLASSPATH);
// Parse the class path into strings.
- String[] classPathStrings = ManifestParser.parseDelimitedString(
+ List<String> classPathStrings = ManifestParser.parseDelimitedString(
classPath, FelixConstants.CLASS_PATH_SEPARATOR);
if (classPathStrings == null)
{
- classPathStrings = new String[0];
+ classPathStrings = new ArrayList<String>(0);
}
// Create the bundles class path.
- for (int i = 0; i < classPathStrings.length; i++)
+ for (int i = 0; i < classPathStrings.size(); i++)
{
// Remove any leading slash, since all bundle class path
// entries are relative to the root of the bundle.
- classPathStrings[i] = (classPathStrings[i].startsWith("/"))
- ? classPathStrings[i].substring(1)
- : classPathStrings[i];
+ classPathStrings.set(i, (classPathStrings.get(i).startsWith("/"))
+ ? classPathStrings.get(i).substring(1)
+ : classPathStrings.get(i));
// Check for the bundle itself on the class path.
- if (classPathStrings[i].equals(FelixConstants.CLASS_PATH_DOT))
+ if (classPathStrings.get(i).equals(FelixConstants.CLASS_PATH_DOT))
{
localContentList.add(content);
}
@@ -552,7 +558,7 @@
{
// Try to find the embedded class path entry in the current
// content.
- IContent embeddedContent =
content.getEntryAsContent(classPathStrings[i]);
+ IContent embeddedContent =
content.getEntryAsContent(classPathStrings.get(i));
// If the embedded class path entry was not found, it might be
// in one of the fragments if the current content is the
bundle,
// so try to search the fragments if necessary.
@@ -561,7 +567,8 @@
&& (m_fragmentContents != null) && (fragIdx <
m_fragmentContents.length);
fragIdx++)
{
- embeddedContent =
m_fragmentContents[fragIdx].getEntryAsContent(classPathStrings[i]);
+ embeddedContent =
+
m_fragmentContents[fragIdx].getEntryAsContent(classPathStrings.get(i));
}
// If we found the embedded content, then add it to the
// class path content list.
@@ -575,7 +582,7 @@
// need to create an "Eventer" class like "Logger" perhaps.
m_logger.log(Logger.LOG_INFO,
"Class path entry not found: "
- + classPathStrings[i]);
+ + classPathStrings.get(i));
}
}
}
@@ -866,15 +873,15 @@
// Note that the search may be aborted if this method throws an
// exception, otherwise it continues if a null is returned.
- IWire[] wires = getWires();
- for (int i = 0; (wires != null) && (i < wires.length); i++)
+ List<Wire> wires = getWires();
+ for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
- if (wires[i] instanceof R4Wire)
+ if (wires.get(i) instanceof WireImpl)
{
try
{
// If we find the class or resource, then return it.
- urls = wires[i].getResources(name);
+ urls = wires.get(i).getResources(name);
}
catch (ResourceNotFoundException ex)
{
@@ -892,14 +899,14 @@
// See whether we can get the resource from the required bundles and
// regardless of whether or not this is the case continue to the next
// step potentially passing on the result of this search (if any).
- for (int i = 0; (wires != null) && (i < wires.length); i++)
+ for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
- if (wires[i] instanceof R4WireModule)
+ if (wires.get(i) instanceof WireModuleImpl)
{
try
{
// If we find the class or resource, then add it.
- urls = wires[i].getResources(name);
+ urls = wires.get(i).getResources(name);
}
catch (ResourceNotFoundException ex)
{
@@ -926,7 +933,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.
- IWire wire = null;
+ Wire wire = null;
try
{
wire = m_resolver.resolveDynamicImport(this, pkgName);
@@ -1087,19 +1094,19 @@
// Fragment and dependency management methods.
//
- public synchronized IModule[] getFragments()
+ public synchronized List<Module> getFragments()
{
return m_fragments;
}
- public synchronized void attachFragments(IModule[] fragments) throws
Exception
+ public synchronized void attachFragments(List<Module> fragments) throws
Exception
{
// Remove module from old fragment dependencies.
// We will generally only remove module fragment
// dependencies when we are uninstalling the module.
- for (int i = 0; (m_fragments != null) && (i < m_fragments.length); i++)
+ for (int i = 0; (m_fragments != null) && (i < m_fragments.size()); i++)
{
- ((ModuleImpl) m_fragments[i]).removeDependentHost(this);
+ ((ModuleImpl) m_fragments.get(i)).removeDependentHost(this);
}
// Remove cached capabilities and requirements.
@@ -1115,12 +1122,12 @@
// to attach to our content loader.
if (m_fragments != null)
{
- IContent[] fragmentContents = new IContent[m_fragments.length];
- for (int i = 0; (m_fragments != null) && (i < m_fragments.length);
i++)
+ IContent[] fragmentContents = new IContent[m_fragments.size()];
+ for (int i = 0; (m_fragments != null) && (i < m_fragments.size());
i++)
{
- ((ModuleImpl) m_fragments[i]).addDependentHost(this);
+ ((ModuleImpl) m_fragments.get(i)).addDependentHost(this);
fragmentContents[i] =
- m_fragments[i].getContent()
+ m_fragments.get(i).getContent()
.getEntryAsContent(FelixConstants.CLASS_PATH_DOT);
}
// Now attach the fragment contents to our content loader.
@@ -1152,121 +1159,68 @@
m_contentPath = initializeContentPath();
}
- public synchronized IModule[] getDependentHosts()
+ public synchronized List<Module> getDependentHosts()
{
return m_dependentHosts;
}
- public synchronized void addDependentHost(IModule module)
+ public synchronized void addDependentHost(Module module)
{
- m_dependentHosts = addDependent(m_dependentHosts, module);
+ if (!m_dependentHosts.contains(module))
+ {
+ m_dependentHosts.add(module);
+ }
}
- public synchronized void removeDependentHost(IModule module)
+ public synchronized void removeDependentHost(Module module)
{
- m_dependentHosts = removeDependent(m_dependentHosts, module);
+ m_dependentHosts.remove(module);
}
- public synchronized IModule[] getDependentImporters()
+ public synchronized List<Module> getDependentImporters()
{
return m_dependentImporters;
}
- public synchronized void addDependentImporter(IModule module)
+ public synchronized void addDependentImporter(Module module)
{
- m_dependentImporters = addDependent(m_dependentImporters, module);
+ if (!m_dependentImporters.contains(module))
+ {
+ m_dependentImporters.add(module);
+ }
}
- public synchronized void removeDependentImporter(IModule module)
+ public synchronized void removeDependentImporter(Module module)
{
- m_dependentImporters = removeDependent(m_dependentImporters, module);
+ m_dependentImporters.remove(module);
}
- public synchronized IModule[] getDependentRequirers()
+ public synchronized List<Module> getDependentRequirers()
{
return m_dependentRequirers;
}
- public synchronized void addDependentRequirer(IModule module)
- {
- m_dependentRequirers = addDependent(m_dependentRequirers, module);
- }
-
- public synchronized void removeDependentRequirer(IModule module)
+ public synchronized void addDependentRequirer(Module module)
{
- m_dependentRequirers = removeDependent(m_dependentRequirers, module);
- }
-
- public synchronized IModule[] getDependents()
- {
- IModule[] dependents = new IModule[
- m_dependentHosts.length + m_dependentImporters.length +
m_dependentRequirers.length];
- System.arraycopy(
- m_dependentHosts,
- 0,
- dependents,
- 0,
- m_dependentHosts.length);
- System.arraycopy(
- m_dependentImporters,
- 0,
- dependents,
- m_dependentHosts.length,
- m_dependentImporters.length);
- System.arraycopy(
- m_dependentRequirers,
- 0,
- dependents,
- m_dependentHosts.length + m_dependentImporters.length,
- m_dependentRequirers.length);
- return dependents;
- }
-
- private static IModule[] addDependent(IModule[] modules, IModule module)
- {
- // Make sure the dependent module is not already present.
- for (int i = 0; i < modules.length; i++)
+ if (!m_dependentRequirers.contains(module))
{
- if (modules[i].equals(module))
- {
- return modules;
- }
+ m_dependentRequirers.add(module);
}
- IModule[] tmp = new IModule[modules.length + 1];
- System.arraycopy(modules, 0, tmp, 0, modules.length);
- tmp[modules.length] = module;
- return tmp;
}
- private static IModule[] removeDependent(IModule[] modules, IModule module)
+ public synchronized void removeDependentRequirer(Module module)
{
- IModule[] tmp = modules;
-
- // Make sure the dependent module is present.
- for (int i = 0; i < modules.length; i++)
- {
- if (modules[i].equals(module))
- {
- // If this is the module, then point to empty list.
- if ((modules.length - 1) == 0)
- {
- tmp = new IModule[0];
- }
- // Otherwise, we need to do some array copying.
- else
- {
- tmp = new IModule[modules.length - 1];
- System.arraycopy(modules, 0, tmp, 0, i);
- if (i < tmp.length)
- {
- System.arraycopy(modules, i + 1, tmp, i, tmp.length -
i);
- }
- }
- break;
- }
- }
+ m_dependentRequirers.remove(module);
+ }
- return tmp;
+ public synchronized List<Module> getDependents()
+ {
+ List<Module> dependents = new ArrayList<Module>
+ (m_dependentHosts.size() + m_dependentImporters.size() +
m_dependentRequirers.size());
+ dependents.addAll(m_dependentHosts);
+ dependents.addAll(m_dependentImporters);
+ dependents.addAll(m_dependentRequirers);
+ return dependents;
}
public synchronized void close()
@@ -1363,13 +1317,13 @@
throws ClassNotFoundException, ResourceNotFoundException
{
// We delegate to the module's wires to find the class or resource.
- IWire[] wires = getWires();
- for (int i = 0; (wires != null) && (i < wires.length); i++)
+ List<Wire> wires = getWires();
+ for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
// If we find the class or resource, then return it.
Object result = (isClass)
- ? (Object) wires[i].getClass(name)
- : (Object) wires[i].getResource(name);
+ ? (Object) wires.get(i).getClass(name)
+ : (Object) wires.get(i).getResource(name);
if (result != null)
{
return result;
@@ -1722,7 +1676,7 @@
int activationPolicy =
((BundleImpl)
getBundle()).isDeclaredActivationPolicyUsed()
? ((BundleImpl)
getBundle()).getCurrentModule().getDeclaredActivationPolicy()
- : IModule.EAGER_ACTIVATION;
+ : Module.EAGER_ACTIVATION;
// If the module is using deferred activation,
then if
// we load this class from this module we need to
activate
@@ -1733,7 +1687,7 @@
? false : isActivationTrigger(pkgName);
if (!m_isActivationTriggered
&& isTriggerClass
- && (activationPolicy ==
IModule.LAZY_ACTIVATION)
+ && (activationPolicy == Module.LAZY_ACTIVATION)
&& (getBundle().getState() == Bundle.STARTING))
{
List deferredList = (List)
m_deferredActivation.get();
@@ -2007,13 +1961,13 @@
String importer = module.getBundle().toString();
// Next, check to see if the module imports the package.
- IWire[] wires = module.getWires();
- for (int i = 0; (wires != null) && (i < wires.length); i++)
+ List<Wire> wires = module.getWires();
+ for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
- if
(wires[i].getCapability().getNamespace().equals(ICapability.PACKAGE_NAMESPACE)
&&
-
wires[i].getCapability().getProperties().get(ICapability.PACKAGE_PROPERTY).equals(pkgName))
+ if
(wires.get(i).getCapability().getNamespace().equals(Capability.PACKAGE_NAMESPACE)
&&
+
wires.get(i).getCapability().getAttribute(Capability.PACKAGE_ATTR).getValue().equals(pkgName))
{
- String exporter =
wires[i].getExporter().getBundle().toString();
+ String exporter =
wires.get(i).getExporter().getBundle().toString();
StringBuffer sb = new StringBuffer("*** Package '");
sb.append(pkgName);
@@ -2037,7 +1991,7 @@
// Next, check to see if the package was optionally imported and
// whether or not there is an exporter available.
- IRequirement[] reqs = module.getRequirements();
+ List<Requirement> reqs = module.getRequirements();
/*
* TODO: RB - Fix diagnostic message for optional imports.
for (int i = 0; (reqs != null) && (i < reqs.length); i++)
@@ -2097,7 +2051,9 @@
}
*/
// Next, check to see if the package is dynamically imported by the
module.
- IRequirement pkgReq = Resolver.findAllowedDynamicImport(module,
pkgName);
+// TODO: FELIX3 - Add Resolver.findAllowedDynamicImport().
+/*
+ Requirement pkgReq = Resolver.findAllowedDynamicImport(module,
pkgName);
if (pkgReq != null)
{
// Try to see if there is an exporter available.
@@ -2151,18 +2107,15 @@
return sb.toString();
}
-
+*/
// Next, check to see if there are any exporters for the package at
all.
- pkgReq = null;
- try
- {
- pkgReq = new Requirement(ICapability.PACKAGE_NAMESPACE,
"(package=" + pkgName + ")");
- }
- catch (InvalidSyntaxException ex)
- {
- // This should never happen.
- }
- List exports =
+ Requirement pkgReq = null;
+ List<Attribute> attrs = new ArrayList(1);
+ attrs.add(new Attribute(Capability.PACKAGE_ATTR, pkgName, false));
+ pkgReq = new RequirementImpl(
+ Capability.PACKAGE_NAMESPACE,
+ new ArrayList<Directive>(0), attrs);
+ List<Capability> exports =
resolver.getResolvedCandidates(pkgReq, module);
exports = (exports.size() == 0)
? resolver.getUnresolvedCandidates(pkgReq, module)
@@ -2184,7 +2137,7 @@
// Ignore
}
- String exporter = ((ICapability)
exports.get(0)).getModule().getBundle().toString();
+ String exporter =
exports.get(0).getModule().getBundle().toString();
StringBuffer sb = new StringBuffer("*** Class '");
sb.append(name);
Modified:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java?rev=901272&r1=901271&r2=901272&view=diff
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java
(original)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java
Wed Jan 20 16:44:13 2010
@@ -18,16 +18,59 @@
*/
package org.apache.felix.framework.candidateset;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
import java.util.List;
+import java.util.Map;
+import org.apache.felix.framework.util.manifestparser.R4Library;
+import org.apache.felix.moduleloader.IContent;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
public interface Module
{
final static int EAGER_ACTIVATION = 0;
final static int LAZY_ACTIVATION = 1;
- String getName();
+ // Metadata access methods.
+ Map getHeaders();
+ boolean isExtension();
+ String getSymbolicName();
+ Version getVersion();
List<Capability> getCapabilities();
List<Requirement> getRequirements();
- boolean isResolved();
+ List<Requirement> getDynamicRequirements();
+ List<R4Library> getNativeLibraries();
+ int getDeclaredActivationPolicy();
+
+ // Run-time data access methods.
+ Bundle getBundle();
+ String getId();
List<Wire> getWires();
+ boolean isResolved();
+ // TODO: FELIX3 - Shouldn't have mutable method on Module.
+ void setSecurityContext(Object securityContext);
+ Object getSecurityContext();
+
+ // Content access methods.
+ IContent getContent();
+ Class getClassByDelegation(String name) throws ClassNotFoundException;
+ URL getResourceByDelegation(String name);
+ Enumeration getResourcesByDelegation(String name);
+ URL getEntry(String name);
+
+ // TODO: ML - For expediency, the index argument was added to these methods
+ // but it is not clear that this makes sense in the long run. This needs to
+ // be readdressed in the future, perhaps by the spec to clearly indicate
+ // how resources on the bundle class path are searched, which is why we
+ // need the index number in the first place -- to differentiate among
+ // resources with the same name on the bundle class path. This was
previously
+ // handled as part of the resource path, but that approach is not spec
+ // compliant.
+ boolean hasInputStream(int index, String urlPath)
+ throws IOException;
+ InputStream getInputStream(int index, String urlPath)
+ throws IOException;
}
\ No newline at end of file
Modified:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java?rev=901272&r1=901271&r2=901272&view=diff
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java
(original)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java
Wed Jan 20 16:44:13 2010
@@ -18,10 +18,82 @@
*/
package org.apache.felix.framework.candidateset;
+import java.net.URL;
+import java.util.Enumeration;
+import org.apache.felix.moduleloader.ResourceNotFoundException;
+
public interface Wire
{
- Module getImporter();
- Requirement getRequirement();
- Module getExporter();
- Capability getCapability();
+ /**
+ * Returns the importing module.
+ * @return The importing module.
+ **/
+ public Module getImporter();
+ /**
+ * Returns the associated requirement from the importing module that
+ * resulted in the creation of this wire.
+ * @return
+ **/
+ public Requirement getRequirement();
+ /**
+ * Returns the exporting module.
+ * @return The exporting module.
+ **/
+ public Module getExporter();
+ /**
+ * Returns the associated capability from the exporting module that
+ * satisfies the requirement of the importing module.
+ * @return
+ **/
+ public Capability getCapability();
+ /**
+ * Returns whether or not the wire has a given package name. For some
+ * wires, such as ones for Require-Bundle, there may be many packages.
+ * This method is necessary since the set of packages attained by wires
+ * restrict which packages can be dynamically imported (i.e., you cannot
+ * dynamically import a package that is already attainable from an
+ * existing wire).
+ * @return <tt>true</tt> if the package name is attainable from this wire,
+ * <tt>false</tt> otherwise.
+ **/
+ public boolean hasPackage(String pkgName);
+ /**
+ * Requests a class from the exporting module. If the class is found, then
+ * it is returned. If the class is not found, then this method may or may
+ * not throw an exception depending on the wire type (e.g., for an
+ * imported package or a required bundle). Throwing an exception indicates
+ * that the search should be aborted, while returning a <tt>null</tt>
+ * indicates that the search should continue.
+ * @return The class if found or <tt>null</tt> if not found and the search
+ * should continue.
+ * @throws java.lang.ClassNotFoundException If the class was not found and
+ * the search should be aborted.
+ **/
+ public Class getClass(String name) throws ClassNotFoundException;
+ /**
+ * Requests a resource from the exporting module. If the resource is found,
+ * then an URL is returned. If the resource is not found, then this method
may
+ * or may not throw an exception depending on the wire type (e.g., for an
+ * imported package or a required bundle). Throwing an exception indicates
+ * that the search should be aborted, while returning a <tt>null</tt>
+ * indicates that the search should continue.
+ * @return An URL to the resource if found or <tt>null</tt> if not found
+ * and the search should continue.
+ * @throws ResourceNotFoundException If the resource was not found and
+ * the search should be aborted.
+ **/
+ public URL getResource(String name) throws ResourceNotFoundException;
+ /**
+ * Requests resources from the exporting module. If the resources are
found,
+ * then an enumeration of URLs is returned. If the resources are not found,
+ * then this method may or may not throw an exception depending on the wire
+ * type (e.g., for an imported package or a required bundle). Throwing an
+ * exception indicates that the search should be aborted, while returning a
+ * <tt>null</tt> indicates that the search should continue.
+ * @return An enumeration of URLs for the resource if found or
<tt>null</tt>
+ * if not found and the search should continue.
+ * @throws ResourceNotFoundException If the resource was not found and
+ * the search should be aborted.
+ **/
+ public Enumeration getResources(String name) throws
ResourceNotFoundException;
}
\ No newline at end of file
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java?rev=901272&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
Wed Jan 20 16:44:13 2010
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.resolver;
+
+import java.util.Comparator;
+import org.apache.felix.resolver.cs.Capability;
+import org.apache.felix.resolver.manifestparser.Constants;
+
+public class CandidateComparator implements Comparator
+{
+ public int compare(Object arg1, Object arg2)
+ {
+ Capability cap1 = (Capability) arg1;
+ Capability cap2 = (Capability) arg2;
+
+ // First check resolved state, since resolved capabilities have
priority
+ // over unresolved ones. Compare in reverse order since we want to sort
+ // in descending order.
+ int c = 0;
+ if (cap1.getModule().isResolved() && !cap2.getModule().isResolved())
+ {
+ c = -1;
+ }
+ else if (!cap1.getModule().isResolved() &&
cap2.getModule().isResolved())
+ {
+ c = 1;
+ }
+
+ // Next compare version numbers.
+ if ((c == 0) &&
cap1.getNamespace().equals(Capability.MODULE_NAMESPACE))
+ {
+ c = ((Comparable)
cap1.getAttribute(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE)
+
.getValue()).compareTo(cap2.getAttribute(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE)
+ .getValue());
+ if (c == 0)
+ {
+ Version v1 =
(cap1.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE) == null)
+ ? Version.emptyVersion
+ : (Version)
cap1.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE).getValue();
+ Version v2 =
(cap2.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE) == null)
+ ? Version.emptyVersion
+ : (Version)
cap2.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE).getValue();
+ // Compare these in reverse order, since we want
+ // highest version to have priority.
+ c = v2.compareTo(v1);
+ }
+ }
+// TODO: PROTO3 RESOLVER - Need to change this to handle arbitrary capabilities
+// that may not have a natural ordering.
+ // Assume everything else is a package capability.
+ else if (c == 0)
+ {
+ c = ((Comparable)
cap1.getAttribute(Capability.PACKAGE_ATTR).getValue())
+
.compareTo(cap2.getAttribute(Capability.PACKAGE_ATTR).getValue());
+ if (c == 0)
+ {
+ Version v1 = (cap1.getAttribute(Capability.VERSION_ATTR) ==
null)
+ ? Version.emptyVersion
+ : (Version)
cap1.getAttribute(Capability.VERSION_ATTR).getValue();
+ Version v2 = (cap2.getAttribute(Capability.VERSION_ATTR) ==
null)
+ ? Version.emptyVersion
+ : (Version)
cap2.getAttribute(Capability.VERSION_ATTR).getValue();
+ // Compare these in reverse order, since we want
+ // highest version to have priority.
+ c = v2.compareTo(v1);
+ }
+ }
+
+ // Finally, compare module identity.
+ if (c == 0)
+ {
+ c =
cap1.getModule().getName().compareTo(cap2.getModule().getName());
+ }
+
+ return c;
+ }
+}
\ No newline at end of file
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolveException.java?rev=901272&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
Wed Jan 20 16:44:13 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.resolver;
+
+import org.apache.felix.framework.candidateset.Module;
+import org.apache.felix.framework.candidateset.Requirement;
+
+public class ResolveException extends RuntimeException
+{
+ private final Module m_module;
+ private final Requirement m_req;
+
+ /**
+ * Constructs an instance of <code>ResolveException</code> with the
specified detail message.
+ * @param msg the detail message.
+ */
+ public ResolveException(String msg, Module module, Requirement req)
+ {
+ super(msg);
+ m_module = module;
+ m_req = req;
+ }
+
+ public Module getModule()
+ {
+ return m_module;
+ }
+
+ public Requirement getRequirement()
+ {
+ return m_req;
+ }
+}
\ No newline at end of file
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/Resolver.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/Resolver.java?rev=901272&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/Resolver.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/Resolver.java
Wed Jan 20 16:44:13 2010
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.resolver;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.felix.resolver.cs.Capability;
+import org.apache.felix.resolver.cs.Requirement;
+
+public interface Resolver
+{
+ Map<Module, List<Wire>> resolve(ResolverState state, Module module);
+
+ public static interface ResolverState
+ {
+ Set<Capability> getCandidates(Module module, Requirement req);
+ }
+}
\ No newline at end of file