felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r374660 [2/2] - in /incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix: framework/ framework/cache/ framework/searchpolicy/ framework/util/ moduleloader/ moduleloader/search/
Date Fri, 03 Feb 2006 12:55:44 GMT
Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java Fri Feb  3 04:54:52 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   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.
@@ -23,8 +23,10 @@
 import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
 
-import org.apache.felix.framework.LogWrapper;
+import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.util.*;
+import org.apache.felix.framework.util.Util;
+import org.apache.felix.moduleloader.*;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 
@@ -53,7 +55,7 @@
     private static final transient String INSTALLED_STATE = "installed";
     private static final transient String UNINSTALLED_STATE = "uninstalled";
 
-    private LogWrapper m_logger = null;
+    private Logger m_logger = null;
     private long m_id = -1;
     private File m_dir = null;
     private String m_location = null;
@@ -64,7 +66,8 @@
     private long m_refreshCount = -1;
     private int m_revisionCount = -1;
 
-    public DefaultBundleArchive(LogWrapper logger, File dir, long id, String location, InputStream is)    
+    public DefaultBundleArchive(
+        Logger logger, File dir, long id, String location, InputStream is)    
         throws Exception
     {
         this(logger, dir, id);
@@ -80,14 +83,14 @@
             if (!deleteDirectoryTree(dir))
             {
                 m_logger.log(
-                    LogWrapper.LOG_ERROR,
+                    Logger.LOG_ERROR,
                     "Unable to delete the archive directory: " + id);
             }
             throw ex;
         }
     }
 
-    public DefaultBundleArchive(LogWrapper logger, File dir, long id)
+    public DefaultBundleArchive(Logger logger, File dir, long id)
     {
         m_logger = logger;
         m_dir = dir;
@@ -133,7 +136,7 @@
             if (!m_dir.mkdir())
             {
                 m_logger.log(
-                    LogWrapper.LOG_ERROR,
+                    Logger.LOG_ERROR,
                     "DefaultBundleArchive: Unable to create archive directory.");
                 throw new IOException("Unable to create archive directory.");
             }
@@ -152,7 +155,7 @@
             if (!revisionDir.mkdir())
             {
                 m_logger.log(
-                    LogWrapper.LOG_ERROR,
+                    Logger.LOG_ERROR,
                     "DefaultBundleArchive: Unable to create revision directory.");
                 throw new IOException("Unable to create revision directory.");
             }
@@ -354,7 +357,7 @@
         catch (IOException ex)
         {
             m_logger.log(
-                LogWrapper.LOG_ERROR,
+                Logger.LOG_ERROR,
                 "DefaultBundleArchive: Unable to record state: " + ex);
             throw ex;
         }
@@ -463,7 +466,7 @@
         catch (IOException ex)
         {
             m_logger.log(
-                LogWrapper.LOG_ERROR,
+                Logger.LOG_ERROR,
                 "DefaultBundleArchive: Unable to record start leel: " + ex);
             throw ex;
         }
@@ -521,7 +524,7 @@
         }
     }
 
-    public BundleActivator getActivator(ClassLoader loader)
+    public BundleActivator getActivator(IContentLoader contentLoader)
         throws Exception
     {
         if (System.getSecurityManager() != null)
@@ -530,7 +533,7 @@
             {
                 return (BundleActivator) AccessController.doPrivileged(
                     new PrivilegedAction(
-                        PrivilegedAction.GET_ACTIVATOR_ACTION, this, loader));
+                        PrivilegedAction.GET_ACTIVATOR_ACTION, this, contentLoader));
             }
             catch (PrivilegedActionException ex)
             {
@@ -539,11 +542,11 @@
         }
         else
         {
-            return getActivatorUnchecked(loader);
+            return getActivatorUnchecked(contentLoader);
         }
     }
 
-    private BundleActivator getActivatorUnchecked(ClassLoader loader)
+    private BundleActivator getActivatorUnchecked(IContentLoader contentLoader)
         throws Exception
     {
         // Get bundle activator file.
@@ -559,14 +562,14 @@
         try
         {
             is = new FileInputStream(activatorFile);
-            ois = new ObjectInputStreamX(is, loader);
+            ois = new ObjectInputStreamX(is, contentLoader);
             Object o = ois.readObject();
             return (BundleActivator) o;
         }
         catch (Exception ex)
         {
             m_logger.log(
-                LogWrapper.LOG_ERROR,
+                Logger.LOG_ERROR,
                 "DefaultBundleArchive: Trying to deserialize - " + ex);
         }
         finally
@@ -623,7 +626,7 @@
         catch (IOException ex)
         {
             m_logger.log(
-                LogWrapper.LOG_ERROR,
+                Logger.LOG_ERROR,
                 "DefaultBundleArchive: Unable to serialize activator - " + ex);
             throw ex;
         }
@@ -741,16 +744,28 @@
         return new JarFile(bundleJar);
     }
 
