Removed some experimental code for "implicit requirements" that was added
for Peter Kriens.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@694792 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
index 40112d5..8d6e9ba 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
@@ -46,9 +46,7 @@
 
     public void addRequirement(String s) throws BundleException
     {
-        // TODO: EXPERIMENTAL - Experimental implicit wire concept to try
-        //       to deal with code generation.
-        m_felix.addRequirement(m_bundle, s);
+        throw new BundleException("Not implemented yet.");
     }
 
     public void removeRequirement() throws BundleException
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 461d167..f7df03f 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -2181,31 +2181,6 @@
     // Implementation of BundleContext interface methods.
     //
 
-    protected void addRequirement(FelixBundle bundle, String s) throws BundleException
-    {
-        // TODO: EXPERIMENTAL - Experimental implicit wire concept to try
-        //       to deal with code generation.
-        synchronized (m_factory)
-        {
-            IRequirement[] reqs = ManifestParser.parseImportHeader(s);
-            IRequirement[] dynamics = bundle.getInfo().getCurrentModule()
-                .getDefinition().getDynamicRequirements();
-            if (dynamics == null)
-            {
-                dynamics = reqs;
-            }
-            else
-            {
-                IRequirement[] tmp = new IRequirement[dynamics.length + reqs.length];
-                System.arraycopy(dynamics, 0, tmp, 0, dynamics.length);
-                System.arraycopy(reqs, 0, tmp, dynamics.length, reqs.length);
-                dynamics = tmp;
-            }
-            ((ModuleDefinition) bundle.getInfo().getCurrentModule().getDefinition())
-                .setDynamicRequirements(dynamics);
-        }
-    }
-
     /**
      * Implementation for BundleContext.getProperty(). Returns
      * environment property associated with the framework.
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
index 73eb14d..8774ea5 100644
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
@@ -62,13 +62,6 @@
         return m_dynamicRequirements;
     }
 
-    // TODO: EXPERIMENTAL - Experimental implicit wire concept to try
-    //       to deal with code generation.
-    public void setDynamicRequirements(IRequirement[] reqs)
-    {
-        m_dynamicRequirements = reqs;
-    }
-
     public R4Library[] getLibraries()
     {
         return m_libraries;
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
index ec22542..e22f08d 100755
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
@@ -1959,38 +1959,6 @@
                 ResolvedPackage rp = new ResolvedPackage(pkgName);
                 rp.m_sourceList.add(ps);
                 pkgMap.put(rp.m_name, rp);
-
-                // TODO: EXPERIMENTAL - Experimental implicit wire concept to try
-                //       to deal with code generation.
-                // Get implicitly imported packages as defined by the provider
-                // of our imported package, unless we are the provider.
-                if (!targetModule.equals(ps.m_module))
-                {
-                    Map implicitPkgMap = calculateImplicitImportedPackages(
-                        ps.m_module, ps.m_capability, candidatesMap, new HashMap());
-                    // Merge the implicitly imported packages with our imports and
-                    // verify that there is no overlap.
-                    for (Iterator i = implicitPkgMap.entrySet().iterator(); i.hasNext(); )
-                    {
-                        Map.Entry entry = (Map.Entry) i.next();
-                        ResolvedPackage implicit = (ResolvedPackage) entry.getValue();
-                        ResolvedPackage existing = (ResolvedPackage) pkgMap.get(entry.getKey());
-                        if ((existing != null) &&
-                            !(existing.isSubset(implicit) && implicit.isSubset(existing)))
-                        {
-                            throw new ResolveException(
-                                "Implicit import of "
-                                + entry.getKey()
-                                + " from "
-                                + implicit
-                                + " duplicates an existing import from "
-                                + existing,
-                                targetModule,
-                                cs.m_requirement);
-                        }
-                        pkgMap.put(entry.getKey(), entry.getValue());
-                    }
-                }
             }
         }
 
@@ -2017,121 +1985,12 @@
                 rp = (rp == null) ? new ResolvedPackage(pkgName) : rp;
                 rp.m_sourceList.add(new PackageSource(wires[wireIdx].getExporter(), wires[wireIdx].getCapability()));
                 pkgMap.put(rp.m_name, rp);
-
-                // TODO: EXPERIMENTAL - Experimental implicit wire concept to try
-                //       to deal with code generation.
-                // Get implicitly imported packages as defined by the provider
-                // of our imported package, unless we are the provider.
-                if (!targetModule.equals(wires[wireIdx].getExporter()))
-                {
-                    Map implicitPkgMap = calculateImplicitImportedPackagesResolved(
-                        wires[wireIdx].getExporter(), wires[wireIdx].getCapability(), new HashMap());
-                    // Merge the implicitly imported packages with our imports.
-                    // No need to verify overlap since this is resolved and should
-                    // be consistent.
-                    for (Iterator i = implicitPkgMap.entrySet().iterator(); i.hasNext(); )
-                    {
-                        Map.Entry entry = (Map.Entry) i.next();
-                        pkgMap.put(entry.getKey(), entry.getValue());
-                    }
-                }
             }
         }
 
         return pkgMap;
     }
 
-    private Map calculateImplicitImportedPackages(
-        IModule targetModule, ICapability targetCapability,
-        Map candidatesMap, Map cycleMap)
-    {
-        return (candidatesMap.get(targetModule) == null)
-            ? calculateImplicitImportedPackagesResolved(
-                targetModule, targetCapability, cycleMap)
-            : calculateImplicitImportedPackagesUnresolved(
-                targetModule, targetCapability, candidatesMap, cycleMap);
-    }
-
-    // TODO: EXPERIMENTAL - This is currently not defined recursively, but it should be.
-    //       Currently, it only assumes that a provider can cause implicit imports for
-    //       packages that it exports.
-    private Map calculateImplicitImportedPackagesUnresolved(
-        IModule targetModule, ICapability targetCapability,
-        Map candidatesMap, Map cycleMap)
-    {
-        Map pkgMap = new HashMap();
-
-        R4Directive[] dirs = ((Capability) targetCapability).getDirectives();
-        if (dirs != null)
-        {
-            for (int dirIdx = 0; dirIdx < dirs.length; dirIdx++)
-            {
-                if (dirs[dirIdx].getName().equals("x-implicitwire"))
-                {
-                    String[] pkgs = ManifestParser.parseDelimitedString(dirs[dirIdx].getValue(), ",");
-                    for (int pkgIdx = 0; pkgIdx < pkgs.length; pkgIdx++)
-                    {
-                        ResolvedPackage rp = new ResolvedPackage(pkgs[pkgIdx].trim());
-                        rp.m_sourceList.add(
-                            new PackageSource(
-                                targetModule,
-                                getExportPackageCapability(targetModule, pkgs[pkgIdx])));
-                        pkgMap.put(rp.m_name, rp);
-                    }
-                }
-            }
-        }
-
-        return pkgMap;
-    }
-
-    // TODO: EXPERIMENTAL - This is currently not defined recursively, but it should be.
-    //       Currently, it only assumes that a provider can cause implicit imports for
-    //       packages that it exports.
-    private Map calculateImplicitImportedPackagesResolved(
-        IModule targetModule, ICapability targetCapability, Map cycleMap)
-    {
-        Map pkgMap = new HashMap();
-
-        R4Directive[] dirs = ((Capability) targetCapability).getDirectives();
-        if (dirs != null)
-        {
-            for (int dirIdx = 0; dirIdx < dirs.length; dirIdx++)
-            {
-                if (dirs[dirIdx].getName().equals("x-implicitwire"))
-                {
-                    String[] pkgs = ManifestParser.parseDelimitedString(dirs[dirIdx].getValue(), ",");
-                    for (int pkgIdx = 0; pkgIdx < pkgs.length; pkgIdx++)
-                    {
-                        ResolvedPackage rp = new ResolvedPackage(pkgs[pkgIdx].trim());
-                        rp.m_sourceList.add(
-                            new PackageSource(
-                                targetModule,
-                                getExportPackageCapability(targetModule, pkgs[pkgIdx])));
-                        pkgMap.put(rp.m_name, rp);
-                    }
-                }
-            }
-        }
-
-        return pkgMap;
-    }
-
-    private Map calculateCandidateImplicitImportedPackages(IModule module, PackageSource psTarget, Map candidatesMap)
-    {
-//System.out.println("calculateCandidateImplicitPackages("+module+")");
-        // Cannot implicitly wire to oneself.
-        if (!module.equals(psTarget.m_module))
-        {
-            Map cycleMap = new HashMap();
-            cycleMap.put(module, module);
-            return calculateImplicitImportedPackages(
-                psTarget.m_module, psTarget.m_capability, candidatesMap, cycleMap);
-        }
-
-        return null;
-    }
-
     private Map calculateExportedPackages(IModule targetModule)
     {
 //System.out.println("calculateExportedPackages("+targetModule+")");
@@ -2693,26 +2552,6 @@
                     cs.m_requirement,
                     cs.m_candidates[cs.m_idx].m_module,
                     cs.m_candidates[cs.m_idx].m_capability));
-
-                // TODO: EXPERIMENTAL - The following is part of an experimental
-                //       implicit imported wire concept. The above code is how
-                //       the wire should normally be created.
-                // Add wires for any implicitly imported package from provider.
-                Map pkgMap = calculateCandidateImplicitImportedPackages(
-                    importer, cs.m_candidates[cs.m_idx], candidatesMap);
-                if (pkgMap != null)
-                {
-                    for (Iterator i = pkgMap.entrySet().iterator(); i.hasNext(); )
-                    {
-                        Map.Entry entry = (Map.Entry) i.next();
-                        ResolvedPackage rp = (ResolvedPackage) entry.getValue();
-                        packageWires.add(new R4Wire(
-                            importer,
-                            cs.m_requirement, // TODO: This is not really correct.
-                            ((PackageSource) rp.m_sourceList.get(0)).m_module,
-                            ((PackageSource) rp.m_sourceList.get(0)).m_capability));
-                    }
-                }
             }
 
             // Create any necessary wires for the selected candidate module.
@@ -3341,7 +3180,7 @@
     }
 
     /**
-     * This utility class a resolved package, which is comprised of a
+     * This utility class is a resolved package, which is comprised of a
      * set of <tt>PackageSource</tt>s that is calculated by the resolver
      * algorithm. A given resolved package may have a single package source,
      * as is the case with imported packages, or it may have multiple
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
index 2b2ead0..07ff41e 100755
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
@@ -88,18 +88,24 @@
         if (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE) &&
             m_capability.getProperties().get(ICapability.PACKAGE_PROPERTY).equals(pkgName))
         {
-            // Before delegating to the exporting module to satisfy
-            // the class load, we must check the include/exclude filters
-            // from the target package to make sure that the class is
-            // actually visible. However, if the exporting module is the
-            // same as the requesting module, then filtering is not
-            // performed since a module has complete access to itself.
-            if ((m_exporter == m_importer) ||
-                (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE) &&
-                    ((Capability) m_capability).isIncluded(name)))
+            // If the importer and the exporter are the same, then
+            // just ask for the class from the exporting module's
+            // content directly.
+            if (m_exporter == m_importer)
             {
                 clazz = m_exporter.getContentLoader().getClass(name);
             }
+            // Otherwise, check the include/exclude filters from the target
+            // package to make sure that the class is actually visible. In
+            // this case since the importing and exporting modules are different,
+            // we delegate to the exporting module, rather than its content,
+            // so that it can follow any internal wires it may have (e.g.,
+            // if the package has multiple sources).
+            else if (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE)
+                && ((Capability) m_capability).isIncluded(name))
+            {
+                clazz = m_exporter.getClass(name);
+            }
 
             // If no class was found, then we must throw an exception
             // since the exporter for this package did not contain the