felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r392939 - in /incubator/felix/trunk: org.apache.felix.framework/src/main/java/org/apache/felix/framework/ org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ org.apache.felix.main/src/main/resources/
Date Mon, 10 Apr 2006 12:56:15 GMT
Author: rickhall
Date: Mon Apr 10 05:56:14 2006
New Revision: 392939

URL: http://svn.apache.org/viewcvs?rev=392939&view=rev
Log:
Implemented boot delegation property (FELIX-25) and modified the default
config file property to include "com.sun.*" and "sun.*" packages.

Modified:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
    incubator/felix/trunk/org.apache.felix.main/src/main/resources/config.properties

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java?rev=392939&r1=392938&r2=392939&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
Mon Apr 10 05:56:14 2006
@@ -266,7 +266,7 @@
         }
 
         // Create search policy for module loader.
-        m_policyCore = new R4SearchPolicyCore(m_logger);
+        m_policyCore = new R4SearchPolicyCore(m_logger, m_config);
 
         // Add a resolver listener to the search policy
         // so that we will be notified when modules are resolved

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java?rev=392939&r1=392938&r2=392939&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
Mon Apr 10 05:56:14 2006
@@ -20,19 +20,24 @@
 import java.util.*;
 
 import org.apache.felix.framework.Logger;
-import org.apache.felix.framework.util.SecurityManagerEx;
-import org.apache.felix.framework.util.Util;
+import org.apache.felix.framework.util.*;
 import org.apache.felix.moduleloader.*;
+import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
 
 public class R4SearchPolicyCore implements ModuleListener
 {
     private Logger m_logger = null;
+    private PropertyResolver m_config = null;
     private IModuleFactory m_factory = null;
     private Map m_availPkgMap = new HashMap();
     private Map m_inUsePkgMap = new HashMap();
     private Map m_moduleDataMap = new HashMap();
 
+    // Boot delegation packages.
+    private String[] m_bootPkgs = null;
+    private boolean[] m_bootPkgWildcards = null;
+
     // Listener-related instance variables.
     private static final ResolveListener[] m_emptyListeners = new ResolveListener[0];
     private ResolveListener[] m_listeners = m_emptyListeners;
@@ -43,9 +48,27 @@
     // Re-usable security manager for accessing class context.
     private static SecurityManagerEx m_sm = new SecurityManagerEx();
 
-    public R4SearchPolicyCore(Logger logger)
+    public R4SearchPolicyCore(Logger logger, PropertyResolver config)
     {
         m_logger = logger;
+        m_config = config;
+
+        // Read the boot delegation property and parse it.
+        String s = m_config.get(Constants.FRAMEWORK_BOOTDELEGATION);
+        s = (s == null) ? "java.*" : s + ",java.*";
+        StringTokenizer st = new StringTokenizer(s, " ,");
+        m_bootPkgs = new String[st.countTokens()];
+        m_bootPkgWildcards = new boolean[m_bootPkgs.length];
+        for (int i = 0; i < m_bootPkgs.length; i++)
+        {
+            s = st.nextToken();
+            if (s.endsWith("*"))
+            {
+                m_bootPkgWildcards[i] = true;
+                s = s.substring(0, s.length() - 1);
+            }
+            m_bootPkgs[i] = s;
+        }
     }
 
     public IModuleFactory getModuleFactory()
@@ -271,11 +294,23 @@
         // Get the package of the target class.
         String pkgName = Util.getClassPackage(name);
 
-        // Load all "java.*" classes from parent class loader;
-        // these packages cannot be provided by other bundles.
-        if (pkgName.startsWith("java."))
-        {
-            return getClass().getClassLoader().loadClass(name);
+        // Delegate any packages listed in the boot delegation
+        // property to the parent class loader.
+        for (int i = 0; i < m_bootPkgs.length; i++)
+        {
+            // A wildcarded boot delegation package will be in the form of "foo.",
+            // so if the package is wildcarded do a startsWith() or a regionMatches()
+            // to ignore the trailing "." to determine if the request should be
+            // delegated to the paren class loader. If the package is not wildcarded,
+            // then simply do an equals() test to see if the request should be
+            // delegated to the parent class loader.
+            if ((m_bootPkgWildcards[i] &&
+                    (pkgName.startsWith(m_bootPkgs[i]) ||
+                    m_bootPkgs[i].regionMatches(0, pkgName, 0, m_bootPkgs[i].length() - 1)))
+                || (!m_bootPkgWildcards[i] && m_bootPkgs[i].equals(pkgName)))
+            {
+                return getClass().getClassLoader().loadClass(name);
+            }
         }
 
         // Look in the module's imports.
@@ -391,7 +426,7 @@
                 break;
             }
         }
-        
+
         throw new ClassNotFoundException(name);
     }
 
@@ -425,11 +460,23 @@
         // Get the package of the target class.
         String pkgName = Util.getResourcePackage(name);
 
-        // Load all "java.*" classes from parent class loader;
-        // these packages cannot be provided by other bundles.
-        if (pkgName.startsWith("java."))
-        {
-            return getClass().getClassLoader().getResource(name);
+        // Delegate any packages listed in the boot delegation
+        // property to the parent class loader.
+        for (int i = 0; i < m_bootPkgs.length; i++)
+        {
+            // A wildcarded boot delegation package will be in the form of "foo.",
+            // so if the package is wildcarded do a startsWith() or a regionMatches()
+            // to ignore the trailing "." to determine if the request should be
+            // delegated to the paren class loader. If the package is not wildcarded,
+            // then simply do an equals() test to see if the request should be
+            // delegated to the parent class loader.
+            if ((m_bootPkgWildcards[i] &&
+                    (pkgName.startsWith(m_bootPkgs[i]) ||
+                    m_bootPkgs[i].regionMatches(0, pkgName, 0, m_bootPkgs[i].length() - 1)))
+                || (!m_bootPkgWildcards[i] && m_bootPkgs[i].equals(pkgName)))
+            {
+                return getClass().getClassLoader().getResource(name);
+            }
         }
 
         // Look in the module's imports.
@@ -1069,8 +1116,6 @@
                 node.m_candidates[node.m_idx],
                 candidatePkg,
                 new HashMap());
-//System.out.println("MODULE " + rootModule + " USES    " + usesMap);
-//System.out.println("CANDIDATE " + node.m_candidates[node.m_idx] + " USES " + candUsesMap);
 
             // Iterate through the root module's current set of transitive
             // "uses" constraints and compare them with the candidate's

Modified: incubator/felix/trunk/org.apache.felix.main/src/main/resources/config.properties
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.main/src/main/resources/config.properties?rev=392939&r1=392938&r2=392939&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.main/src/main/resources/config.properties (original)
+++ incubator/felix/trunk/org.apache.felix.main/src/main/resources/config.properties Mon Apr
10 05:56:14 2006
@@ -9,6 +9,7 @@
  javax.swing.tree; \
  javax.swing.text; \
  version=1.4
+org.osgi.framework.bootdelegation=sun.*,com.sun.*
 #felix.cache.profile=foo
 felix.auto.start.1= \
  file:bundle/org.apache.felix.shell-${pom.version}.jar \



Mime
View raw message