-    public String[] getClassPath(int revision)
+    private IContent getContentUnchecked(int revision)
         throws Exception
     {
+        // Get the revision directory.
+        File revisionDir = new File(
+            m_dir, REVISION_DIRECTORY + getRefreshCount() + "." + revision);
+        // Return a content object for the bundle itself.
+        return new JarContent(new File(revisionDir, BUNDLE_JAR_FILE));
+    }
+
+    public IContent getContent(int revision)
+        throws Exception
+    {
+        IContent content = null;
+    
         if (System.getSecurityManager() != null)
         {
             try
             {
-                return (String []) AccessController.doPrivileged(
+                content = (IContent) AccessController.doPrivileged(
                     new PrivilegedAction(
-                        PrivilegedAction.GET_CLASS_PATH_ACTION, this, revision));
+                        PrivilegedAction.GET_CONTENT_ACTION, this, revision));
             }
             catch (PrivilegedActionException ex)
             {
@@ -759,16 +774,24 @@
         }
         else
         {
-            return getClassPathUnchecked(revision);
+            content = getContentUnchecked(revision);
         }
+    
+        return content;
     }
 
-    private String[] getClassPathUnchecked(int revision)
+    private IContent[] getContentPathUnchecked(int revision)
         throws Exception
     {
+        // Creating the content path entails examining the bundle's
+        // class path to determine whether the bundle JAR file itself
+        // is on the bundle's class path and then creating content
+        // objects for everything on the class path.
+
         // Get the revision directory.
         File revisionDir = new File(
             m_dir, REVISION_DIRECTORY + getRefreshCount() + "." + revision);
+        File embedDir = new File(revisionDir, EMBEDDED_DIRECTORY);
 
         // Get the bundle's manifest header.
         Map map = getManifestHeader(revision);
@@ -778,75 +801,79 @@
         }
 
         // Find class path meta-data.
-        String classPath = null;
+        String classPathString = null;
         Iterator iter = map.entrySet().iterator();
-        while ((classPath == null) && iter.hasNext())
+        while ((classPathString == null) && iter.hasNext())
         {
             Map.Entry entry = (Map.Entry) iter.next();
             if (entry.getKey().toString().toLowerCase().equals(
                 FelixConstants.BUNDLE_CLASSPATH.toLowerCase()))
             {
-                classPath = entry.getValue().toString();
+                classPathString = entry.getValue().toString();
             }
         }
 
         // Parse the class path into strings.
         String[] classPathStrings = Util.parseDelimitedString(
-            classPath, FelixConstants.CLASS_PATH_SEPARATOR);
+            classPathString, FelixConstants.CLASS_PATH_SEPARATOR);
 
         if (classPathStrings == null)
         {
             classPathStrings = new String[0];
         }
 
-        // Now, check for "." in the class path.
-        boolean includeDot = false;
-        for (int i = 0; !includeDot && (i < classPathStrings.length); i++)
+        // Create the bundles class path.
+        IContent self = new JarContent(new File(revisionDir, BUNDLE_JAR_FILE));
+        IContent[] classPath = new IContent[classPathStrings.length];
+        for (int i = 0; i < classPathStrings.length; i++)
         {
             if (classPathStrings[i].equals(FelixConstants.CLASS_PATH_DOT))
             {
-                includeDot = true;
+                classPath[i] = self;
             }
-        }
-
-        // Include all JARs in the embedded jar directory, since they
-        // were extracted when the bundle was initially saved.
-        File embedDir = new File(revisionDir, EMBEDDED_DIRECTORY);
-        String[] paths = null;
-        if (embedDir.exists())
-        {
-            // The size of the paths array is the number of
-            // embedded JAR files plus one, if we need to include
-            // ".", otherwise it is just the number of JAR files.
-            // If "." is included, then it will be added to the
-            // first place in the path array below.
-            File[] children = embedDir.listFiles();
-            int size = (children == null) ? 0 : children.length;
-            size = (includeDot) ? size + 1 : size;
-            paths = new String[size];
-            for (int i = 0; i < children.length; i++)
-            {
-                // If we are including "." then skip the first slot,
-                // because this is where we will put the bundle JAR file.
-                paths[(includeDot) ? i + 1 : i] = children[i].getPath();
+            else
+            {
+                String jarName = (classPathStrings[i].lastIndexOf('/') >= 0)
+                    ? classPathStrings[i].substring(classPathStrings[i].lastIndexOf('/') + 1)
+                    : classPathStrings[i];
+                classPath[i] = new JarContent(new File(embedDir, jarName));
             }
         }
 
         // If there is nothing on the class path, then include
         // "." by default, as per the spec.
-        if ((paths == null) || (paths.length == 0))
+        if (classPath.length == 0)
         {
-            includeDot = true;
-            paths = new String[1];
+            classPath = new IContent[] { self };
         }
 
-        // Put the bundle jar file first, if included.
-        if (includeDot)
+        return classPath;
+    }
+
+    public IContent[] getContentPath(int revision)
+        throws Exception
+    {
+        IContent[] contents = null;
+
+        if (System.getSecurityManager() != null)
+        {
+            try
+            {
+                contents = (IContent[]) AccessController.doPrivileged(
+                    new PrivilegedAction(
+                        PrivilegedAction.GET_CONTENT_PATH_ACTION, this, revision));
+            }
+            catch (PrivilegedActionException ex)
+            {
+                throw ((PrivilegedActionException) ex).getException();
+            }
+        }
+        else
         {
-            paths[0] = revisionDir + File.separator + BUNDLE_JAR_FILE;
+            contents = getContentPathUnchecked(revision);
         }
 
-        return paths;
+        return contents;
     }
 
 //  TODO: This will need to consider security.
@@ -999,7 +1026,7 @@
         catch (IOException ex)
         {
             m_logger.log(
-                LogWrapper.LOG_ERROR,
+                Logger.LOG_ERROR,
                 "DefaultBundleArchive: Unable to write counter: " + ex);
             throw ex;
         }
