felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r441518 [1/3] - in /incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix: framework/ framework/searchpolicy/ framework/util/ framework/util/ldap/ moduleloader/
Date Fri, 08 Sep 2006 14:36:58 GMT
Author: rickhall
Date: Fri Sep  8 07:36:56 2006
New Revision: 441518

URL: http://svn.apache.org/viewvc?view=rev&rev=441518
Log:
This is a reasonably large set of changes that is experimenting with making
the resolver use a more generic capability/requirement model, such as the
one used by OBR. The goal here is to use such an approach as the basis for
implementing require-bundle functionality. These changes are still pretty
rough, but they do pass the same 11 TCK test suites that the trunk passes. I
do believe, however, that it fails some additional cases in some of the test
suites where the trunk fails. The main point of these changes is to see
if the approach is feasible for the trunk.

Added:
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ExportCapability.java
  (with props)
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ImportRequirement.java
  (with props)
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/Requirement.java
  (with props)
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ICapability.java
  (with props)
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IRequirement.java
  (with props)
Removed:
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Export.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Import.java
Modified:
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/
  (props changed)
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/SystemBundle.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/
  (props changed)
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveException.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/VersionRange.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/
  (props changed)
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/ManifestParser.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/ldap/Parser.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/
  (props changed)
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java
    incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java

Propchange: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Sep  8 07:36:56 2006
@@ -0,0 +1,4 @@
+Main.java~
+ExportedPackageImpl.java~
+Felix.java~
+SystemBundle.java~

Modified: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java?view=diff&rev=441518&r1=441517&r2=441518
==============================================================================
--- incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
(original)
+++ incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
Fri Sep  8 07:36:56 2006
@@ -16,7 +16,7 @@
  */
 package org.apache.felix.framework;
 
-import org.apache.felix.framework.searchpolicy.R4Export;
+import org.apache.felix.framework.searchpolicy.R4ExportCapability;
 import org.apache.felix.moduleloader.IModule;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Version;
@@ -27,12 +27,12 @@
     private Felix m_felix = null;
     private BundleImpl m_exportingBundle = null;
     private IModule m_exportingModule = null;
-    private R4Export m_export = null;
+    private R4ExportCapability m_export = null;
     private String m_toString = null;
     private String m_versionString = null;
 
     public ExportedPackageImpl(
-        Felix felix, BundleImpl exporter, IModule module, R4Export export)
+        Felix felix, BundleImpl exporter, IModule module, R4ExportCapability export)
     {
         m_felix = felix;
         m_exportingBundle = exporter;

Modified: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java?view=diff&rev=441518&r1=441517&r2=441518
==============================================================================
--- incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
(original)
+++ incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
Fri Sep  8 07:36:56 2006
@@ -365,7 +365,7 @@
                 // This should never happen.
                 throw new BundleException(
                         "Unresolved package in System Bundle:"
-                        + ex.getPackage());
+                        + ex.getRequirement());
             }
 
             // Start the system bundle; this will set its state
