Modified Felix' constructor so that it no longer throws an exception so
it aligns better with the OSGi META-INF/services framework factory.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@750065 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/pom.xml b/framework/pom.xml
index 492e450..cf4d3d1 100644
--- a/framework/pom.xml
+++ b/framework/pom.xml
@@ -65,7 +65,7 @@
             <Export-Package>org.osgi.framework;-split-package:=merge-first,org.osgi.framework.launch,org.osgi.framework.hooks.service,org.osgi.service.packageadmin,org.osgi.service.url,org.osgi.service.startlevel,org.osgi.util.tracker</Export-Package>
             <Private-Package>org.apache.felix.moduleloader.*,org.apache.felix.framework.*</Private-Package>
             <Import-Package>!*</Import-Package>
-            <Include-Resource>META-INF/services/org.osgi.framework.launch.FrameworkFactory=org.osgi.framework.launch.FrameworkFactory,META-INF/LICENSE=LICENSE,META-INF/NOTICE=NOTICE,{src/main/resources/},org/osgi/framework/=target/classes/org/osgi/framework/</Include-Resource> 
+            <Include-Resource>META-INF/LICENSE=LICENSE,META-INF/NOTICE=NOTICE,{src/main/resources/},org/osgi/framework/=target/classes/org/osgi/framework/</Include-Resource> 
           </instructions>
         </configuration>
       </plugin>
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 5e0a2b1..a017bde 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -59,6 +59,20 @@
     private int m_lockCount = 0;
     private Thread m_lockThread = null;
 
+    /**
+     * This constructor is used by the system bundle (i.e., the framework),
+     * since it needs a constructor that does not throw an exception.
+    **/
+    BundleImpl()
+    {
+        __m_felix = null;
+        m_archive = null;
+        m_state = Bundle.INSTALLED;
+        m_stale = false;
+        m_activator = null;
+        m_context = null;
+    }
+
     BundleImpl(Felix felix, BundleArchive archive) throws Exception
     {
         __m_felix = felix;
@@ -68,13 +82,8 @@
         m_activator = null;
         m_context = null;
 
-        // We have to check for null here because the framework/system bundle
-        // extends BundleImpl and it doesn't have an archive.
-        if (m_archive != null)
-        {
-            IModule module = createModule();
-            addModule(module);
-        }
+        IModule module = createModule();
+        addModule(module);
     }
 
     // This method exists because the system bundle extends BundleImpl
diff --git a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
index d00884c..4c3a3d7 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -139,7 +139,7 @@
      * @param config the configuration to read properties from.
      * @param systemBundleInfo the info to change if we need to add exports.
      */