@@ -1159,6 +1186,8 @@
         // Remove leading slash if present.
         jarPath = (jarPath.charAt(0) == '/') ? jarPath.substring(1) : jarPath;
         // Get only the JAR file name.
+// TODO: FIX THIS SO THAT IT CREATES DIRECTORIES TO AVOID NAME CLASHES,
+// DOING SO WILL IMPACT getContentLoaderUnchecked() METHOD ABOVE.
         String jarName = (jarPath.lastIndexOf('/') >= 0)
             ? jarPath.substring(jarPath.lastIndexOf('/') + 1) : jarPath;
 
@@ -1254,7 +1283,7 @@
                 {
                     // There is very little we can do here.
                     m_logger.log(
-                        LogWrapper.LOG_ERROR,
+                        Logger.LOG_ERROR,
                         "Unable to remove partial revision directory.", ex2);
                 }
             }
@@ -1368,16 +1397,17 @@
         private static final int SET_START_LEVEL_ACTION = 9;
         private static final int OPEN_BUNDLE_JAR_ACTION = 10;
         private static final int CREATE_DATA_DIR_ACTION = 11;
-        private static final int GET_CLASS_PATH_ACTION = 12;
-        private static final int GET_ACTIVATOR_ACTION = 13;
-        private static final int SET_ACTIVATOR_ACTION = 14;
+        private static final int GET_CONTENT_ACTION = 12;
+        private static final int GET_CONTENT_PATH_ACTION = 13;
+        private static final int GET_ACTIVATOR_ACTION = 14;
+        private static final int SET_ACTIVATOR_ACTION = 15;
 
         private int m_action = 0;
         private DefaultBundleArchive m_archive = null;
         private InputStream m_isArg = null;
         private int m_intArg = 0;
         private File m_fileArg = null;
-        private ClassLoader m_loaderArg = null;
+        private IContentLoader m_contentLoaderArg = null;
         private Object m_objArg = null;
 
         public PrivilegedAction(int action, DefaultBundleArchive archive)
@@ -1407,11 +1437,11 @@
             m_fileArg = fileArg;
         }
 
-        public PrivilegedAction(int action, DefaultBundleArchive archive, ClassLoader loaderArg)
+        public PrivilegedAction(int action, DefaultBundleArchive archive, IContentLoader contentLoaderArg)
         {
             m_action = action;
             m_archive = archive;
-            m_loaderArg = loaderArg;
+            m_contentLoaderArg = contentLoaderArg;
         }
 
         public PrivilegedAction(int action, DefaultBundleArchive archive, Object objArg)
@@ -1456,10 +1486,12 @@
                 case CREATE_DATA_DIR_ACTION:
                     m_archive.createDataDirectoryUnchecked(m_fileArg);
                     return null;
-                case GET_CLASS_PATH_ACTION:
-                    return m_archive.getClassPathUnchecked(m_intArg);
+                case GET_CONTENT_ACTION:
+                    return m_archive.getContentUnchecked(m_intArg);
+                case GET_CONTENT_PATH_ACTION:
+                    return m_archive.getContentPathUnchecked(m_intArg);
                 case GET_ACTIVATOR_ACTION:
-                    return m_archive.getActivatorUnchecked(m_loaderArg);
+                    return m_archive.getActivatorUnchecked(m_contentLoaderArg);
                 case SET_ACTIVATOR_ACTION:
                     m_archive.setActivatorUnchecked(m_objArg);
                     return null;

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleCache.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleCache.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleCache.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/DefaultBundleCache.java Fri Feb  3 04:54:52 2006
@@ -18,7 +18,7 @@
 
 import java.io.*;
 
-import org.apache.felix.framework.LogWrapper;
+import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.util.PropertyResolver;
 
 /**
@@ -77,7 +77,7 @@
     protected static transient final String BUNDLE_DIR_PREFIX = "bundle";
 
     private PropertyResolver m_cfg = null;
-    private LogWrapper m_logger = null;
+    private Logger m_logger = null;
     private File m_profileDir = null;
     private BundleArchive[] m_archives = null;
 
@@ -85,7 +85,7 @@
     {
     }
 
-    public void initialize(PropertyResolver cfg, LogWrapper logger) throws Exception
+    public void initialize(PropertyResolver cfg, Logger logger) throws Exception
     {
         // Save Properties reference.
         m_cfg = cfg;
@@ -154,7 +154,7 @@
             if (!m_profileDir.mkdirs())
             {
                 m_logger.log(
-                    LogWrapper.LOG_ERROR,
+                    Logger.LOG_ERROR,
                     "Unable to create directory: " + m_profileDir);
                 throw new RuntimeException("Unable to create profile directory.");
             }

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Package.java Fri Feb  3 04:54:52 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   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.
@@ -16,140 +16,30 @@
  */
 package org.apache.felix.framework.searchpolicy;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.felix.framework.util.FelixConstants;
 import org.apache.felix.framework.util.Util;