@@ -1312,7 +1312,7 @@
                 throw new BundleException(
                     "Unresolved package in bundle "
                     + Util.getBundleIdFromModuleId(ex.getModule().getId())
-                    + ": " + ex.getPackage());
+                    + ": " + ex.getRequirement());
             }
             else
             {
@@ -2242,7 +2242,8 @@
     {
         // First, get all exporters of the package.
         ExportedPackage[] pkgs = null;
-        IModule[] exporters = m_policyCore.getInUseExporters(new R4Import(name, null, null),
true);
+        R4SearchPolicyCore.ResolverCandidate[] exporters =
+            m_policyCore.getInUseCandidates(new R4ImportRequirement(name, null, null), true);
         if (exporters != null)
         {
             pkgs = new ExportedPackage[exporters.length];
@@ -2250,7 +2251,7 @@
             {
                 // Get the bundle associated with the current exporting module.
                 BundleImpl bundle = (BundleImpl) getBundle(
-                    Util.getBundleIdFromModuleId(exporters[pkgIdx].getId()));
+                    Util.getBundleIdFromModuleId(exporters[pkgIdx].m_module.getId()));
 
                 // We need to find the version of the exported package, but this
                 // is tricky since there may be multiple versions of the package
@@ -2265,12 +2266,22 @@
                 IModule[] modules = bundle.getInfo().getModules();
                 for (int modIdx = 0; modIdx < modules.length; modIdx++)
                 {
-                    R4Export export = Util.getExportPackage(modules[modIdx], name);
-                    if (export != null)
+                    R4ExportCapability ec = null;
+                    try
+                    {
+                        ec = (R4ExportCapability) Util.getSatisfyingCapability(
+                            modules[modIdx],
+                            new Requirement(ICapability.PACKAGE_NAMESPACE, "(package=" +
name + ")"));
+                    }
+                    catch (InvalidSyntaxException ex)
+                    {
+                        ex.printStackTrace();
+                    }
+
+                    if (ec != null)
                     {
                         pkgs[pkgIdx] =
-                            new ExportedPackageImpl(
-                                this, bundle, modules[modIdx], export);
+                            new ExportedPackageImpl(this, bundle, modules[modIdx], ec);
                     }
                 }
             }
@@ -2349,24 +2360,25 @@
         IModule[] modules = bundle.getInfo().getModules();
         for (int modIdx = 0; modIdx < modules.length; modIdx++)
         {
-            R4Export[] exports = modules[modIdx].getDefinition().getExports();
-            if ((exports != null) && (exports.length > 0))
+            ICapability[] caps = modules[modIdx].getDefinition().getCapabilities();
+            if ((caps != null) && (caps.length > 0))
             {
-                for (int expIdx = 0; expIdx < exports.length; expIdx++)
+                for (int capIdx = 0; capIdx < caps.length; capIdx++)
                 {
                     // See if the target bundle's module is one of the
                     // "in use" exporters of the package.
-                    IModule[] inUseModules =
-                        m_policyCore.getInUseExporters(
-                            new R4Import(exports[expIdx].getName(), null, null), true);
+                    R4SearchPolicyCore.ResolverCandidate[] inUseModules =
+                        m_policyCore.getInUseCandidates(
+                            new R4ImportRequirement(
+                                ((R4ExportCapability) caps[capIdx]).getName(), null, null),
true);
                     // Search through the current providers to find the target
                     // module.
                     for (int i = 0; (inUseModules != null) && (i < inUseModules.length);
i++)
                     {
-                        if (inUseModules[i] == modules[modIdx])
+                        if (inUseModules[i].m_module == modules[modIdx])
                         {
                             list.add(new ExportedPackageImpl(
-                                this, bundle, modules[modIdx], exports[expIdx]));
+                                this, bundle, modules[modIdx], (R4ExportCapability) caps[capIdx]));
                         }
                     }
                 }
@@ -2617,9 +2629,9 @@
 
         // Create the module definition for the new module.
         IModuleDefinition md = new ModuleDefinition(
-            mp.getExports(),
-            mp.getImports(),
-            mp.getDynamicImports(),
+            mp.getCapabilities(),
+            mp.getRequirements(),
+            mp.getDynamicRequirements(),
             mp.getLibraries(
                 m_cache,
                 targetId,
@@ -3609,24 +3621,26 @@
             java.security.PermissionCollection pc = 
                 java.security.Policy.getPolicy().getPermissions(cs);
 
-            R4Import[] imports =
-                m_bundle.getInfo().getCurrentModule().getDefinition().getImports();
+            IRequirement[] requirements =
+                m_bundle.getInfo().getCurrentModule().getDefinition().getRequirements();
             
-            for (int i = 0;i < imports.length; i++)
+            for (int i = 0;i < requirements.length; i++)
             {
-                PackagePermission perm = new PackagePermission(imports[i].getName(), 
+                PackagePermission perm = new PackagePermission(((R4ImportRequirement) requirements[i]).getName(),

                     PackagePermission.IMPORT);
                 if (!pc.implies(perm))
                 {
                    throw new java.security.AccessControlException(
                        "PackagePermission.IMPORT denied for import: " + 
-                       imports[i].getName(), perm);
+                       ((R4ImportRequirement) requirements[i]).getName(), perm);
                 }
             }
+/*
+ * TODO: SECURITY - This shouldn't be necessary now.
             // Check export permission for all exports of the current module.
-            R4Export[] implicitImports =
+            ICapability[] implicitImports =
                 m_bundle.getInfo().getCurrentModule().getDefinition().getExports();
-            
+
             for (int i = 0;i < implicitImports.length; i++)
             {
                 PackagePermission perm = new PackagePermission(
@@ -3638,7 +3652,7 @@
                         implicitImports[i].getName(), perm);
                 }
             }
-            
+*/
             return null;
         }
     }

Modified: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/SystemBundle.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/SystemBundle.java?view=diff&rev=441518&r1=441517&r2=441518
==============================================================================
--- incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/SystemBundle.java
(original)
+++ incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/SystemBundle.java
Fri Sep  8 07:36:56 2006
@@ -20,7 +20,7 @@
 import java.util.*;
 
 import org.apache.felix.framework.cache.SystemBundleArchive;
-import org.apache.felix.framework.searchpolicy.R4Export;
+import org.apache.felix.framework.searchpolicy.R4ExportCapability;
 import org.apache.felix.framework.searchpolicy.R4Package;
 import org.apache.felix.framework.util.FelixConstants;
 import org.apache.felix.framework.util.StringMap;
@@ -32,7 +32,7 @@
     private List m_activatorList = null;
     private BundleActivator m_activator = null;
     private Thread m_shutdownThread = null;
-    private R4Export[] m_exports = null;
+    private R4ExportCapability[] m_exports = null;
     private IContentLoader m_contentLoader = null;
 
     protected SystemBundle(Felix felix, BundleInfo info, List activatorList)
@@ -79,12 +79,12 @@
 
         // Now, create the list of standard framework exports for
         // the system bundle.
-        m_exports = new R4Export[classPathPkgs.length];
+        m_exports = new R4ExportCapability[classPathPkgs.length];
 
         // Copy the class path exported packages.
         for (int i = 0; i < classPathPkgs.length; i++)
         {
-            m_exports[i] = new R4Export(classPathPkgs[i]);
+            m_exports[i] = new R4ExportCapability(classPathPkgs[i]);
         }
 
         m_contentLoader = new SystemBundleContentLoader(getFelix().getLogger());
@@ -121,7 +121,7 @@
         // that will allow for them to be independently configured.
     }
 
-    public R4Export[] getExports()
+    public R4ExportCapability[] getExports()
     {
         return m_exports;
     }

Propchange: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Sep  8 07:36:56 2006
@@ -0,0 +1,11 @@
+Capability.java~
+R4ExportCapability.java~
+R4ImportRequirement.java~
+VersionRange.java~
+ResolveException.java~
+ExportCapability.java~
+ModuleDefinition.java~
+R4Wire.java~
+R4SearchPolicyCore.java~
+Requirement.java~
+R4Package.java~

Modified: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java?view=diff&rev=441518&r1=441517&r2=441518
==============================================================================
--- incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
(original)
+++ incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
Fri Sep  8 07:36:56 2006
@@ -16,39 +16,41 @@
  */
 package org.apache.felix.framework.searchpolicy;
 
+import org.apache.felix.moduleloader.ICapability;
 import org.apache.felix.moduleloader.IModuleDefinition;
+import org.apache.felix.moduleloader.IRequirement;
 
 public class ModuleDefinition implements IModuleDefinition
 {
-    public R4Export[] m_exports = null;
-    public R4Import[] m_imports = null;
-    public R4Import[] m_dynamicImports = null;
+    public ICapability[] m_capabilities = null;
+    public IRequirement[] m_requirements = null;
+    public IRequirement[] m_dynamicRequirements = null;
     public R4Library[] m_libraries = null;
 
     public ModuleDefinition(
-        R4Export[] exports, R4Import[] imports,
-        R4Import[] dynamicImports, R4Library[] libraries)
+        ICapability[] capabilities, IRequirement[] requirements,
+        IRequirement[] dynamicRequirements, R4Library[] libraries)
     {
-        m_exports = exports;
-        m_imports = imports;
-        m_dynamicImports = dynamicImports;
+        m_capabilities = capabilities;
+        m_requirements = requirements;
+        m_dynamicRequirements = dynamicRequirements;
         m_libraries = libraries;
     }
 
-    public R4Export[] getExports()
+    public ICapability[] getCapabilities()
     {
 // TODO: ML - These should probably all return copies of the array.
-        return m_exports;
+        return m_capabilities;
     }
 
-    public R4Import[] getImports()
+    public IRequirement[] getRequirements()
     {
-        return m_imports;
+        return m_requirements;
     }
 
-    public R4Import[] getDynamicImports()
+    public IRequirement[] getDynamicRequirements()
     {
-        return m_dynamicImports;
+        return m_dynamicRequirements;
     }
 
     public R4Library[] getLibraries()

Added: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ExportCapability.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ExportCapability.java?view=auto&rev=441518
==============================================================================
--- incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ExportCapability.java
(added)
+++ incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ExportCapability.java
Fri Sep  8 07:36:56 2006
@@ -0,0 +1,423 @@
+/*
+ *   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 java.util.*;
+
+import org.apache.felix.framework.util.Util;
+import org.apache.felix.moduleloader.ICapability;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+public class R4ExportCapability extends R4Package implements ICapability
+{
+    private String[] m_uses = null;
+    private String[][] m_includeFilter = null;
+    private String[][] m_excludeFilter = null;
+
+    private Map m_attrMap = null;
+
+    public R4ExportCapability(R4Package pkg)
+    {
+        this(pkg.getName(), pkg.getDirectives(), pkg.getAttributes());
+    }
+
+    public R4ExportCapability(String name, R4Directive[] directives, R4Attribute[] attrs)
+    {
+        super(name, directives, attrs);
+
+        // Find all export directives: uses, mandatory, include, and exclude.
+        String mandatory = "", uses = "";
+        for (int i = 0; i < m_directives.length; i++)
+        {
+            if (m_directives[i].getName().equals(Constants.USES_DIRECTIVE))
+            {
+                uses = m_directives[i].getValue();
+            }
+            else if (m_directives[i].getName().equals(Constants.MANDATORY_DIRECTIVE))
+            {
+                mandatory = m_directives[i].getValue();
+            }
+            else if (m_directives[i].getName().equals(Constants.INCLUDE_DIRECTIVE))
+            {
+                String[] ss = Util.parseDelimitedString(m_directives[i].getValue(), ",");
+                m_includeFilter = new String[ss.length][];
+                for (int filterIdx = 0; filterIdx < ss.length; filterIdx++)
+                {
+                    m_includeFilter[filterIdx] = parseSubstring(ss[filterIdx]);
+                }
+            }
+            else if (m_directives[i].getName().equals(Constants.EXCLUDE_DIRECTIVE))
+            {
+                String[] ss = Util.parseDelimitedString(m_directives[i].getValue(), ",");
+                m_excludeFilter = new String[ss.length][];
+                for (int filterIdx = 0; filterIdx < ss.length; filterIdx++)
+                {
+                    m_excludeFilter[filterIdx] = parseSubstring(ss[filterIdx]);
+                }
+            }
+        }
+
+        // Parse these uses directive.
+        StringTokenizer tok = new StringTokenizer(uses, ",");
+        m_uses = new String[tok.countTokens()];
+        for (int i = 0; i < m_uses.length; i++)
+        {
+            m_uses[i] = tok.nextToken().trim();
+        }
+
+        // Parse mandatory directive and mark specified
+        // attributes as mandatory.
+        tok = new StringTokenizer(mandatory, ",");
+        while (tok.hasMoreTokens())
+        {
+            // Get attribute name.
+            String attrName = tok.nextToken().trim();
+            // Find attribute and mark it as mandatory.
+            boolean found = false;
+            for (int i = 0; (!found) && (i < m_attrs.length); i++)
+            {
+                if (m_attrs[i].getName().equals(attrName))
+                {
+                    m_attrs[i] = new R4Attribute(
+                        m_attrs[i].getName(),
+                        m_attrs[i].getValue(), true);
+                    found = true;
+                }
+            }
+            // If a specified mandatory attribute was not found,
+            // then error.
+            if (!found)
+            {
+                throw new IllegalArgumentException(
+                    "Mandatory attribute '" + attrName + "' does not exist.");
+            }
+        }
+
+        // Find the version, if present, and convert to Version.
+        // The version attribute value may be a String or a Version,
+        // since the value may be coming from an R4Export that already
+        // converted it to Version.
+        m_version = Version.emptyVersion;
+        for (int i = 0; i < m_attrs.length; i++)
+        {
+            if (m_attrs[i].getName().equals(Constants.VERSION_ATTRIBUTE))
+            {
+                String versionStr = (m_attrs[i].getValue() instanceof Version)
+                    ? ((Version) m_attrs[i].getValue()).toString()
+                    : (String) m_attrs[i].getValue();
+                m_version = Version.parseVersion(versionStr);
+                m_attrs[i] = new R4Attribute(
+                    m_attrs[i].getName(),
+                    m_version,
+                    m_attrs[i].isMandatory());
+                break;
+            }
+        }
+    }
+
+    public String getNamespace()
+    {
+        return ICapability.PACKAGE_NAMESPACE;
+    }
+
+    public Map getProperties()
+    {
+        if (m_attrMap == null)
+        {
+            m_attrMap = new Map() {
+                public int size()
+                {
+                    // A version attribute is always present, since it has a
+                    // default value.
+                    return m_attrs.length + 1;
+                }
+
+                public boolean isEmpty()
+                {
+                    // A version attribute is always present, since it has a
+                    // default value.
+                    return false;
+                }
+
+                public boolean containsKey(Object key)
+                {
+                    return (get(key) != null);
+                }
+
+                public boolean containsValue(Object value)
+                {
+                    // Check the version.
+                    if (m_version.equals(value))
+                    {
+                        return true;
+                    }
+
+                    // Check all attributes.
+                    for (int i = 0; i < m_attrs.length; i++)
+                    {
+                        if (m_attrs[i].getValue().equals(value))
+                        {
+                            return true;
+                        }
+                    }
+
+                    return false;
+                }
+
+                public Object get(Object key)
+                {
+                    if (ICapability.PACKAGE_PROPERTY.equals(key))
+                    {
+                        return getName();
+                    }
+                    else if (ICapability.VERSION_PROPERTY.equals(key))
+                    {
+                        return getVersion();
+                    }
+
+                    for (int i = 0; i < m_attrs.length; i++)
+                    {
+                        if (m_attrs[i].getName().equals(key))
+                        {
+                            return m_attrs[i].getValue();
+                        }
+                    }
+
+                    return null;
+                }
+
+                public Object put(Object key, Object value)
+                {
+                    throw new UnsupportedOperationException("Map.put() not implemented.");
+                }
+
+                public Object remove(Object key)
+                {
+                    throw new UnsupportedOperationException("Map.remove() not implemented.");
+                }
+
+                public void putAll(Map t)
+                {
+                    throw new UnsupportedOperationException("Map.putAll() not implemented.");
+                }
+
+                public void clear()
+                {
+                    throw new UnsupportedOperationException("Map.clear() not implemented.");
+                }
+
+                public Set keySet()
+                {
+                    Set set = new HashSet();
+                    set.add(ICapability.PACKAGE_PROPERTY);
+                    set.add(ICapability.VERSION_PROPERTY);
+                    for (int i = 0; i < m_attrs.length; i++)
+                    {
+                        set.add(m_attrs[i].getName());
+                    }
+                    return set;
+                }
+
+                public Collection values()
+                {
+                    throw new UnsupportedOperationException("Map.values() not implemented.");
+                }
+
+                public Set entrySet()
+                {
+                    throw new UnsupportedOperationException("Map.entrySet() not implemented.");
+                }
+            };
+        }
+        return m_attrMap;
+    }
+
+    public String[] getUses()
+    {
+        return m_uses;
+    }
+
+    public boolean isIncluded(String name)
+    {
+        if ((m_includeFilter == null) && (m_excludeFilter == null))
+        {
+            return true;
+        }
+
+        // Get the class name portion of the target class.
+        String className = Util.getClassName(name);
+
+        // If there are no include filters then all classes are included
+        // by default, otherwise try to find one match.
+        boolean included = (m_includeFilter == null);
+        for (int i = 0;
+            (!included) && (m_includeFilter != null) && (i < m_includeFilter.length);
+            i++)
+        {
+            included = checkSubstring(m_includeFilter[i], className);
+        }
+
+        // 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_excludeFilter != null) && (i < m_excludeFilter.length);
+            i++)
+        {
+            excluded = checkSubstring(m_excludeFilter[i], className);
+        }
+        return included && !excluded;
+    }
+
+    //
+    // The following substring-related code was lifted and modified
+    // from the LDAP parser code.
+    //
+
+    private static String[] parseSubstring(String target)
+    {
+        List pieces = new ArrayList();
+        StringBuffer ss = new StringBuffer();
+        // int kind = SIMPLE; // assume until proven otherwise
+        boolean wasStar = false; // indicates last piece was a star
+        boolean leftstar = false; // track if the initial piece is a star
+        boolean rightstar = false; // track if the final piece is a star
+
+        int idx = 0;
+
+        // We assume (sub)strings can contain leading and trailing blanks
+loop:   for (;;)
+        {
+            if (idx >= target.length())
+            {
+                if (wasStar)
+                {
+                    // insert last piece as "" to handle trailing star
+                    rightstar = true;
+                }
+                else
+                {
+                    pieces.add(ss.toString());
+                    // accumulate the last piece
+                    // note that in the case of
+                    // (cn=); this might be
+                    // the string "" (!=null)
+                }
+                ss.setLength(0);
+                break loop;
+            }
+
+            char c = target.charAt(idx++);
+            if (c == '*')
+            {
+                if (wasStar)
+                {
+                    // encountered two successive stars;
+                    // I assume this is illegal
+                    throw new IllegalArgumentException("Invalid filter string: " + target);
+                }
+                if (ss.length() > 0)
+                {
+                    pieces.add(ss.toString()); // accumulate the pieces
+                    // between '*' occurrences
+                }
+                ss.setLength(0);
+                // if this is a leading star, then track it
+                if (pieces.size() == 0)
+                {
+                    leftstar = true;
+                }
+                ss.setLength(0);
+                wasStar = true;
+            }
+            else
+            {
+                wasStar = false;
+                ss.append(c);
+            }
+        }
+        if (leftstar || rightstar || pieces.size() > 1)
+        {
+            // insert leading and/or trailing "" to anchor ends
+            if (rightstar)
+            {
+                pieces.add("");
+            }
+            if (leftstar)
+            {
+                pieces.add(0, "");
+            }
+        }
+        return (String[]) pieces.toArray(new String[pieces.size()]);
+    }
+
+    private static boolean checkSubstring(String[] pieces, String s)
+    {
+        // Walk the pieces to match the string
+        // There are implicit stars between each piece,
+        // and the first and last pieces might be "" to anchor the match.
+        // assert (pieces.length > 1)
+        // minimal case is <string>*<string>
+
+        boolean result = false;
+        int len = pieces.length;
+
+loop:   for (int i = 0; i < len; i++)
+        {
+            String piece = (String) pieces[i];
+            int index = 0;
+            if (i == len - 1)
+            {
+                // this is the last piece
+                if (s.endsWith(piece))
+                {
+                    result = true;
+                }
+                else
+                {
+                    result = false;
+                }
+                break loop;
+            }
+            // initial non-star; assert index == 0
+            else if (i == 0)
+            {
+                if (!s.startsWith(piece))
+                {
+                    result = false;
+                    break loop;
+                }
+            }
+            // assert i > 0 && i < len-1
+            else
+            {
+                // Sure wish stringbuffer supported e.g. indexOf
+                index = s.indexOf(piece, index);
+                if (index < 0)
+                {
+                    result = false;
+                    break loop;
+                }
+            }
+            // start beyond the matching piece
+            index += piece.length();
+        }
+
+        return result;
+    }
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ExportCapability.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ImportRequirement.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ImportRequirement.java?view=auto&rev=441518
==============================================================================
--- incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ImportRequirement.java
(added)
+++ incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ImportRequirement.java
Fri Sep  8 07:36:56 2006
@@ -0,0 +1,306 @@
+/*
+ *   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.framework.FilterImpl;
+import org.apache.felix.moduleloader.ICapability;
+import org.apache.felix.moduleloader.IRequirement;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Version;
+
+public class R4ImportRequirement extends R4Package implements IRequirement
+{
+    private VersionRange m_versionRange = null;
+    private boolean m_isOptional = false;
+
+    public R4ImportRequirement(R4Package pkg)
+    {
+        this(pkg.getName(), pkg.getDirectives(), pkg.getAttributes());
+    }
+
+    public R4ImportRequirement(String name, R4Directive[] directives, R4Attribute[] attrs)
+    {
+        super(name, directives, attrs);
+
+        // Find all import directives: resolution.
+        for (int i = 0; i < m_directives.length; i++)
+        {
+            if (m_directives[i].getName().equals(Constants.RESOLUTION_DIRECTIVE))
+            {
+                m_isOptional = m_directives[i].getValue().equals(Constants.RESOLUTION_OPTIONAL);
+            }
+        }
+
+        // Convert version and bundle version attributes to VersionRange.
+        // The attribute value may be a String or a Version, since the
+        // value may be coming from an R4Export that already converted
+        // it to Version.
+        m_versionRange = VersionRange.parse(Version.emptyVersion.toString());
+        m_version = m_versionRange.getLow();
+        for (int i = 0; i < m_attrs.length; i++)
+        {
+            if (m_attrs[i].getName().equals(Constants.VERSION_ATTRIBUTE))
+            {
+                String versionStr = (m_attrs[i].getValue() instanceof Version)
+                    ? ((Version) m_attrs[i].getValue()).toString()
+                    : (String) m_attrs[i].getValue();
+                m_versionRange = VersionRange.parse(versionStr);
+                m_version = m_versionRange.getLow();
+                m_attrs[i] = new R4Attribute(
+                    m_attrs[i].getName(),
+                    m_versionRange,
+                    m_attrs[i].isMandatory());
+            }
+            else if (m_attrs[i].getName().equals(Constants.BUNDLE_VERSION_ATTRIBUTE))
+            {
+                String versionStr = (m_attrs[i].getValue() instanceof Version)
+                    ? ((Version) m_attrs[i].getValue()).toString()
+                    : (String) m_attrs[i].getValue();
+                m_attrs[i] = new R4Attribute(
+                    m_attrs[i].getName(),
+                    VersionRange.parse(versionStr),
+                    m_attrs[i].isMandatory());
+            }
+        }
+    }
+
+    public String getNamespace()
+    {
+        return ICapability.PACKAGE_NAMESPACE;
+    }
+
+    public Filter getFilter()
+    {
+        return convertToFilter();
+    }
+
+    private Filter convertToFilter()
+    {
+        String filterStr = null;
+
+        // Convert wild-carded dynamically imported package
+        // names to an OR comparison.
+        StringBuffer sb = new StringBuffer("(&");
+        if (getName().endsWith(".*"))
+        {
+            int idx = getName().indexOf(".*");
+            sb.append("(|(package=");
+            sb.append(getName().substring(0, idx));
+            sb.append(")(package=");
+            sb.append(getName());
+            sb.append("))");
+        }
+        else
+        {
+            sb.append("(package=");
+            sb.append(getName());
+            sb.append(")");
+        }
+
+        if (isLowInclusive())
+        {
+            sb.append("(version>=");
+            sb.append(getVersion());
+            sb.append(")");
+        }
+        else
+        {
+            sb.append("(!(version<=");
+            sb.append(getVersion());
+            sb.append("))");
+        }
+
+        if (getVersionHigh() != null)
+        {
+            if (isHighInclusive())
+            {
+                sb.append("(version<=");
+                sb.append(getVersionHigh());
+                sb.append(")");
+            }
+            else
+            {
+                sb.append("(!(version>=");
+                sb.append(getVersionHigh());
+                sb.append("))");
+            }
+//            RequirementImpl req = new RequirementImpl();
+//            req.setMultiple("false");
+//            req.setName("package");
+//            req.addText("Import package " + imports[impIdx].toString());
+//            req.setFilter(
+//                );
+        }
+
+        sb.append(")");
+
+        try
+        {
+            return new FilterImpl(sb.toString());
+        }
+        catch (InvalidSyntaxException ex)
+        {
+            // Should never happen.
+        }
+
+        return null;
+    }
+
+    public boolean isMultiple()
+    {
+        return false;
+    }
+
+    public boolean isOptional()
+    {
+        return m_isOptional;
+    }
+
+    public String getComment()
+    {
+        return "Comment for " + toString();
+    }
+
+    public boolean isSatisfied(ICapability capability)
+    {
+        // For packages to be compatible, they must have the
+        // same name.
+        if (capability instanceof R4ExportCapability)
+        {
+            if (!getName().equals(((R4ExportCapability) capability).getName()))
+            {
+                return false;
+            }
+
+            return m_versionRange.isInRange(((R4ExportCapability) capability).getVersion())
+                && doAttributesMatch((R4ExportCapability) capability);
+        }
+        return false;
+    }
+
+    public Version getVersionHigh()
+    {
+        return m_versionRange.getHigh();
+    }
+
+    public boolean isLowInclusive()
+    {
+        return m_versionRange.isLowInclusive();
+    }
+
+    public boolean isHighInclusive()
+    {
+        return m_versionRange.isHighInclusive();
+    }
+
+    private boolean doAttributesMatch(R4ExportCapability ec)
+    {
+        // Cycle through all attributes of this import package
+        // and make sure its values match the attribute values
+        // of the specified export package.
+        for (int impAttrIdx = 0; impAttrIdx < getAttributes().length; impAttrIdx++)
+        {
+            // Get current attribute from this import package.
+            R4Attribute impAttr = getAttributes()[impAttrIdx];
+
+            // Ignore version attribute, since it is a special case that
+            // has already been compared using isVersionInRange() before
+            // the call to this method was made.
+            if (impAttr.getName().equals(Constants.VERSION_ATTRIBUTE))
+            {
+                continue;
+            }
+
+            // Check if the export package has the same attribute.
+            boolean found = false;
+            for (int expAttrIdx = 0;
+                (!found) && (expAttrIdx < ec.getAttributes().length);
+                expAttrIdx++)
+            {
+                // Get current attribute for the export package.
+                R4Attribute expAttr = ec.getAttributes()[expAttrIdx];
+                // Check if the attribute names are equal.
+                if (impAttr.getName().equals(expAttr.getName()))
+                {
+                    // We only recognize version types. If the value of the
+                    // attribute is a version/version range, then we use the
+                    // "in range" comparison, otherwise we simply use equals().
+                    if (expAttr.getValue() instanceof Version)
+                    {
+                        if (!((VersionRange) impAttr.getValue()).isInRange((Version) expAttr.getValue()))
+                        {
+                            return false;
+                        }
+                    }
+                    else if (!impAttr.getValue().equals(expAttr.getValue()))
+                    {
+                        return false;
+                    }
+                    found = true;
+                }
+            }
+            // If the attribute was not found, then return false.
+            if (!found)
+            {
+                return false;
+            }
+        }
+
+        // Now, cycle through all attributes of the export package and verify that
+        // all mandatory attributes are present in this import package.
+        for (int expAttrIdx = 0; expAttrIdx < ec.getAttributes().length; expAttrIdx++)
+        {
+            // Get current attribute for this package.
+            R4Attribute expAttr = ec.getAttributes()[expAttrIdx];
+            
+            // If the export attribute is mandatory, then make sure
+            // this import package has the attribute.
+            if (expAttr.isMandatory())
+            {
+                boolean found = false;
+                for (int impAttrIdx = 0;
+                    (!found) && (impAttrIdx < getAttributes().length);
+                    impAttrIdx++)
+                {
+                    // Get current attribute from specified package.
+                    R4Attribute impAttr = getAttributes()[impAttrIdx];
+        
+                    // Check if the attribute names are equal
+                    // and set found flag.
+                    if (expAttr.getName().equals(impAttr.getName()))
+                    {
+                        found = true;
+                    }
+                }
+                // If not found, then return false.
+                if (!found)
+                {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
+    public String toString()
+    {
+        return getFilter().toString();
+    }
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4ImportRequirement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java?view=diff&rev=441518&r1=441517&r2=441518
==============================================================================
--- incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java
(original)
+++ incubator/felix/sandbox/rickhall/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java
Fri Sep  8 07:36:56 2006
@@ -28,7 +28,7 @@
     private String m_name = "";
     protected R4Directive[] m_directives = null;
     protected R4Attribute[] m_attrs = null;
-    protected Version m_version = new Version("0.0.0");
+    protected Version m_version = null;
 
     public R4Package(String name, R4Directive[] directives, R4Attribute[] attrs)
     {
@@ -44,6 +44,11 @@
         return m_name;
     }
 
+    public Version getVersion()
+    {
+        return m_version;
+    }
+
     public R4Directive[] getDirectives()
     {
         return m_directives;
@@ -53,12 +58,6 @@
     {
         return m_attrs;
     }
-
-    public Version getVersion()
-    {
-        return m_version;
-    }
-
 
     public String toString()
     {



Mime
View raw message