felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r467664 - in /incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy: R4SearchPolicyCore.java R4WireModule.java
Date Wed, 25 Oct 2006 14:24:49 GMT
Author: rickhall
Date: Wed Oct 25 07:24:48 2006
New Revision: 467664

URL: http://svn.apache.org/viewvc?view=rev&rev=467664
Log:
Added support for "module wires", which now allows loading from classes
using require-bundle. This has only been tested on a simple example, but
it appears to work in a preliminary way. There is still a long way to go
to get this polished and into the trunk...it is a lot of work for a feature
that we will encourage people not to use. :-( Oh well.

Added:
    incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java
  (with props)
Modified:
    incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java

Modified: incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java?view=diff&rev=467664&r1=467663&r2=467664
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
(original)
+++ incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
Wed Oct 25 07:24:48 2006
@@ -602,7 +602,6 @@
             // this map will be resolved, only the target module and
             // any candidates selected to resolve its imports and the
             // transitive imports this implies.
-try {
             populateResolverMap(resolverMap, rootModule);
 
             // The next step is to use the resolver map to determine if
@@ -627,11 +626,6 @@
             // The resolved module wire map maps a module to its array of
             // wires.
             resolvedModuleWireMap = createWires(resolverMap, rootModule);
-} catch (NullPointerException ex) {
-    System.out.println("GOT IT");
-    ex.printStackTrace();
-    throw ex;
-}
 
 //dumpAvailablePackages();
 //dumpUsedPackages();
@@ -1242,11 +1236,11 @@
         return pkgMap;
     }
 
-    private class PackageSource
+    protected class PackageSource
     {
         public String m_name = null;
         public List m_sourceList = new ArrayList();
-        public Map m_impliedMap = new HashMap();
+
         public PackageSource(String name)
         {
             m_name = name;
@@ -1266,8 +1260,6 @@
                 ResolverCandidate rc2 = (ResolverCandidate) ps.m_sourceList.get(i);
                 if (rc1.m_module != rc2.m_module)
                 {
-System.out.println(rc1.m_capability.getProperties().get(ICapability.PACKAGE_PROPERTY)
-    + " " +rc1.m_module + " != " + rc2.m_module);
                     return false;
                 }
             }
@@ -1295,20 +1287,6 @@
                 ResolverCandidate rc = (ResolverCandidate) m_sourceList.get(i);
                 sb.append(rc.m_module);
             }
-            if (m_impliedMap.size() > 0)
-            {
-                sb.append("\n");
-                sb.append(padding);
-                sb.append("IMPLIES:\n");
-                for (Iterator i = m_impliedMap.values().iterator(); i.hasNext(); )
-                {
-                    ((PackageSource) i.next()).toString(padding + "  ", sb);
-                    if (i.hasNext())
-                    {
-                        sb.append("\n");
-                    }
-                }
-            }
             return sb;
         }
     }
@@ -1400,7 +1378,7 @@
                 {
                     ICapability[] inUseCaps = (ICapability[]) m_inUseCapMap.get(module);
                     inUseCaps = addCapabilityToArray(inUseCaps, caps[capIdx]);
-                    m_inUseCapMap.put(module, inUseCaps);                
+                    m_inUseCapMap.put(module, inUseCaps);
                 }
             }
         }
@@ -1432,10 +1410,23 @@
             ResolverNode node = (ResolverNode) nodeList.get(nodeIdx);
 
             // Add the candidate to the list of wires.
-            wires[nodeIdx] = new R4Wire(
-                importer,
-                node.m_candidates[node.m_idx].m_module,
-                node.m_candidates[node.m_idx].m_capability);
+            if (node.m_requirement.getNamespace().equals(ICapability.MODULE_NAMESPACE))
+            {
+                // TODO: ML - This is recalculating the package sources for the provider
module,
+                // which could be avoided since this was already calculated once.
+                wires[nodeIdx] = new R4WireModule(
+                    importer,
+                    node.m_candidates[node.m_idx].m_module,
+                    node.m_candidates[node.m_idx].m_capability,
+                    calculateModulePackages(node.m_candidates[node.m_idx].m_module, resolverMap));
+            }
+            else
+            {
+                wires[nodeIdx] = new R4Wire(
+                    importer,
+                    node.m_candidates[node.m_idx].m_module,
+                    node.m_candidates[node.m_idx].m_capability);
+            }
 
             // Create the wires for the selected candidate module.
             wireMap = populateWireMap(

Added: incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java?view=auto&rev=467664
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java
(added)
+++ incubator/felix/sandbox/rickhall/framework-require-bundle/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java
Wed Oct 25 07:24:48 2006
@@ -0,0 +1,146 @@
+/*
+ *   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.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import org.apache.felix.framework.searchpolicy.R4SearchPolicyCore.PackageSource;
+import org.apache.felix.framework.searchpolicy.R4SearchPolicyCore.ResolverCandidate;
+
+import org.apache.felix.framework.util.Util;
+import org.apache.felix.moduleloader.*;
+
+public class R4WireModule implements IWire
+{
+    private IModule m_importer = null;
+    private IModule m_exporter = null;
+    private ICapability m_capability = null;
+    private Map m_pkgMap = null;
+    
+    public R4WireModule(IModule importer, IModule exporter, ICapability capability, Map pkgMap)
+    {
+        m_importer = importer;
+        m_exporter = exporter;
+        m_capability = capability;
+        m_pkgMap = pkgMap;
+
+        System.out.println("Package source for wire:");
+        for (Iterator i = pkgMap.entrySet().iterator(); i.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) i.next();
+            PackageSource ps = (PackageSource) entry.getValue();
+            System.out.println(ps);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getImportingModule()
+     */
+    public IModule getImporter()
+    {
+        return m_importer;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getExportingModule()
+     */
+    public IModule getExporter()
+    {
+        return m_exporter;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getExport()
+     */
+    public ICapability getCapability()
+    {
+        return m_capability;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
+     */
+    public Class getClass(String name) throws ClassNotFoundException
+    {
+        if (m_capability.getNamespace().equals(ICapability.MODULE_NAMESPACE))
+        {
+            Class clazz = null;
+
+            // Get the package of the target class.
+            String pkgName = Util.getClassPackage(name);
+
+            PackageSource ps = (PackageSource) m_pkgMap.get(pkgName);
+            for (int srcIdx = 0; (ps != null) && (srcIdx < ps.m_sourceList.size());
srcIdx++)
+            {
+                ResolverCandidate rc = (ResolverCandidate) ps.m_sourceList.get(srcIdx);
+                if ((rc.m_module == m_importer) ||
+                    ((rc.m_capability instanceof R4ExportCapability) &&
+                    ((R4ExportCapability) rc.m_capability).isIncluded(name)))
+                {
+                    clazz = rc.m_module.getContentLoader().getClass(name);
+                    if (clazz != null)
+                    {
+                        return clazz;
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    /* (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_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE) &&
+            m_capability.getProperties().get(ICapability.PACKAGE_PROPERTY).equals(pkgName))
+        {
+            url = m_exporter.getContentLoader().getResource(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;
+    }
+    
+    public String toString()
+    {
+        if (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
+        {
+            return m_importer + " -> "
+                + m_capability.getProperties().get(ICapability.PACKAGE_PROPERTY)
+                + " -> " + m_exporter;
+        }
+        return m_importer + " -> " + m_capability + " -> " + m_exporter;
+    }
+}
\ No newline at end of file

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



Mime
View raw message