+import org.osgi.framework.Version;
 
 public class R4Package
 {
-    private String m_id = "";
-    private R4Directive[] m_directives = null;
-    private R4Attribute[] m_attrs = null;
-    private R4Version m_versionLow = null;
-    private R4Version m_versionHigh = null;
-    private String[] m_uses = null;
-    private boolean m_isOptional = false;
-    private String[][] m_includeFilter = null;
-    private String[][] m_excludeFilter = null;
+    private String m_name = "";
+    protected R4Directive[] m_directives = null;
+    protected R4Attribute[] m_attrs = null;
+    protected Version m_version = null;
 
-    protected R4Package(R4Package pkg)
+    public R4Package(String name, R4Directive[] directives, R4Attribute[] attrs)
     {
-        m_id = pkg.m_id;
-        m_directives = pkg.m_directives;
-        m_attrs = pkg.m_attrs;
-        m_versionLow = pkg.m_versionLow;
-        m_versionHigh = pkg.m_versionHigh;
-        m_uses = pkg.m_uses;
-        m_isOptional = pkg.m_isOptional;
-        m_includeFilter = pkg.m_includeFilter;
-        m_excludeFilter = pkg.m_excludeFilter;
-    }
-
-    public R4Package(String id, R4Directive[] directives, R4Attribute[] attrs)
-    {
-        m_id = id;
+        m_name = name;
         m_directives = (directives == null) ? new R4Directive[0] : directives;
         m_attrs = (attrs == null) ? new R4Attribute[0] : attrs;
-
-        // Find all directives: uses, mandatory, resolution, include, and exclude.
-        String mandatory = "", uses = "";
-        for (int i = 0; i < m_directives.length; i++)
-        {
-            if (m_directives[i].getName().equals(FelixConstants.USES_DIRECTIVE))
-            {
-                uses = m_directives[i].getValue();
-            }
-            else if (m_directives[i].getName().equals(FelixConstants.MANDATORY_DIRECTIVE))
-            {
-                mandatory = m_directives[i].getValue();
-            }
-            else if (m_directives[i].getName().equals(FelixConstants.RESOLUTION_DIRECTIVE))
-            {
-                m_isOptional = m_directives[i].getValue().equals(FelixConstants.RESOLUTION_OPTIONAL);
-            }
-            else if (m_directives[i].getName().equals(FelixConstants.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(FelixConstants.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 and parse version attribute, if present.
-        String versionInterval = "0.0.0";
-        for (int i = 0; i < m_attrs.length; i++)
-        {
-            if (m_attrs[i].getName().equals(FelixConstants.VERSION_ATTRIBUTE) ||
-                m_attrs[i].getName().equals(FelixConstants.PACKAGE_SPECIFICATION_VERSION))
-            {
-                // Normalize version attribute name.
-                m_attrs[i] = new R4Attribute(
-                    FelixConstants.VERSION_ATTRIBUTE, m_attrs[i].getValue(),
-                    m_attrs[i].isMandatory());
-                versionInterval = m_attrs[i].getValue();
-                break;
-            }
-        }
-        
-        R4Version[] versions = parseVersionInterval(versionInterval);
-        m_versionLow = versions[0];
-        if (versions.length == 2)
-        {
-            m_versionHigh = versions[1];
-        }
     }
 
-    public String getId()
+    public String getName()
     {
-        return m_id;
+        return m_name;
     }
 
     public R4Directive[] getDirectives()
@@ -162,185 +52,15 @@
         return m_attrs;
     }
 
-    public R4Version getVersionLow()
-    {
-        return m_versionLow;
-    }
-
-    public R4Version getVersionHigh()
-    {
-        return m_versionHigh;
-    }
-
-    public String[] getUses()
+    public Version getVersion()
     {
-        return m_uses;
+        return m_version;
     }
 
-    public boolean isOptional()
-    {
-        return m_isOptional;
-    }
-
-    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 = org.apache.felix.moduleloader.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;
-    }
-
-    // PREVIOUSLY PART OF COMPATIBILITY POLICY.
-    public boolean doesSatisfy(R4Package pkg)
-    {
-        // For packages to be compatible, they must have the
-        // same name.
-        if (!m_id.equals(pkg.m_id))
-        {
-            return false;
-        }
-        
-        return isVersionInRange(m_versionLow, pkg.m_versionLow, pkg.m_versionHigh)
-            && doAttributesMatch(pkg);
-    }
-
-    // PREVIOUSLY PART OF COMPATIBILITY POLICY.
-    public static boolean isVersionInRange(R4Version version, R4Version low, R4Version high)
-    {
-        // We might not have an upper end to the range.
-        if (high == null)
-        {
-            return (version.compareTo(low) >= 0);
-        }
-        else if (low.isInclusive() && high.isInclusive())
-        {
-            return (version.compareTo(low) >= 0) && (version.compareTo(high) <= 0);
-        }
-        else if (high.isInclusive())
-        {
-            return (version.compareTo(low) > 0) && (version.compareTo(high) <= 0);
-        }
-        else if (low.isInclusive())
-        {
-            return (version.compareTo(low) >= 0) && (version.compareTo(high) < 0);
-        }
-
-        return (version.compareTo(low) > 0) && (version.compareTo(high) < 0);
-    }
-
-    private boolean doAttributesMatch(R4Package pkg)
-    {
-        // Cycle through all attributes of the specified package
-        // and make sure their values match the attribute values
-        // of this package.
-        for (int attrIdx = 0; attrIdx < pkg.m_attrs.length; attrIdx++)
-        {
-            // Get current attribute from specified package.
-            R4Attribute attr = pkg.m_attrs[attrIdx];
-
-            // 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 (attr.getName().equals(FelixConstants.VERSION_ATTRIBUTE))
-            {
-                continue;
-            }
-
-            // Check if this package has the same attribute.
-            boolean found = false;
-            for (int thisAttrIdx = 0;
-                (!found) && (thisAttrIdx < m_attrs.length);
-                thisAttrIdx++)
-            {
-                // Get current attribute for this package.
-                R4Attribute thisAttr = m_attrs[thisAttrIdx];
-                // Check if the attribute names are equal.
-                if (attr.getName().equals(thisAttr.getName()))
-                {
-                    // If the values are not equal, then return false immediately.
-                    // We should not compare version values here, since they are
-                    // a special case and have already been compared by a call to
-                    // isVersionInRange() before getting here; however, it is
-                    // possible for version to be mandatory, so make sure it is
-                    // present below.
-                    if (!attr.getValue().equals(thisAttr.getValue()))
-                    {
-                        return false;
-                    }
-                    found = true;
-                }
-            }
-            // If the attribute was not found, then return false.
-            if (!found)
-            {
-                return false;
-            }
-        }
-
-        // Now, cycle through all attributes of this package and verify that
-        // all mandatory attributes are present in the speceified package.
-        for (int thisAttrIdx = 0; thisAttrIdx < m_attrs.length; thisAttrIdx++)
-        {
-            // Get current attribute for this package.
-            R4Attribute thisAttr = m_attrs[thisAttrIdx];
-            
-            // If the attribute is mandatory, then make sure
-            // the specified package has the attribute.
-            if (thisAttr.isMandatory())
-            {
-                boolean found = false;
-                for (int attrIdx = 0;
-                    (!found) && (attrIdx < pkg.m_attrs.length);
-                    attrIdx++)
-                {
-                    // Get current attribute from specified package.
-                    R4Attribute attr = pkg.m_attrs[attrIdx];
-        
-                    // Check if the attribute names are equal
-                    // and set found flag.
-                    if (thisAttr.getName().equals(attr.getName()))
-                    {
-                        found = true;
-                    }
-                }
-                // If not found, then return false.
-                if (!found)
-                {
-                    return false;
-                }
-            }
-        }
-
-        return true;
-    }
 
     public String toString()
     {
-        String msg = getId();
+        String msg = getName();
         for (int i = 0; (m_directives != null) && (i < m_directives.length); i++)
         {
             msg = msg + " [" + m_directives[i].getName() + ":="+ m_directives[i].getValue() + "]";
@@ -471,164 +191,8 @@
             }
         }
     
-        R4Package[] ips = (R4Package[])
+        R4Package[] pkgs = (R4Package[])
             completeList.toArray(new R4Package[completeList.size()]);
-        return ips;
-    }
-
-    public static R4Version[] parseVersionInterval(String interval)
-    {
-        // Check if the version is an interval.
-        if (interval.indexOf(',') >= 0)
-        {
-            String s = interval.substring(1, interval.length() - 1);
-            String vlo = s.substring(0, s.indexOf(','));
-            String vhi = s.substring(s.indexOf(',') + 1, s.length());
-            return new R4Version[] {
-                new R4Version(vlo, (interval.charAt(0) == '[')),
-                new R4Version(vhi, (interval.charAt(interval.length() - 1) == ']'))
-            };
-        }
-        else
-        {
-            return new R4Version[] { new R4Version(interval, true) };
-        }
-    }
-
-    //
-    // 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;
+        return pkgs;
     }
 }