-    ExtensionManager(Logger logger, Felix felix) throws BundleException
+    ExtensionManager(Logger logger, Felix felix)
     {
         m_module = new ExtensionManagerModule(felix);
         m_extensions = null;
@@ -614,9 +614,9 @@
     class ExtensionManagerModule extends ModuleImpl
     {
         private final Version m_version;
-        ExtensionManagerModule(Felix felix) throws BundleException
+        ExtensionManagerModule(Felix felix)
         {
-            super(m_logger, null, null, felix, "0", null, null, null,
+            super(m_logger, felix, "0",
                 felix.getBootPackages(), felix.getBootPackageWildcards());
             m_version = new Version((String)
                 felix.getConfig().get(FelixConstants.FELIX_VERSION_PROPERTY));
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 056d63f..1f1f210 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -246,9 +246,9 @@
      * @param configMap A map for obtaining configuration properties,
      *        may be <tt>null</tt>.
     **/
-    public Felix(Map configMap) throws Exception
+    public Felix(Map configMap)
     {
-        super(null, null);
+        super();
         // Copy the configuration properties; convert keys to strings.
         m_configMutableMap = new StringMap(false);
         if (configMap != null)
@@ -299,7 +299,16 @@
         // Create the extension manager, which we will use as the module
         // definition for creating the system bundle module.
         m_extensionManager = new ExtensionManager(m_logger, this);
-        addModule(m_extensionManager.getModule());
+        try
+        {
+            addModule(m_extensionManager.getModule());
+        }
+        catch (Exception ex)
+        {
+            // This should not throw an exception, but if so, lets convert it to
+            // a runtime exception.
+            throw new RuntimeException(ex.getMessage());
+        }
 
 
         // Read the boot delegation property and parse it.
diff --git a/framework/src/main/java/org/apache/felix/framework/FrameworkFactory.java b/framework/src/main/java/org/apache/felix/framework/FrameworkFactory.java
index 262d7af..ce377ad 100644
--- a/framework/src/main/java/org/apache/felix/framework/FrameworkFactory.java
+++ b/framework/src/main/java/org/apache/felix/framework/FrameworkFactory.java
@@ -23,7 +23,7 @@
 
 public class FrameworkFactory implements org.osgi.framework.launch.FrameworkFactory
 {
-    public Framework newFramework(Map configuration) throws Exception
+    public Framework newFramework(Map configuration)
     {
         return new Felix(configuration);
     }
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
index 2456b48..d02bf26 100644
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
@@ -99,6 +99,39 @@
     // Thread local to detect class loading cycles.
     private final ThreadLocal m_cycleCheck = new ThreadLocal();
 
+    /**
+     * This constructor is used by the extension manager, since it needs
+     * a constructor that does not throw an exception.
+     * @param logger
+     * @param bundle
+     * @param id
+     * @param bootPkgs
+     * @param bootPkgWildcards
+     * @throws org.osgi.framework.BundleException
+     */
+    public ModuleImpl(
+        Logger logger, Bundle bundle, String id,
+        String[] bootPkgs, boolean[] bootPkgWildcards)
+    {
+        m_logger = logger;
+        m_configMap = null;
+        m_resolver = null;
+        m_bundle = bundle;
+        m_id = id;
+        m_headerMap = null;
+        m_content = null;
+        m_streamHandler = null;
+        m_bootPkgs = bootPkgs;
+        m_bootPkgWildcards = bootPkgWildcards;
+        m_manifestVersion = null;
+        m_symbolicName = null;
+        m_version = null;
+        m_capabilities = null;
+        m_requirements = null;
+        m_dynamicRequirements = null;
+        m_nativeLibraries = null;
+    }
+
     public ModuleImpl(
         Logger logger, Map configMap, FelixResolver resolver,
         Bundle bundle, String id, Map headerMap, IContent content,
@@ -117,76 +150,61 @@
         m_bootPkgs = bootPkgs;
         m_bootPkgWildcards = bootPkgWildcards;
 
-        // We need to special case the system bundle module, which does not
-        // have a content.
-        if (m_content != null)
+        ManifestParser mp = new ManifestParser(m_logger, m_configMap, m_headerMap);
+
+        // Record some of the parsed metadata. Note, if this is an extension
+        // bundle it's exports are removed, since they will be added to the
+        // system bundle directly later on.
+        m_manifestVersion = mp.getManifestVersion();
+        m_version = mp.getBundleVersion();
+        m_capabilities = (Util.isExtensionBundle(m_headerMap))
+            ? null : mp.getCapabilities();
+        m_requirements = mp.getRequirements();
+        m_dynamicRequirements = mp.getDynamicRequirements();
+        m_nativeLibraries = mp.getLibraries();
+
+        // Get symbolic name.
+        String symName = null;
+        for (int capIdx = 0;
+            (m_capabilities != null) && (capIdx < m_capabilities.length);
+            capIdx++)
         {
-            ManifestParser mp = new ManifestParser(m_logger, m_configMap, m_headerMap);
-
-            // Record some of the parsed metadata. Note, if this is an extension
-            // bundle it's exports are removed, since they will be added to the
-            // system bundle directly later on.
-            m_manifestVersion = mp.getManifestVersion();
-            m_version = mp.getBundleVersion();
-            m_capabilities = (Util.isExtensionBundle(m_headerMap))
-                ? null : mp.getCapabilities();
-            m_requirements = mp.getRequirements();
-            m_dynamicRequirements = mp.getDynamicRequirements();
-            m_nativeLibraries = mp.getLibraries();
-
-            // Get symbolic name.
-            String symName = null;
-            for (int capIdx = 0;
-                (m_capabilities != null) && (capIdx < m_capabilities.length);
-                capIdx++)
+            if (m_capabilities[capIdx].getNamespace().equals(ICapability.MODULE_NAMESPACE))
             {
-                if (m_capabilities[capIdx].getNamespace().equals(ICapability.MODULE_NAMESPACE))
-                {
-                    symName = (String) m_capabilities[capIdx].getProperties().get(
-                        Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
-                    break;
-                }
+                symName = (String) m_capabilities[capIdx].getProperties().get(
+                    Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
+                break;
             }
-            m_symbolicName = symName;
+        }
+        m_symbolicName = symName;
 
-            // Verify that all native libraries exist in advance; this will
-            // throw an exception if the native library does not exist.
-            try
+        // Verify that all native libraries exist in advance; this will
+        // throw an exception if the native library does not exist.
+        try
+        {
+            for (int i = 0;
+                (m_nativeLibraries != null) && (i < m_nativeLibraries.length);
+                i++)
             {
-                for (int i = 0;
-                    (m_nativeLibraries != null) && (i < m_nativeLibraries.length);
-                    i++)
+                String entryName = m_nativeLibraries[i].getEntryName();
+                if (entryName != null)
                 {
-                    String entryName = m_nativeLibraries[i].getEntryName();
-                    if (entryName != null)
+                    if (m_content.getEntryAsNativeLibrary(entryName) == null)
                     {
-                        if (m_content.getEntryAsNativeLibrary(entryName) == null)
-                        {
-                            throw new BundleException("Native library does not exist: " + entryName);
-                        }
+                        throw new BundleException("Native library does not exist: " + entryName);
                     }
                 }
             }
-            finally
-            {
-                // We close the module content here to make sure it is closed
-                // to avoid having to close it if there is an exception during
-                // the entire module creation process.
+        }
+        finally
+        {
+            // We close the module content here to make sure it is closed
+            // to avoid having to close it if there is an exception during
+            // the entire module creation process.
 // TODO: REFACTOR - If we do the above check here, then we open the module's content
 //       immediately every time, which means we must close it here so we don't have
 //       to remember to close it if there are other failures during module init.
-                m_content.close();
-            }
-        }
-        else
-        {
-            m_manifestVersion = null;
-            m_version = null;
-            m_capabilities = null;
-            m_requirements = null;
-            m_dynamicRequirements = null;
-            m_nativeLibraries = null;
-            m_symbolicName = null;
+            m_content.close();
         }
     }
 
diff --git a/framework/src/main/java/org/osgi/framework/launch/FrameworkFactory.java b/framework/src/main/java/org/osgi/framework/launch/FrameworkFactory.java
index 6a3dc7b..7e96ede 100644
--- a/framework/src/main/java/org/osgi/framework/launch/FrameworkFactory.java
+++ b/framework/src/main/java/org/osgi/framework/launch/FrameworkFactory.java
@@ -68,5 +68,5 @@
 	 *         <code>AllPermission</code>, and the Java Runtime Environment
 	 *         supports permissions.
 	 */
-	Framework newFramework(Map configuration) throws Exception;
+	Framework newFramework(Map configuration);
 }
diff --git a/framework/org.osgi.framework.launch.FrameworkFactory b/framework/src/main/resources/META-INF/services/org.osgi.framework.launch.FrameworkFactory
similarity index 100%
rename from framework/org.osgi.framework.launch.FrameworkFactory
rename to framework/src/main/resources/META-INF/services/org.osgi.framework.launch.FrameworkFactory