felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1095097 [7/7] - in /felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework: ./ capabilityset/ resolver/ util/ util/manifestparser/ wiring/
Date Tue, 19 Apr 2011 14:17:01 GMT
Copied: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java (from r1091796, felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/WireImpl.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java?p2=felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java&p1=felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/WireImpl.java&r1=1091796&r2=1095097&rev=1095097&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/WireImpl.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java Tue Apr 19 14:16:59 2011
@@ -18,160 +18,53 @@
  */
 package org.apache.felix.framework.resolver;
 
-import java.net.URL;
-import java.util.Enumeration;
-import org.apache.felix.framework.util.Util;
 import org.apache.felix.framework.wiring.BundleCapabilityImpl;
 import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
 
-class WireImpl implements Wire
+class ResolverWireImpl implements ResolverWire
 {
-    private final Module m_importer;
-    private final BundleRequirementImpl m_req;
-    private final Module m_exporter;
-    private final BundleCapabilityImpl m_cap;
-
-    public WireImpl(Module importer, BundleRequirementImpl ip,
-        Module exporter, BundleCapabilityImpl cap)
-    {
-        m_importer = importer;
-        m_req = ip;
-        m_exporter = exporter;
+    private final BundleRevision m_requirer;
+    private final BundleRequirement m_req;
+    private final BundleRevision m_provider;
+    private final BundleCapability m_cap;
+
+    public ResolverWireImpl(BundleRevision requirer, BundleRequirement req,
+        BundleRevision provider, BundleCapability cap)
+    {
+        m_requirer = requirer;
+        m_req = req;
+        m_provider = provider;
         m_cap = cap;
     }
 
-    public Module getImporter()
+    public BundleRevision getRequirer()
     {
-        return m_importer;
+        return m_requirer;
     }
 
-    public BundleRequirementImpl getRequirement()
+    public BundleRequirement getRequirement()
     {
         return m_req;
     }
 
-    public Module getExporter()
+    public BundleRevision getProvider()
     {
-        return m_exporter;
+        return m_provider;
     }
 
-    public BundleCapabilityImpl getCapability()
+    public BundleCapability getCapability()
     {
         return m_cap;
     }
 
     public String toString()
     {
-        return "[" + m_importer + "] "
-            + m_req.getNamespace() + "; "
-            + m_req.getFilter() + " -> "
-            + "[" + m_exporter + "]";
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
-     */
-    public boolean hasPackage(String pkgName)
-    {
-        return (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-            m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName));
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
-     */
-    public Class getClass(String name) throws ClassNotFoundException
-    {
-        Class clazz = null;
-
-        // Get the package of the target class.
-        String pkgName = Util.getClassPackage(name);
-
-        // Only check when the package of the target class is
-        // the same as the package for the wire.
-        if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-            m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
-        {
-            // Check the include/exclude filters from the target package
-            // to make sure that the class is actually visible. We delegate
-            // to the exporting module, rather than its content, so it can
-            // it can follow any internal wires it may have (e.g., if the
-            // package has multiple sources).
-            if (m_cap.isIncluded(name))
-            {
-                clazz = m_exporter.getClassByDelegation(name);
-            }
-
-            // If no class was found, then we must throw an exception
-            // since the exporter for this package did not contain the
-            // requested class.
-            if (clazz == null)
-            {
-                throw new ClassNotFoundException(name);
-            }
-        }
-
-        return clazz;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.felix.framework.searchpolicy.IWire#getResource(java.lang.String)
-     */
-    public URL getResource(String name) throws ResourceNotFoundException
-    {
-        URL url = null;
-
-        // Get the package of the target class.
-        String pkgName = Util.getResourcePackage(name);
-
-        // Only check when the package of the target resource is
-        // the same as the package for the wire.
-        if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-            m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
-        {
-            // 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).
-            url = m_exporter.getResourceByDelegation(name);
-
-            // If no resource was found, then we must throw an exception
-            // since the exporter for this package did not contain the
-            // requested class.
-            if (url == null)
-            {
-                throw new ResourceNotFoundException(name);
-            }
-        }
-
-        return url;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.felix.framework.searchpolicy.IWire#getResources(java.lang.String)
-     */
-    public Enumeration getResources(String name) throws ResourceNotFoundException
-    {
-        Enumeration urls = null;
-
-        // Get the package of the target class.
-        String pkgName = Util.getResourcePackage(name);
-
-        // Only check when the package of the target resource is
-        // the same as the package for the wire.
-        if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-            m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
-        {
-            urls = m_exporter.getResourcesByDelegation(name);
-
-            // If no resource was found, then we must throw an exception
-            // since the exporter for this package did not contain the
-            // requested class.
-            if ((urls == null) || !urls.hasMoreElements())
-            {
-                throw new ResourceNotFoundException(name);
-            }
-        }
-
-        return urls;
+        return "[" + m_requirer + "] "
+            + m_req
+            + " -> "
+            + "[" + m_provider + "]";
     }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/Util.java?rev=1095097&r1=1095096&r2=1095097&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/Util.java Tue Apr 19 14:16:59 2011
@@ -26,16 +26,17 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import org.apache.felix.framework.BundleRevisionImpl;
 import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.capabilityset.CapabilitySet;
-import org.apache.felix.framework.resolver.Module;
-import org.apache.felix.framework.resolver.Wire;
 import org.apache.felix.framework.wiring.BundleCapabilityImpl;
 import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.apache.felix.framework.wiring.FelixBundleWire;
 
 import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
 
 public class Util
 {
@@ -85,11 +86,11 @@ public class Util
     }
 
     /**
-     * Converts a module identifier to a bundle identifier. Module IDs
+     * Converts a revision identifier to a bundle identifier. Revision IDs
      * are typically <tt>&lt;bundle-id&gt;.&lt;revision&gt;</tt>; this
      * method returns only the portion corresponding to the bundle ID.
     **/
-    public static long getBundleIdFromModuleId(String id)
+    public static long getBundleIdFromRevisionId(String id)
     {
         try
         {
@@ -279,17 +280,18 @@ public class Util
         return allow;
     }
 
-    public static BundleCapabilityImpl getSatisfyingCapability(Module m, BundleRequirementImpl req)
+    public static BundleCapability getSatisfyingCapability(
+        BundleRevision br, BundleRequirementImpl req)
     {
-        List<BundleCapabilityImpl> caps = (m.isResolved())
-            ? m.getResolvedCapabilities()
-            : m.getDeclaredCapabilities();
+        List<BundleCapability> caps = (br.getWiring() != null)
+            ? br.getWiring().getCapabilities(null)
+            : br.getDeclaredCapabilities(null);
         if (caps != null)
         {
-            for (BundleCapabilityImpl cap : caps)
+            for (BundleCapability cap : caps)
             {
                 if (cap.getNamespace().equals(req.getNamespace())
-                    && CapabilitySet.matches(cap, req.getFilter()))
+                    && CapabilitySet.matches((BundleCapabilityImpl) cap, req.getFilter()))
                 {
                     return cap;
                 }
@@ -301,19 +303,20 @@ public class Util
     /**
      * Returns all the capabilities from a module that has a specified namespace.
      *
-     * @param m    module providing capabilities
+     * @param br    module providing capabilities
      * @param namespace capability namespace
      * @return array of matching capabilities or empty if none found
      */
-    public static List<BundleCapabilityImpl> getCapabilityByNamespace(Module m, String namespace)
+    public static List<BundleCapability> getCapabilityByNamespace(
+        BundleRevision br, String namespace)
     {
-        final List<BundleCapabilityImpl> matching = new ArrayList();
-        final List<BundleCapabilityImpl> caps = (m.isResolved())
-            ? m.getResolvedCapabilities()
-            : m.getDeclaredCapabilities();
+        final List<BundleCapability> matching = new ArrayList();
+        final List<BundleCapability> caps = (br.getWiring() != null)
+            ? br.getWiring().getCapabilities(null)
+            : br.getDeclaredCapabilities(null);
         if (caps != null)
         {
-            for (BundleCapabilityImpl cap : caps)
+            for (BundleCapability cap : caps)
             {
                 if (cap.getNamespace().equals(namespace))
                 {
@@ -324,12 +327,12 @@ public class Util
         return matching;
     }
 
-    public static Wire getWire(Module m, String name)
+    public static FelixBundleWire getWire(BundleRevision br, String name)
     {
-        List<Wire> wires = m.getWires();
+        List<FelixBundleWire> wires = ((BundleRevisionImpl) br).getWires();
         if (wires != null)
         {
-            for (Wire w : wires)
+            for (FelixBundleWire w : wires)
             {
                 if (w.getCapability().getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
                     w.getCapability().getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(name))
@@ -587,9 +590,8 @@ public class Util
      * @return <code>true</code> if the module declares a fragment host, <code>false</code>
      *      otherwise.
      */
-    public static boolean isFragment(Module module)
+    public static boolean isFragment(BundleRevision revision)
     {
-        Map headerMap = module.getHeaders();
-        return headerMap.containsKey(Constants.FRAGMENT_HOST);
+        return ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) > 0);
     }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java?rev=1095097&r1=1095096&r2=1095097&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java Tue Apr 19 14:16:59 2011
@@ -21,33 +21,36 @@ package org.apache.felix.framework.util.
 import java.util.*;
 import java.util.ArrayList;
 import java.util.Map.Entry;
+import org.apache.felix.framework.BundleRevisionImpl;
 
 import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.resolver.Module;
 import org.apache.felix.framework.util.FelixConstants;
 import org.apache.felix.framework.util.VersionRange;
 import org.apache.felix.framework.wiring.BundleRequirementImpl;
 import org.osgi.framework.*;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
 
 public class ManifestParser
 {
     private final Logger m_logger;
     private final Map m_configMap;
     private final Map m_headerMap;
-    private volatile int m_activationPolicy = Module.EAGER_ACTIVATION;
+    private volatile int m_activationPolicy = BundleRevisionImpl.EAGER_ACTIVATION;
     private volatile String m_activationIncludeDir;
     private volatile String m_activationExcludeDir;
     private volatile boolean m_isExtension = false;
     private volatile String m_bundleSymbolicName;
     private volatile Version m_bundleVersion;
-    private volatile List<BundleCapabilityImpl> m_capabilities;
-    private volatile List<BundleRequirementImpl> m_requirements;
-    private volatile List<BundleRequirementImpl> m_dynamicRequirements;
+    private volatile List<BundleCapability> m_capabilities;
+    private volatile List<BundleRequirement> m_requirements;
+    private volatile List<BundleRequirement> m_dynamicRequirements;
     private volatile List<R4LibraryClause> m_libraryClauses;
     private volatile boolean m_libraryHeadersOptional = false;
 
-    public ManifestParser(Logger logger, Map configMap, Module owner, Map headerMap)
+    public ManifestParser(Logger logger, Map configMap, BundleRevision owner, Map headerMap)
         throws BundleException
     {
         m_logger = logger;
@@ -92,41 +95,41 @@ public class ManifestParser
         // Parse bundle symbolic name.
         //
 
-        BundleCapabilityImpl moduleCap = parseBundleSymbolicName(owner, m_headerMap);
-        if (moduleCap != null)
+        BundleCapabilityImpl requireCap = parseBundleSymbolicName(owner, m_headerMap);
+        if (requireCap != null)
         {
             m_bundleSymbolicName = (String)
-                moduleCap.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
+                requireCap.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
 
-            // Add a module capability and a host capability to all
+            // Add a bundle capability and a host capability to all
             // non-fragment bundles. A host capability is the same
-            // as a module capability, but with a different capability
-            // namespace. Module capabilities resolve required-bundle
+            // as a require capability, but with a different capability
+            // namespace. Bundle capabilities resolve required-bundle
             // dependencies, while host capabilities resolve fragment-host
             // dependencies.
             if (headerMap.get(Constants.FRAGMENT_HOST) == null)
             {
-                capList.add(moduleCap);
+                capList.add(requireCap);
                 capList.add(new BundleCapabilityImpl(
                     owner, BundleCapabilityImpl.HOST_NAMESPACE,
                     Collections.EMPTY_MAP,
 // TODO: OSGi R4.3 - Wraps map as unmodifiable twice.
-                    moduleCap.getAttributes()));
+                    requireCap.getAttributes()));
             }
 
             // Add a singleton capability if the bundle is a singleton.
             // This is sort of a hack, but we need this for the resolver
             // to be able to resolve singletons. It is not possible to
-            // attach this information to the module or host capabilities
+            // attach this information to the bundle or host capabilities
             // because fragments don't have those capabilities, but fragments
             // can be singletons too.
-            if (isSingleton(moduleCap))
+            if (isSingleton(requireCap))
             {
                 capList.add(new BundleCapabilityImpl(
                     owner, BundleCapabilityImpl.SINGLETON_NAMESPACE,
                     Collections.EMPTY_MAP,
 // TODO: OSGi R4.3 - Wraps map as unmodifiable twice.
-                    moduleCap.getAttributes()));
+                    requireCap.getAttributes()));
             }
         }
 
@@ -159,7 +162,7 @@ public class ManifestParser
         List<ParsedHeaderClause> importClauses =
             parseStandardHeader((String) headerMap.get(Constants.IMPORT_PACKAGE));
         importClauses = normalizeImportClauses(m_logger, importClauses, getManifestVersion());
-        List<BundleRequirementImpl> importReqs = convertImports(importClauses, owner);
+        List<BundleRequirement> importReqs = convertImports(importClauses, owner);
 
         //
         // Parse DynamicImport-Package.
@@ -179,7 +182,7 @@ public class ManifestParser
             parseStandardHeader((String) headerMap.get(Constants.EXPORT_PACKAGE));
         exportClauses = normalizeExportClauses(logger, exportClauses,
             getManifestVersion(), m_bundleSymbolicName, m_bundleVersion);
-        List<BundleCapabilityImpl> exportCaps = convertExports(exportClauses, owner);
+        List<BundleCapability> exportCaps = convertExports(exportClauses, owner);
 
         //
         // Calculate implicit imports.
@@ -216,7 +219,7 @@ public class ManifestParser
         // Parse Bundle-NativeCode.
         //
 
-        // Get native library entry names for module library sources.
+        // Parse native library clauses.
         m_libraryClauses =
             parseLibraryStrings(
                 m_logger,
@@ -244,7 +247,7 @@ public class ManifestParser
 
     private static boolean isSingleton(BundleCapabilityImpl cap)
     {
-        if (cap.getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
+        if (cap.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
         {
             String value = cap.getDirectives().get(Constants.SINGLETON_DIRECTIVE);
             if ((value != null) && Boolean.valueOf(value))
@@ -382,8 +385,8 @@ public class ManifestParser
         return clauses;
     }
 
-    private static List<BundleRequirementImpl> convertImports(
-        List<ParsedHeaderClause> clauses, Module owner)
+    private static List<BundleRequirement> convertImports(
+        List<ParsedHeaderClause> clauses, BundleRevision owner)
     {
         // Now convert generic header clauses into requirements.
         List reqList = new ArrayList();
@@ -682,17 +685,17 @@ public class ManifestParser
         return m_bundleVersion;
     }
 
-    public List<BundleCapabilityImpl> getCapabilities()
+    public List<BundleCapability> getCapabilities()
     {
         return m_capabilities;
     }
 
-    public List<BundleRequirementImpl> getRequirements()
+    public List<BundleRequirement> getRequirements()
     {
         return m_requirements;
     }
 
-    public List<BundleRequirementImpl> getDynamicRequirements()
+    public List<BundleRequirement> getDynamicRequirements()
     {
         return m_dynamicRequirements;
     }
@@ -917,7 +920,7 @@ public class ManifestParser
     }
 
     private static List<ParsedHeaderClause> calculateImplicitImports(
-        List<BundleCapabilityImpl> exports, List<ParsedHeaderClause> imports)
+        List<BundleCapability> exports, List<ParsedHeaderClause> imports)
         throws BundleException
     {
         List<ParsedHeaderClause> clauseList = new ArrayList();
@@ -963,8 +966,8 @@ public class ManifestParser
         return clauseList;
     }
 
-    private static List<BundleCapabilityImpl> calculateImplicitUses(
-        List<BundleCapabilityImpl> exports, List<ParsedHeaderClause> imports)
+    private static List<BundleCapability> calculateImplicitUses(
+        List<BundleCapability> exports, List<ParsedHeaderClause> imports)
         throws BundleException
     {
         // Add a "uses" directive onto each export of R3 bundles
@@ -987,7 +990,7 @@ public class ManifestParser
             Map<String, String> dirs = new HashMap<String, String>(1);
             dirs.put(Constants.USES_DIRECTIVE, usesValue);
             exports.set(i, new BundleCapabilityImpl(
-                exports.get(i).getModule(),
+                exports.get(i).getRevision(),
                 BundleCapabilityImpl.PACKAGE_NAMESPACE,
                 dirs,
                 exports.get(i).getAttributes()));
@@ -1022,7 +1025,8 @@ public class ManifestParser
         return false;
     }
 
-    private static BundleCapabilityImpl parseBundleSymbolicName(Module owner, Map headerMap)
+    private static BundleCapabilityImpl parseBundleSymbolicName(
+        BundleRevision owner, Map headerMap)
         throws BundleException
     {
         List<ParsedHeaderClause> clauses = parseStandardHeader(
@@ -1063,14 +1067,14 @@ public class ManifestParser
                 }
             }
 
-            // Create a module capability and return it.
+            // Create a require capability and return it.
             String symName = (String) clauses.get(0).m_paths.get(0);
             Map<String, Object> attrs = new HashMap<String, Object>(2);
             attrs.put(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, symName);
             attrs.put(Constants.BUNDLE_VERSION_ATTRIBUTE, bundleVersion);
             return new BundleCapabilityImpl(
                 owner,
-                BundleCapabilityImpl.MODULE_NAMESPACE,
+                BundleCapabilityImpl.BUNDLE_NAMESPACE,
                 clauses.get(0).m_dirs,
                 attrs);
         }
@@ -1079,7 +1083,7 @@ public class ManifestParser
     }
 
     private static List<BundleRequirementImpl> parseFragmentHost(
-        Logger logger, Module owner, Map headerMap)
+        Logger logger, BundleRevision owner, Map headerMap)
         throws BundleException
     {
         List<BundleRequirementImpl> reqs = new ArrayList();
@@ -1155,11 +1159,11 @@ public class ManifestParser
         return reqs;
     }
 
-    public static List<BundleCapabilityImpl> parseExportHeader(
-        Logger logger, Module owner, String header, String bsn, Version bv)
+    public static List<BundleCapability> parseExportHeader(
+        Logger logger, BundleRevision owner, String header, String bsn, Version bv)
     {
 
-        List<BundleCapabilityImpl> caps = null;
+        List<BundleCapability> caps = null;
         try
         {
             List<ParsedHeaderClause> exportClauses = parseStandardHeader(header);
@@ -1173,10 +1177,10 @@ public class ManifestParser
         return caps;
     }
 
-    private static List<BundleCapabilityImpl> convertExports(
-        List<ParsedHeaderClause> clauses, Module owner)
+    private static List<BundleCapability> convertExports(
+        List<ParsedHeaderClause> clauses, BundleRevision owner)
     {
-        List<BundleCapabilityImpl> capList = new ArrayList();
+        List<BundleCapability> capList = new ArrayList();
         for (int clauseIdx = 0; clauseIdx < clauses.size(); clauseIdx++)
         {
             for (int pathIdx = 0;
@@ -1232,7 +1236,7 @@ public class ManifestParser
     }
 
     private static List<BundleRequirementImpl> convertRequires(
-        List<ParsedHeaderClause> clauses, Module owner)
+        List<ParsedHeaderClause> clauses, BundleRevision owner)
     {
         List<BundleRequirementImpl> reqList = new ArrayList();
         for (int clauseIdx = 0; clauseIdx < clauses.size(); clauseIdx++)
@@ -1259,7 +1263,7 @@ public class ManifestParser
                 reqList.add(
                     new BundleRequirementImpl(
                         owner,
-                        BundleCapabilityImpl.MODULE_NAMESPACE,
+                        BundleCapabilityImpl.BUNDLE_NAMESPACE,
                         clauses.get(clauseIdx).m_dirs,
                         newAttrs));
             }
@@ -1303,7 +1307,7 @@ public class ManifestParser
 
     private void parseActivationPolicy(Map headerMap)
     {
-        m_activationPolicy = Module.EAGER_ACTIVATION;
+        m_activationPolicy = BundleRevisionImpl.EAGER_ACTIVATION;
 
         List<ParsedHeaderClause> clauses = parseStandardHeader(
             (String) headerMap.get(Constants.BUNDLE_ACTIVATIONPOLICY));
@@ -1316,7 +1320,7 @@ public class ManifestParser
             {
                 if (clauses.get(0).m_paths.get(clauseIdx).equals(Constants.ACTIVATION_LAZY))
                 {
-                    m_activationPolicy = Module.LAZY_ACTIVATION;
+                    m_activationPolicy = BundleRevisionImpl.LAZY_ACTIVATION;
                     for (Entry<String, String> entry : clauses.get(0).m_dirs.entrySet())
                     {
                         if (entry.getKey().equalsIgnoreCase(Constants.INCLUDE_DIRECTIVE))

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java?rev=1095097&r1=1095096&r2=1095097&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java Tue Apr 19 14:16:59 2011
@@ -26,7 +26,6 @@ import java.util.Map;
 import java.util.List;
 import java.util.StringTokenizer;
 import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.resolver.Module;
 import org.apache.felix.framework.util.Util;
 import org.apache.felix.framework.util.manifestparser.ManifestParser;
 import org.osgi.framework.Constants;
@@ -35,7 +34,7 @@ import org.osgi.framework.wiring.BundleR
 
 public class BundleCapabilityImpl implements BundleCapability
 {
-    public static final String MODULE_NAMESPACE = "module";
+    public static final String BUNDLE_NAMESPACE = "module";
     public static final String HOST_NAMESPACE = "host";
     public static final String PACKAGE_NAMESPACE = "package";
     public static final String SINGLETON_NAMESPACE = "singleton";
@@ -43,7 +42,7 @@ public class BundleCapabilityImpl implem
     public static final String PACKAGE_ATTR = "package";
     public static final String VERSION_ATTR = "version";
 
-    private final Module m_module;
+    private final BundleRevision m_revision;
     private final String m_namespace;
     private final Map<String, String> m_dirs;
     private final Map<String, Object> m_attrs;
@@ -52,11 +51,11 @@ public class BundleCapabilityImpl implem
     private final List<List<String>> m_excludeFilter;
     private final Set<String> m_mandatory;
 
-    public BundleCapabilityImpl(Module module, String namespace,
+    public BundleCapabilityImpl(BundleRevision revision, String namespace,
         Map<String, String> dirs, Map<String, Object> attrs)
     {
         m_namespace = namespace;
-        m_module = module;
+        m_revision = revision;
         m_dirs = Collections.unmodifiableMap(dirs);
         m_attrs = Collections.unmodifiableMap(attrs);
 
@@ -128,14 +127,9 @@ public class BundleCapabilityImpl implem
         }
     }
 
-    public Module getModule()
-    {
-        return m_module;
-    }
-
     public BundleRevision getRevision()
     {
-        return null;
+        return m_revision;
     }
 
     public String getNamespace()
@@ -197,15 +191,15 @@ public class BundleCapabilityImpl implem
 
     public String toString()
     {
-        if (m_module == null)
+        if (m_revision == null)
         {
             return m_attrs.toString();
         }
         if (m_namespace.equals(PACKAGE_NAMESPACE))
         {
-            return "[" + m_module + "] "
+            return "[" + m_revision + "] "
                 + m_namespace + "; " + m_attrs.get(PACKAGE_ATTR);
         }
-        return "[" + m_module + "] " + m_namespace + "; " + m_attrs;
+        return "[" + m_revision + "] " + m_namespace + "; " + m_attrs;
     }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java?rev=1095097&r1=1095096&r2=1095097&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java Tue Apr 19 14:16:59 2011
@@ -20,13 +20,11 @@ package org.apache.felix.framework.wirin
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import org.apache.felix.framework.capabilityset.CapabilitySet;
 import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.resolver.Module;
 import org.apache.felix.framework.util.VersionRange;
 import org.osgi.framework.Constants;
 import org.osgi.framework.wiring.BundleCapability;
@@ -35,7 +33,7 @@ import org.osgi.framework.wiring.BundleR
 
 public class BundleRequirementImpl implements BundleRequirement
 {
-    private final Module m_module;
+    private final BundleRevision m_revision;
     private final String m_namespace;
     private final SimpleFilter m_filter;
     private final boolean m_optional;
@@ -43,10 +41,10 @@ public class BundleRequirementImpl imple
     private final Map<String, Object> m_attrs;
 
     public BundleRequirementImpl(
-        Module module, String namespace,
+        BundleRevision revision, String namespace,
         Map<String, String> dirs, Map<String, Object> attrs)
     {
-        m_module = module;
+        m_revision = revision;
         m_namespace = namespace;
         m_dirs = Collections.unmodifiableMap(dirs);
         m_attrs = Collections.unmodifiableMap(attrs);
@@ -77,14 +75,9 @@ public class BundleRequirementImpl imple
         return m_attrs;
     }
 
-    public Module getModule()
-    {
-        return m_module;
-    }
-
     public BundleRevision getRevision()
     {
-        throw new UnsupportedOperationException("Not supported yet.");
+        return m_revision;
     }
 
     public boolean matches(BundleCapability cap)
@@ -104,7 +97,7 @@ public class BundleRequirementImpl imple
 
     public String toString()
     {
-        return "[" + m_module + "] " + m_namespace + "; " + getFilter().toString();
+        return "[" + m_revision + "] " + m_namespace + "; " + getFilter().toString();
     }
 
     private static SimpleFilter convertToFilter(Map<String, Object> attrs)

Added: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/FelixBundleWire.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/FelixBundleWire.java?rev=1095097&view=auto
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/FelixBundleWire.java (added)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/FelixBundleWire.java Tue Apr 19 14:16:59 2011
@@ -0,0 +1,83 @@
+/*
+ * 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.wiring;
+
+import java.net.URL;
+import java.util.Enumeration;
+import org.apache.felix.framework.resolver.ResourceNotFoundException;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
+
+public interface FelixBundleWire extends BundleWire
+{
+    public BundleRevision getRequirer();
+
+    public BundleRevision getProvider();
+
+    /**
+     * 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.
+    **/
+    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.
+    **/
+    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.
+    **/
+    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.
+    **/
+    Enumeration getResources(String name) throws ResourceNotFoundException;
+}
\ No newline at end of file

Copied: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/FelixBundleWireImpl.java (from r1091796, felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/WireImpl.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/FelixBundleWireImpl.java?p2=felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/FelixBundleWireImpl.java&p1=felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/WireImpl.java&r1=1091796&r2=1095097&rev=1095097&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/WireImpl.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/wiring/FelixBundleWireImpl.java Tue Apr 19 14:16:59 2011
@@ -16,56 +16,76 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.felix.framework.resolver;
+package org.apache.felix.framework.wiring;
 
+import org.apache.felix.framework.resolver.*;
 import java.net.URL;
 import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.felix.framework.BundleRevisionImpl;
 import org.apache.felix.framework.util.Util;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
 
-class WireImpl implements Wire
+// TODO: OSGi R4.3 - Should this be in framework package?
+public class FelixBundleWireImpl implements FelixBundleWire
 {
-    private final Module m_importer;
-    private final BundleRequirementImpl m_req;
-    private final Module m_exporter;
-    private final BundleCapabilityImpl m_cap;
-
-    public WireImpl(Module importer, BundleRequirementImpl ip,
-        Module exporter, BundleCapabilityImpl cap)
-    {
-        m_importer = importer;
-        m_req = ip;
-        m_exporter = exporter;
+    private final BundleRevision m_requirer;
+    private final BundleRequirement m_req;
+    private final BundleRevision m_provider;
+    private final BundleCapability m_cap;
+    private volatile Set<String> m_packages;
+
+    public FelixBundleWireImpl(BundleRevision requirer, BundleRequirement req,
+        BundleRevision provider, BundleCapability cap)
+    {
+        m_requirer = requirer;
+        m_req = req;
+        m_provider = provider;
         m_cap = cap;
     }
 
-    public Module getImporter()
+    public BundleRevision getRequirer()
+    {
+        return m_requirer;
+    }
+
+    public BundleWiring getRequirerWiring()
     {
-        return m_importer;
+        return m_requirer.getWiring();
     }
 
-    public BundleRequirementImpl getRequirement()
+    public BundleRequirement getRequirement()
     {
         return m_req;
     }
 
-    public Module getExporter()
+    public BundleRevision getProvider()
     {
-        return m_exporter;
+        return m_provider;
     }
 
-    public BundleCapabilityImpl getCapability()
+    public BundleWiring getProviderWiring()
+    {
+        return m_provider.getWiring();
+    }
+
+    public BundleCapability getCapability()
     {
         return m_cap;
     }
 
     public String toString()
     {
-        return "[" + m_importer + "] "
-            + m_req.getNamespace() + "; "
-            + m_req.getFilter() + " -> "
-            + "[" + m_exporter + "]";
+        return "[" + m_requirer + "] "
+            + m_req
+            + " -> "
+            + "[" + m_provider + "]";
     }
 
     /* (non-Javadoc)
@@ -73,8 +93,22 @@ class WireImpl implements Wire
      */
     public boolean hasPackage(String pkgName)
     {
-        return (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-            m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName));
+        boolean result = false;
+        if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+        {
+            result = m_cap.getAttributes()
+                .get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName); 
+        }
+        else if (m_cap.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+        {
+            if (m_packages == null)
+            {
+                m_packages = calculateRequiredPackages(
+                    m_provider.getWiring(), new HashSet<String>());
+            }
+            result = m_packages.contains(pkgName);
+        }
+        return result;
     }
 
     /* (non-Javadoc)
@@ -87,27 +121,42 @@ class WireImpl implements Wire
         // Get the package of the target class.
         String pkgName = Util.getClassPackage(name);
 
-        // Only check when the package of the target class is
-        // the same as the package for the wire.
-        if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-            m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
-        {
-            // Check the include/exclude filters from the target package
-            // to make sure that the class is actually visible. We delegate
-            // to the exporting module, rather than its content, so it can
-            // it can follow any internal wires it may have (e.g., if the
-            // package has multiple sources).
-            if (m_cap.isIncluded(name))
-            {
-                clazz = m_exporter.getClassByDelegation(name);
-            }
-
-            // If no class was found, then we must throw an exception
-            // since the exporter for this package did not contain the
-            // requested class.
-            if (clazz == null)
+        // Only check if this wire provides the target package.
+        if (hasPackage(pkgName))
+        {
+            String namespace = m_cap.getNamespace();
+            if (namespace.equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
             {
-                throw new ClassNotFoundException(name);
+                // Check the include/exclude filters from the target package
+                // to make sure that the class is actually visible. We delegate
+                // to the exporting revision, rather than its content, so it can
+                // it can follow any internal wires it may have (e.g., if the
+                // package has multiple sources).
+                if (((BundleCapabilityImpl) m_cap).isIncluded(name))
+                {
+                    clazz = ((BundleRevisionImpl) m_provider).getClassByDelegation(name);
+                }
+
+                // If no class was found, then we must throw an exception
+                // since the exporter for this package did not contain the
+                // requested class.
+                if (clazz == null)
+                {
+                    throw new ClassNotFoundException(name);
+                }
+            }
+            else if (namespace.equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+            {
+                try
+                {
+                    clazz = ((BundleRevisionImpl) m_provider).getClassByDelegation(name);
+                }
+                catch (ClassNotFoundException ex)
+                {
+                    // Do not throw the exception here, since we want
+                    // to continue search other package sources and
+                    // ultimately the revision's own content.
+                }
             }
         }
 
@@ -124,23 +173,33 @@ class WireImpl implements Wire
         // Get the package of the target class.
         String pkgName = Util.getResourcePackage(name);
 
-        // Only check when the package of the target resource is
-        // the same as the package for the wire.
-        if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-            m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
-        {
-            // 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).
-            url = m_exporter.getResourceByDelegation(name);
-
-            // If no resource was found, then we must throw an exception
-            // since the exporter for this package did not contain the
-            // requested class.
-            if (url == null)
+        // Only check if this wire provides the target package.
+        if (hasPackage(pkgName))
+        {
+            String namespace = m_cap.getNamespace();
+            if (namespace.equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+            {
+                // Delegate to the exporting revision, rather than its
+                // content, so that it can follow any internal wires it may have
+                // (e.g., if the package has multiple sources).
+                url = ((BundleRevisionImpl) m_provider).getResourceByDelegation(name);
+
+                // If no resource was found, then we must throw an exception
+                // since the exporter for this package did not contain the
+                // requested class.
+                if (url == null)
+                {
+                    throw new ResourceNotFoundException(name);
+                }
+            }
+            else if (namespace.equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
             {
-                throw new ResourceNotFoundException(name);
+                url = ((BundleRevisionImpl) m_provider).getResourceByDelegation(name);
+
+                // Don't throw ResourceNotFoundException because require-bundle
+                // dependencies support split packages.
             }
+
         }
 
         return url;
@@ -156,22 +215,64 @@ class WireImpl implements Wire
         // Get the package of the target class.
         String pkgName = Util.getResourcePackage(name);
 
-        // Only check when the package of the target resource is
-        // the same as the package for the wire.
-        if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-            m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
-        {
-            urls = m_exporter.getResourcesByDelegation(name);
-
-            // If no resource was found, then we must throw an exception
-            // since the exporter for this package did not contain the
-            // requested class.
-            if ((urls == null) || !urls.hasMoreElements())
+        // Only check if this wire provides the target package.
+        if (hasPackage(pkgName))
+        {
+            String namespace = m_cap.getNamespace();
+            if (namespace.equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+            {
+                urls = ((BundleRevisionImpl) m_provider).getResourcesByDelegation(name);
+
+                // If no resource was found, then we must throw an exception
+                // since the exporter for this package did not contain the
+                // requested class.
+                if ((urls == null) || !urls.hasMoreElements())
+                {
+                    throw new ResourceNotFoundException(name);
+                }
+            }
+            else if (namespace.equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
             {
-                throw new ResourceNotFoundException(name);
+                urls = ((BundleRevisionImpl) m_provider).getResourcesByDelegation(name);
+
+                // Don't throw ResourceNotFoundException because require-bundle
+                // dependencies support split packages.
             }
         }
 
         return urls;
     }
+
+    private static Set<String> calculateRequiredPackages(
+        BundleWiring providerWiring, Set<String> packages)
+    {
+// TODO: OSGi R4.3 - This might be calcualted differently when BundleWiring
+//       returns the proper information.
+
+        // Add exported packages.
+        for (BundleCapability cap : providerWiring.getCapabilities(null))
+        {
+            if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+            {
+                packages.add(
+                    (String) cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR));
+            }
+        }
+
+        // Add re-exported packages for any required bundle dependencies
+        // that are re-exported.
+        for (BundleWire bw : providerWiring.getRequiredWires(null))
+        {
+            if (bw.getRequirement().getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+            {
+                String dir =
+                    bw.getRequirement().getDirectives().get(Constants.VISIBILITY_DIRECTIVE);
+                if ((dir != null) && (dir.equals(Constants.VISIBILITY_REEXPORT)))
+                {
+                    calculateRequiredPackages(bw.getProviderWiring(), packages);
+                }
+            }
+        }
+        return packages;
+    }
 }
\ No newline at end of file



Mime
View raw message