Propchange: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java Fri Feb  3 04:54:52 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   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.
@@ -16,21 +16,100 @@
  */
 package org.apache.felix.framework.searchpolicy;
 
-import org.apache.felix.moduleloader.Module;
+import java.net.URL;
+
+import org.apache.felix.framework.util.Util;
+import org.apache.felix.moduleloader.*;
 
 public class R4Wire
 {
-    public R4Package m_pkg = null;
-    public Module m_module = null;
-    
-    public R4Wire(R4Package pkg, Module module)
+    private IModule m_importer = null;
+    private IModule m_exporter = null;
+    private R4Export m_export= null;
+
+    public R4Wire(IModule importer, IModule exporter, R4Export export)
+    {
+        m_importer = importer;
+        m_exporter = exporter;
+        m_export = export;
+    }
+
+    public IModule getImportingModule()
+    {
+        return m_importer;
+    }
+
+    public IModule getExportingModule()
+    {
+        return m_exporter;
+    }
+
+    public R4Export getExport()
+    {
+        return m_export;
+    }
+
+    public Class getClass(String name) throws ClassNotFoundException
     {
-        m_pkg = pkg;
-        m_module = module;
+        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_export.getName().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_export.isIncluded(name))
+            {
+                clazz = m_exporter.getContentLoader().getClass(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;
     }
-    
+
+    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_export.getName().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()
     {
-        return m_pkg.getId() + " -> " + m_module;
+        return m_importer + " -> " + m_export.getName() + " -> " + m_exporter;
     }
 }

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/DispatchQueue.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/DispatchQueue.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/DispatchQueue.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/DispatchQueue.java Fri Feb  3 04:54:52 2006
@@ -18,7 +18,7 @@
 
 import java.util.*;
 
-import org.apache.felix.framework.LogWrapper;
+import org.apache.felix.framework.Logger;
 
 /**
  * This class implements an event dispatching queue to simplify delivering
@@ -66,13 +66,13 @@
     // Cached dispatch requests to avoid memory allocation.
     private static final ArrayList m_requestCache = new ArrayList();
     // The logger for dispatch queue.
-    private static LogWrapper m_logger = null;
+    private static Logger m_logger = null;
 
     /**
      * Constructs a dispatch queue and starts a dispather thread if
      * necessary.
     **/
-    public DispatchQueue(LogWrapper logger)
+    public DispatchQueue(Logger logger)
     {
         synchronized (m_threadLock)
         {
@@ -127,7 +127,7 @@
         }
     }
 
-    public static LogWrapper getLogger()
+    public static Logger getLogger()
     {
         return m_logger;
     }
@@ -360,7 +360,7 @@
                     try {
                         m_requestList.wait();
                     } catch (InterruptedException ex) {
-                        m_logger.log(LogWrapper.LOG_ERROR, "DispatchQueue: Thread interrupted.", ex);
+                        m_logger.log(Logger.LOG_ERROR, "DispatchQueue: Thread interrupted.", ex);
                     }
                 }
 
@@ -396,7 +396,7 @@
                             dr.m_dispatcher.dispatch(
                                 (EventListener) dr.m_listeners[i + 1], dr.m_eventObj);
                         } catch (Throwable th) {
-                            m_logger.log(LogWrapper.LOG_ERROR, "DispatchQueue: Error during dispatch.", th);
+                            m_logger.log(Logger.LOG_ERROR, "DispatchQueue: Error during dispatch.", th);
                         }
                     }
                 }

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/FelixDispatchQueue.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/FelixDispatchQueue.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/FelixDispatchQueue.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/FelixDispatchQueue.java Fri Feb  3 04:54:52 2006
@@ -19,7 +19,7 @@
 import java.util.EventListener;
 import java.util.EventObject;
 
-import org.apache.felix.framework.LogWrapper;
+import org.apache.felix.framework.Logger;
 import org.osgi.framework.*;
 
 /**
@@ -36,7 +36,7 @@
 **/
 public class FelixDispatchQueue extends DispatchQueue
 {
-    public FelixDispatchQueue(LogWrapper logger)
+    public FelixDispatchQueue(Logger logger)
     {
         super(logger);
     }
@@ -77,7 +77,7 @@
                             (EventListener) lw, eventObj);
                     } catch (Throwable th) {
                         getLogger().log(
-                            LogWrapper.LOG_ERROR,
+                            Logger.LOG_ERROR,
                             "FelixDispatchQueue: Error during dispatch.", th);
                     }
                 }
@@ -100,7 +100,7 @@
                             (EventListener) lw, eventObj);
                     } catch (Throwable th) {
                         getLogger().log(
-                            LogWrapper.LOG_ERROR,
+                            Logger.LOG_ERROR,
                             "FelixDispatchQueue: Error during dispatch.", th);
                     }
                 }

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java Fri Feb  3 04:54:52 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   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.
@@ -18,6 +18,8 @@
 
 import java.io.*;
 
+import org.apache.felix.moduleloader.IContentLoader;
+
 /**
  * The ObjectInputStreamX class is a simple extension to the ObjectInputStream
  * class.  The purpose of ObjectInputStreamX is to allow objects to be deserialized
@@ -25,7 +27,7 @@
  */
 public class ObjectInputStreamX extends ObjectInputStream
 {
-    private ClassLoader m_loader = null;
+    private IContentLoader m_contentLoader = null;
 
     /**
      * Construct an ObjectInputStreamX for the specified InputStream and the specified
@@ -33,11 +35,11 @@
      * @param in the input stream to read.
      * @param loader the class loader used to resolve classes.
      */
-    public ObjectInputStreamX(InputStream in, ClassLoader loader)
+    public ObjectInputStreamX(InputStream in, IContentLoader contentLoader)
         throws IOException, StreamCorruptedException
     {
         super(in);
-        this.m_loader = loader;
+        m_contentLoader = contentLoader;
     }
 
     /**
@@ -47,7 +49,6 @@
     protected Class resolveClass(ObjectStreamClass v)
         throws IOException, ClassNotFoundException
     {
-        Class clazz = m_loader.loadClass(v.getName());
-        return clazz;
+        return m_contentLoader.getClass(v.getName());
     }
 }

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/SecureAction.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/SecureAction.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/SecureAction.java Fri Feb  3 04:54:52 2006
@@ -16,6 +16,7 @@
  */
 package org.apache.felix.framework.util;
 
+import java.net.*;
 import java.security.*;
 
 /**
@@ -33,20 +34,21 @@
 public class SecureAction
 {
     private AccessControlContext m_acc = null;
+    private Actions m_actions = new Actions();
 
     public SecureAction()
     {
         m_acc = AccessController.getContext();
     }
 
-    public String getProperty(String name, String def)
+    public synchronized String getProperty(String name, String def)
     {
         if (System.getSecurityManager() != null)
         {
             try
             {
-                return (String) AccessController.doPrivileged(
-                    new Actions(Actions.GET_PROPERTY_ACTION, name, def), m_acc);
+                m_actions.set(Actions.GET_PROPERTY_ACTION, name, def);
+                return (String) AccessController.doPrivileged(m_actions, m_acc);
             }
             catch (PrivilegedActionException ex)
             {
@@ -59,14 +61,14 @@
         }
     }
 
-    public Class forName(String name) throws ClassNotFoundException
+    public synchronized Class forName(String name) throws ClassNotFoundException
     {
         if (System.getSecurityManager() != null)
         {
             try
             {
-                return (Class) AccessController.doPrivileged(
-                    new Actions(Actions.FOR_NAME_ACTION, name), m_acc);
+                m_actions.set(Actions.FOR_NAME_ACTION, name);
+                return (Class) AccessController.doPrivileged(m_actions, m_acc);
             }
             catch (PrivilegedActionException ex)
             {
@@ -83,26 +85,87 @@
         }
     }
 
+    public synchronized URL createURL(String protocol, String host,
+        int port, String path, URLStreamHandler handler)
+        throws MalformedURLException
+    {
+        if (System.getSecurityManager() != null)
+        {
+            try 
+            {
+                m_actions.set(
+                    Actions.CREATE_URL_ACTION, protocol, host, port, path, handler);
+                return (URL) AccessController.doPrivileged(m_actions, m_acc);
+            }
+            catch (PrivilegedActionException ex)
+            {
+                if (ex.getException() instanceof MalformedURLException)
+                {
+                    throw (MalformedURLException) ex.getException();
+                }
+                throw (RuntimeException) ex.getException();
+            }
+        }
+        else
+        {
+            return new URL(protocol, host, port, path, handler);
+        }
+    }
+
     private static class Actions implements PrivilegedExceptionAction
     {
         public static final int GET_PROPERTY_ACTION = 0;
         public static final int FOR_NAME_ACTION = 1;
+        public static final int CREATE_URL_ACTION = 2;
 
         private int m_action = -1;
         private Object m_arg1 = null;
         private Object m_arg2 = null;
 
-        public Actions(int action, Object arg1)
+        private String m_protocol = null;
+        private String m_host = null;
+        private int m_port = -1;
+        private String m_path = null;
+        private URLStreamHandler m_handler = null;
+
+        public void set(int action, Object arg1)
         {
             m_action = action;
             m_arg1 = arg1;
+
+            m_arg2 = null;
+            m_protocol = null;
+            m_host = null;
+            m_port = -1;
+            m_path = null;
+            m_handler = null;
         }
 
-        public Actions(int action, Object arg1, Object arg2)
+        public void set(int action, Object arg1, Object arg2)
         {
             m_action = action;
             m_arg1 = arg1;
             m_arg2 = arg2;
+
+            m_protocol = null;
+            m_host = null;
+            m_port = -1;
+            m_path = null;
+            m_handler = null;
+        }
+
+        public void set(int action, String protocol, String host,
+            int port, String path, URLStreamHandler handler)
+        {
+            m_action = action;
+            m_protocol = protocol;
+            m_host = host;
+            m_port = port;
+            m_path = path;
+            m_handler = handler;
+
+            m_arg1 = null;
+            m_arg2 = null;
         }
 
         public Object run() throws Exception
@@ -111,9 +174,13 @@
             {
                 return System.getProperty((String) m_arg1, (String) m_arg2);
             }
-            else if (m_action ==FOR_NAME_ACTION)
+            else if (m_action == FOR_NAME_ACTION)
             {
                 return Class.forName((String) m_arg1);
+            }
+            else if (m_action == CREATE_URL_ACTION)
+            {
+                return new URL(m_protocol, m_host, m_port, m_path, m_handler);
             }
             return null;
         }

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java Fri Feb  3 04:54:52 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   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.
@@ -20,9 +20,137 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.felix.framework.Logger;
+import org.apache.felix.framework.searchpolicy.*;
+import org.apache.felix.moduleloader.IModule;
+
 public class Util
 {
     /**
+     * Converts a module identifier to a bundle identifier. Module 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)
+    {
+        try
+        {
+            String bundleId = (id.indexOf('.') >= 0)
+                ? id.substring(0, id.indexOf('.')) : id;
+            return Long.parseLong(bundleId);
+        }
+        catch (NumberFormatException ex)
+        {
+            return -1;
+        }
+    }
+
+    /**
+     * Converts a module identifier to a bundle identifier. Module IDs
+     * are typically <tt>&lt;bundle-id&gt;.&lt;revision&gt;</tt>; this
+     * method returns only the portion corresponding to the revision.
+    **/
+    public static int getModuleRevisionFromModuleId(String id)
+    {
+        try
+        {
+            String rev = (id.indexOf('.') >= 0)
+                ? id.substring(id.indexOf('.') + 1) : id;
+            return Integer.parseInt(rev);
+        }
+        catch (NumberFormatException ex)
+        {
+            return -1;
+        }
+    }
+
+    public static String getClassName(String className)
+    {
+        if (className == null)
+        {
+            className = "";
+        }
+        return (className.lastIndexOf('.') < 0)
+            ? "" : className.substring(className.lastIndexOf('.') + 1);
+    }
+
+    public static String getClassPackage(String className)
+    {
+        if (className == null)
+        {
+            className = "";
+        }
+        return (className.lastIndexOf('.') < 0)
+            ? "" : className.substring(0, className.lastIndexOf('.'));
+    }
+
+    public static String getResourcePackage(String resource)
+    {
+        if (resource == null)
+        {
+            resource = "";
+        }
+        // NOTE: The package of a resource is tricky to determine since
+        // resources do not follow the same naming conventions as classes.
+        // This code is pessimistic and assumes that the package of a
+        // resource is everything up to the last '/' character. By making
+        // this choice, it will not be possible to load resources from
+        // imports using relative resource names. For example, if a
+        // bundle exports "foo" and an importer of "foo" tries to load
+        // "/foo/bar/myresource.txt", this will not be found in the exporter
+        // because the following algorithm assumes the package name is
+        // "foo.bar", not just "foo". This only affects imported resources,
+        // local resources will work as expected.
+        String pkgName = (resource.startsWith("/")) ? resource.substring(1) : resource;
+        pkgName = (pkgName.lastIndexOf('/') < 0)
+            ? "" : pkgName.substring(0, pkgName.lastIndexOf('/'));
+        pkgName = pkgName.replace('/', '.');
+        return pkgName;
+    }
+
+    public static R4Export getExportPackage(IModule m, String name)
+    {
+        R4Export[] pkgs =
+            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getExports();
+        for (int i = 0; (pkgs != null) && (i < pkgs.length); i++)
+        {
+            if (pkgs[i].getName().equals(name))
+            {
+                return pkgs[i];
+            }
+        }
+        return null;
+    }
+
+    public static R4Import getImportPackage(IModule m, String name)
+    {
+        R4Import[] pkgs =
+            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getImports();
+        for (int i = 0; (pkgs != null) && (i < pkgs.length); i++)
+        {
+            if (pkgs[i].getName().equals(name))
+            {
+                return pkgs[i];
+            }
+        }
+        return null;
+    }
+
+    public static R4Wire getWire(IModule m, String name)
+    {
+        R4Wire[] wires =
+            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getWires();
+        for (int i = 0; (wires != null) && (i < wires.length); i++)
+        {
+            if (wires[i].getExport().getName().equals(name))
+            {
+                return wires[i];
+            }
+        }
+        return null;
+    }
+
+    /**
      * Parses delimited string and returns an array containing the tokens. This
      * parser obeys quotes, so the delimiter character will be ignored if it is
      * inside of a quote. This method assumes that the quote character is not
@@ -97,19 +225,19 @@
      * @return an array of <tt>LibraryInfo</tt> objects for the
      *         passed in strings.
     **/
-    public static LibraryInfo[] parseLibraryStrings(String[] libStrs)
+    public static R4LibraryHeader[] parseLibraryStrings(Logger logger, String[] libStrs)
         throws IllegalArgumentException
     {
         if (libStrs == null)
         {
-            return null;
+            return new R4LibraryHeader[0];
         }
 
         List libList = new ArrayList();
 
         for (int i = 0; i < libStrs.length; i++)
         {
-            LibraryInfo[] libs = LibraryInfo.parse(libStrs[i]);
+            R4LibraryHeader[] libs = R4LibraryHeader.parse(logger, libStrs[i]);
             for (int libIdx = 0;
                 (libs != null) && (libIdx < libs.length);
                 libIdx++)
@@ -118,12 +246,7 @@
             }
         }
 
-        if (libList.size() == 0)
-        {
-            return null;
-        }
-
-        return (LibraryInfo[]) libList.toArray(new LibraryInfo[libList.size()]);
+        return (R4LibraryHeader[]) libList.toArray(new R4LibraryHeader[libList.size()]);
     }
 
     private static final byte encTab[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java Fri Feb  3 04:54:52 2006
@@ -25,13 +25,13 @@
  * events, a <tt>ModuleListener</tt> must be added to the <tt>ModuleManager</tt>
  * instance.
  * </p>
- * @see org.apache.felix.moduleloader.ModuleManager
- * @see org.apache.felix.moduleloader.Module
+ * @see org.apache.felix.moduleloader.ModuleFactoryImpl
+ * @see org.apache.felix.moduleloader.ModuleImpl
  * @see org.apache.felix.moduleloader.ModuleListener
 **/
 public class ModuleEvent extends EventObject
 {
-    private Module m_module = null;
+    private IModule m_module = null;
 
     /**
      * <p>
@@ -42,9 +42,9 @@
      * @param mgr the source of the event.
      * @param module the subject of the event.
     **/
-    public ModuleEvent(ModuleManager mgr, Module module)
+    public ModuleEvent(IModuleFactory factory, IModule module)
     {
-        super(mgr);
+        super(factory);
         m_module = module;
     }
 
@@ -54,7 +54,7 @@
      * </p>
      * @return the module that is the subject of the event.
     **/
-    public Module getModule()
+    public IModule getModule()
     {
         return m_module;
     }

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleListener.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleListener.java?rev=374660&r1=374659&r2=374660&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleListener.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleListener.java Fri Feb  3 04:54:52 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   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.
@@ -22,9 +22,9 @@
  * <p>
  * This interface is an event listener for <tt>ModuleEvent</tt> events.
  * To receive events, an implementation of this listener must be added
- * to the <tt>ModuleManager</tt> instance.
+ * to the <tt>IModuleFactory</tt> instance.
  * </p>
- * @see org.apache.felix.moduleloader.ModuleManager
+ * @see org.apache.felix.moduleloader.IModuleFactory
  * @see org.apache.felix.moduleloader.ModuleEvent
 **/
 public interface ModuleListener extends EventListener
@@ -32,7 +32,7 @@
     /**
      * <p>
      * This method is called after a module is added to the
-     * <tt>ModuleManager</tt>.
+     * <tt>IModuleFactory</tt>.
      * </p>
      * @param event the event object containing the event details.
     **/
@@ -40,17 +40,8 @@
 
     /**
      * <p>
-     * This method is called after a module has been reset by the
-     * <tt>ModuleManager</tt>.
-     * </p>
-     * @param event the event object containing the event details.
-    **/
-    public void moduleReset(ModuleEvent event);
-
-    /**
-     * <p>
      * This method is called after a module is remove from the
-     * <tt>ModuleManager</tt>.
+     * <tt>IModuleFactory</tt>.
      * </p>
      * @param event the event object containing the event details.
     **/



Mime
View raw message