[jboss-cvs] JBossAS SVN: r98038 - in projects/jboss-osgi/projects/runtime/framework/trunk/src: main/java/org/jboss/osgi/framework/bundle and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Dec 19 18:46:54 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-12-19 18:46:53 -0500 (Sat, 19 Dec 2009)
New Revision: 98038

Added:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoader.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleClassLoadingDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java
Removed:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoadingDeployer.java
Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/etc/osgitck/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR3.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR4.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderFactory.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderSystem.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiManifestParsingDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolverBundleImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
Log:
Add initial support for native code libraries

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/etc/osgitck/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/etc/osgitck/jboss-osgi-bootstrap.xml	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/etc/osgitck/jboss-osgi-bootstrap.xml	2009-12-19 23:46:53 UTC (rev 98038)
@@ -143,6 +143,7 @@
   <bean name="OSGiBundleStateRemoveDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateRemoveDeployer">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiBundleNativeCodeDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleNativeCodeDeployer" />
   <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer" />
   <bean name="OSGiContextTrackerDeployer" class="org.jboss.osgi.framework.deployers.OSGiContextTrackerDeployer" />
 
@@ -163,7 +164,7 @@
   <bean name="OSGiClassLoaderFactory" class="org.jboss.osgi.framework.classloading.OSGiClassLoaderFactory" >
     <property name="system"><inject bean="OSGiClassLoaderSystem"/></property>
   </bean>
-  <bean name="OSGiBundleClassLoadingDeployer" class="org.jboss.osgi.framework.classloading.OSGiBundleClassLoadingDeployer">
+  <bean name="OSGiBundleClassLoadingDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleClassLoadingDeployer">
     <property name="domain"><inject bean="OSGiClassLoaderDomain"/></property>
     <property name="factory"><inject bean="OSGiClassLoaderFactory"/></property>
   </bean>

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -128,7 +128,7 @@
 
    public String getSymbolicName()
    {
-      String symbolicName = getMetaData().getBundleSymbolicName();
+      String symbolicName = getOSGiMetaData().getBundleSymbolicName();
       if (symbolicName == null)
          symbolicName = "anonymous-bundle" + getBundleId();
 
@@ -137,7 +137,7 @@
 
    public Version getVersion()
    {
-      String versionstr = getMetaData().getBundleVersion();
+      String versionstr = getOSGiMetaData().getBundleVersion();
       try
       {
          return Version.parseVersion(versionstr);
@@ -232,7 +232,7 @@
     * 
     * @return the osgiMetaData.
     */
-   public abstract OSGiMetaData getMetaData();
+   public abstract OSGiMetaData getOSGiMetaData();
 
    @SuppressWarnings("rawtypes")
    public Dictionary getHeaders()
@@ -248,7 +248,7 @@
       checkAdminPermission(AdminPermission.METADATA);
 
       // Get the raw (unlocalized) manifest headers
-      Dictionary<String, String> rawHeaders = getMetaData().getHeaders();
+      Dictionary<String, String> rawHeaders = getOSGiMetaData().getHeaders();
 
       // If the specified locale is the empty string, this method will return the 
       // raw (unlocalized) manifest headers including any leading "%"

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -127,9 +127,9 @@
    /** The bundle manager's bean name: OSGiBundleManager */
    public static final String BEAN_BUNDLE_MANAGER = "OSGiBundleManager";
    /** The framework version */
-   private static String OSGi_FRAMEWORK_VERSION = "r4v42"; // [TODO] externalise
+   private static String OSGi_FRAMEWORK_VERSION = "r4v42";
    /** The framework vendor */
-   private static String OSGi_FRAMEWORK_VENDOR = "jboss.org"; // [TODO] externalise
+   private static String OSGi_FRAMEWORK_VENDOR = "jboss.org";
    /** The framework language */
    private static String OSGi_FRAMEWORK_LANGUAGE = Locale.getDefault().getISO3Language(); // REVIEW correct?
    /** The os name */
@@ -805,7 +805,7 @@
    {
       // If the specified InputStream is null, the Framework must create the InputStream from which to read the updated bundle by interpreting, 
       // in an implementation dependent manner, this bundle's Bundle-UpdateLocation Manifest header, if present, or this bundle's original location.
-      URL updateURL = bundleState.getMetaData().getBundleUpdateLocation();
+      URL updateURL = bundleState.getOSGiMetaData().getBundleUpdateLocation();
       if (updateURL == null)
       {
          // This updates the bundle from its original location 
@@ -937,8 +937,8 @@
       if (unit == null)
          throw new IllegalArgumentException("Null unit");
 
-      OSGiMetaData metaData = unit.getAttachment(OSGiMetaData.class);
-      if (metaData == null)
+      OSGiMetaData osgiMetaData = unit.getAttachment(OSGiMetaData.class);
+      if (osgiMetaData == null)
       {
          Manifest manifest = unit.getAttachment(Manifest.class);
          // [TODO] we need a mechanism to construct an OSGiMetaData from an easier factory
@@ -948,8 +948,8 @@
          Attributes attributes = manifest.getMainAttributes();
          attributes.put(new Name(Constants.BUNDLE_NAME), unit.getName());
          attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), unit.getName());
-         metaData = new AbstractOSGiMetaData(manifest);
-         unit.addAttachment(OSGiMetaData.class, metaData);
+         osgiMetaData = new AbstractOSGiMetaData(manifest);
+         unit.addAttachment(OSGiMetaData.class, osgiMetaData);
       }
 
       // In case of Bundle.update() the OSGiBundleState should be attached. We add the DeploymentUnit 
@@ -1033,17 +1033,17 @@
     */
    private void validateBundle(AbstractBundleState bundleState)
    {
-      OSGiMetaData metaData = bundleState.getMetaData();
-      if (metaData == null)
+      OSGiMetaData osgiMetaData = bundleState.getOSGiMetaData();
+      if (osgiMetaData == null)
          return;
 
-      ParameterizedAttribute fragmentHost = metaData.getFragmentHost();
+      ParameterizedAttribute fragmentHost = osgiMetaData.getFragmentHost();
       if (fragmentHost != null)
          throw new NotImplementedException("Fragments not implemented: " + fragmentHost);
       
       // Delegate to the validator for the appropriate revision
       OSGiBundleValidator validator = new OSGiBundleValidatorR3(this);
-      if(metaData.getBundleManifestVersion() > 1)
+      if(osgiMetaData.getBundleManifestVersion() > 1)
          validator = new OSGiBundleValidatorR4(this);
 
       validator.validateBundle(bundleState);

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -117,11 +117,11 @@
    }
 
    @Override
-   public OSGiMetaData getMetaData()
+   public OSGiMetaData getOSGiMetaData()
    {
       DeploymentUnit unit = getDeploymentUnit();
-      OSGiMetaData metadata = unit.getAttachment(OSGiMetaData.class);
-      return metadata;
+      OSGiMetaData osgiMetaData = unit.getAttachment(OSGiMetaData.class);
+      return osgiMetaData;
    }
 
    protected Set<ControllerContext> getRegisteredContexts()
@@ -351,12 +351,12 @@
       // The BundleActivator.start(org.osgi.framework.BundleContext) method of this bundle's BundleActivator, if one is specified, is called. 
       try
       {
-         OSGiMetaData metaData = getMetaData();
-         if (metaData == null)
+         OSGiMetaData osgiMetaData = getOSGiMetaData();
+         if (osgiMetaData == null)
             throw new IllegalStateException("Cannot obtain OSGi meta data");
 
          // Do we have a bundle activator
-         String bundleActivatorClassName = metaData.getBundleActivator();
+         String bundleActivatorClassName = osgiMetaData.getBundleActivator();
          if (bundleActivatorClassName != null)
          {
             Object result = loadClass(bundleActivatorClassName).newInstance();

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR3.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR3.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR3.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -37,8 +37,8 @@
 
    public void validateBundle(AbstractBundleState bundleState)
    {
-      OSGiMetaData metaData = bundleState.getMetaData();
-      int manifestVersion = metaData.getBundleManifestVersion();
+      OSGiMetaData osgiMetaData = bundleState.getOSGiMetaData();
+      int manifestVersion = osgiMetaData.getBundleManifestVersion();
       if (manifestVersion != 1)
          throw new IllegalStateException("Unsupported manifest version " + manifestVersion + " for " + bundleState);
    }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR4.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR4.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR4.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -47,7 +47,7 @@
    @SuppressWarnings("deprecation")
    public void validateBundle(AbstractBundleState bundleState)
    {
-      OSGiMetaData metaData = bundleState.getMetaData();
+      OSGiMetaData osgiMetaData = bundleState.getOSGiMetaData();
       
       // Missing Bundle-SymbolicName
       String symbolicName = bundleState.getSymbolicName();
@@ -55,14 +55,14 @@
          throw new IllegalStateException("Missing Bundle-SymbolicName in: " + bundleState);
       
       // Bundle-ManifestVersion value not equal to 2, unless the Framework specifically recognizes the semantics of a later release.
-      int manifestVersion = metaData.getBundleManifestVersion();
+      int manifestVersion = osgiMetaData.getBundleManifestVersion();
       if (manifestVersion > 2)
          throw new IllegalStateException("Unsupported manifest version " + manifestVersion + " for " + bundleState);
 
       // [TODO] Duplicate attribute or duplicate directive (except in the Bundle-Native code clause).
       
       // Multiple imports of a given package.
-      List<PackageAttribute> importPackages = metaData.getImportPackages();
+      List<PackageAttribute> importPackages = osgiMetaData.getImportPackages();
       if (importPackages != null && importPackages.isEmpty() == false)
       {
          Set<String> packages = new HashSet<String>();
@@ -84,7 +84,7 @@
       }
       
       // Export or import of java.*.
-      List<PackageAttribute> exportPackages = metaData.getExportPackages();
+      List<PackageAttribute> exportPackages = osgiMetaData.getExportPackages();
       if (exportPackages != null && exportPackages.isEmpty() == false)
       {
          for (PackageAttribute packageAttribute : exportPackages)
@@ -100,12 +100,12 @@
       // Installing a bundle that has the same symbolic name and version as an already installed bundle.
       for (AbstractBundleState bundle : bundleManager.getBundles())
       {
-         OSGiMetaData other = bundle.getMetaData();
+         OSGiMetaData other = bundle.getOSGiMetaData();
          if (symbolicName.equals(other.getBundleSymbolicName()))
          {
-            if (other.isSingleton() && metaData.isSingleton())
+            if (other.isSingleton() && osgiMetaData.isSingleton())
                throw new IllegalStateException("Cannot install singleton " + bundleState + " another singleton is already installed: " + bundle.getLocation());
-            if (other.getBundleVersion().equals(metaData.getBundleVersion()))
+            if (other.getBundleVersion().equals(osgiMetaData.getBundleVersion()))
                throw new IllegalStateException("Cannot install " + bundleState + " a bundle with that name and version is already installed: "
                      + bundle.getLocation());
          }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -65,7 +65,7 @@
    }
 
    @Override
-   public OSGiMetaData getMetaData()
+   public OSGiMetaData getOSGiMetaData()
    {
       return osgiMetaData;
    }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -90,7 +90,7 @@
     */
    public OSGiMetaData getMetaData()
    {
-      return bundleState.getMetaData();
+      return bundleState.getOSGiMetaData();
    }
 
    @Override
@@ -104,8 +104,8 @@
       // Review its not clear to me from the spec whether attribute matching 
       // beyond the version should work for require-bundle?
       OSGiBundleRequirement bundleRequirement = (OSGiBundleRequirement) requirement;
-      OSGiMetaData metaData = getMetaData();
-      ParameterizedAttribute ourParameters = metaData.getBundleParameters();
+      OSGiMetaData osgiMetaData = getMetaData();
+      ParameterizedAttribute ourParameters = osgiMetaData.getBundleParameters();
       ParameterizedAttribute otherParameters = bundleRequirement.getRequireBundle();
       if (otherParameters != null)
       {

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoader.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoader.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoader.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.classloading;
+
+// $Id: OSGiClassLoaderFactory.java 95177 2009-10-20 15:14:31Z thomas.diesler at jboss.com $
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.base.BaseClassLoader;
+import org.jboss.osgi.framework.deployers.OSGiBundleNativeCodeDeployer;
+
+/**
+ * An OSGi bundle class loader.
+ * 
+ * This implementation supports the notion of OSGi Native Code Libraries.
+ * The library map is initialized in {@link OSGiBundleNativeCodeDeployer}.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 19-Dec-2209
+ */
+public class OSGiBundleClassLoader extends BaseClassLoader
+{
+   private OSGiClassLoaderPolicy osgiPolicy;
+
+   public OSGiBundleClassLoader(ClassLoaderPolicy policy)
+   {
+      super(policy);
+
+      if (policy instanceof OSGiClassLoaderPolicy)
+         osgiPolicy = (OSGiClassLoaderPolicy)policy;
+   }
+
+   @Override
+   protected String findLibrary(String libname)
+   {
+      String libraryPath = null;
+
+      if (osgiPolicy != null)
+         libraryPath = osgiPolicy.findLibrary(libname);
+
+      if (libraryPath == null)
+         libraryPath = super.findLibrary(libname);
+
+      return libraryPath;
+   }
+
+}

Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoadingDeployer.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoadingDeployer.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -1,152 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.osgi.framework.classloading;
-
-// $Id: $
-
-import java.util.List;
-
-import org.jboss.classloader.spi.ClassLoaderDomain;
-import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
-import org.jboss.classloading.spi.metadata.RequirementsMetaData;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.ClassLoaderFactory;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.framework.metadata.PackageAttribute;
-import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
-import org.jboss.osgi.framework.plugins.SystemPackagesPlugin;
-
-/**
- * OSGiBundleClassLoadingDeployer.<p>
- * 
- * This deployer maps osgi metadata into our classloading metadata.
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Thomas.Diesler at jboss.com
- * @version $Revision: 1.1 $
- */
-public class OSGiBundleClassLoadingDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
-{
-   private ClassLoaderDomain domain;
-   private ClassLoaderFactory factory;
-   
-   /**
-    * Create a new OSGiBundleClassLoadingDeployer.
-    */
-   public OSGiBundleClassLoadingDeployer()
-   {
-      super(OSGiMetaData.class);
-      addInput(OSGiBundleState.class);
-      setOutput(ClassLoadingMetaData.class);
-      setStage(DeploymentStages.POST_PARSE);
-      setTopLevelOnly(true);
-   }
-
-   public void setDomain(ClassLoaderDomain domain)
-   {
-      this.domain = domain;
-   }
-
-   public void setFactory(ClassLoaderFactory factory)
-   {
-      this.factory = factory;
-   }
-
-   @Override
-   public void deploy(DeploymentUnit unit, OSGiMetaData osgiMetaData) throws DeploymentException
-   {
-      if (unit.isAttachmentPresent(ClassLoadingMetaData.class))
-         return;
-
-      OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
-      if (bundleState == null)
-         throw new IllegalStateException("No bundle state");
-      
-      OSGiBundleManager bundleManager = bundleState.getBundleManager();
-      
-      ClassLoadingMetaData classLoadingMetaData = new ClassLoadingMetaData();
-      classLoadingMetaData.setName(bundleState.getSymbolicName());
-      classLoadingMetaData.setVersion(bundleState.getVersion());
-      classLoadingMetaData.setDomain(domain != null ? domain.getName() : null);
-
-      CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
-      RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
-      
-      OSGiBundleCapability capability = OSGiBundleCapability.create(bundleState);
-      capabilities.addCapability(capability);
-      
-      List<ParameterizedAttribute> requireBundles = osgiMetaData.getRequireBundles();
-      if (requireBundles != null && requireBundles.isEmpty() == false)
-      {
-         for (ParameterizedAttribute requireBundle : requireBundles)
-         {
-            OSGiBundleRequirement requirement = OSGiBundleRequirement.create(requireBundle);
-            requirements.addRequirement(requirement);
-         }
-      }
-      
-      List<PackageAttribute> exported = osgiMetaData.getExportPackages();
-      if (exported != null && exported.isEmpty() == false)
-      {
-         for (PackageAttribute packageAttribute : exported)
-         {
-            OSGiPackageCapability packageCapability = OSGiPackageCapability.create(bundleState, packageAttribute); 
-            capabilities.addCapability(packageCapability);
-         }
-      }
-      
-      List<PackageAttribute> imported = osgiMetaData.getImportPackages();
-      if (imported != null && imported.isEmpty() == false)
-      {
-         SystemPackagesPlugin syspackPlugin = bundleManager.getPlugin(SystemPackagesPlugin.class);
-         for (PackageAttribute packageAttribute : imported)
-         {
-            String packageName = packageAttribute.getAttribute();
-            
-            // [TODO] Should system packages be added as capabilities?
-            boolean isSystemPackage = syspackPlugin.isSystemPackage(packageName);
-            if (isSystemPackage == false)
-            {
-               OSGiPackageRequirement requirement = OSGiPackageRequirement.create(bundleState, packageAttribute); 
-               requirements.addRequirement(requirement);
-            }
-         }
-      }
-      
-      // Add the OSGi ClassLoaderFactory if configured
-      if (factory != null)
-         unit.addAttachment(ClassLoaderFactory.class, factory);
-      
-      // [TODO] dynamic imports
-      
-      unit.addAttachment(ClassLoadingMetaData.class, classLoadingMetaData);
-      
-      // AnnotationMetaDataDeployer.ANNOTATION_META_DATA_COMPLETE
-      unit.addAttachment("org.jboss.deployment.annotation.metadata.complete", Boolean.TRUE);
-   }
-}

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderFactory.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderFactory.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -71,7 +71,9 @@
             VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit)unit;
             OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
             VirtualFile[] roots = getClassLoaderPolicyRoots(bundleState, vfsUnit);
-            return new OSGiClassLoaderPolicy(bundleState, roots);
+            ClassLoaderPolicy policy = new OSGiClassLoaderPolicy(bundleState, roots);
+            unit.addAttachment(ClassLoaderPolicy.class, policy);
+            return policy;
          }
 
          private VirtualFile[] getClassLoaderPolicyRoots(OSGiBundleState bundleState, VFSDeploymentUnit vfsUnit)

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -23,24 +23,36 @@
 
 // $Id$
 
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.jboss.classloading.spi.dependency.Module;
 import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.plugins.classloader.VFSDeploymentClassLoaderPolicyModule;
 import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.deployers.OSGiBundleNativeCodeDeployer;
 import org.jboss.virtual.VirtualFile;
 
 /**
- * OSGiClassLoaderPolicy
+ * The ClassLoaderPolicy for OSGi bundles.
  * 
+ * This implementation supports the notion of OSGi Native Code Libraries.
+ * The library map is initialized in {@link OSGiBundleNativeCodeDeployer}.
+ * 
  * @author Thomas.Diesler at jboss.com
  * @since 11-Sep-2209
  */
 public class OSGiClassLoaderPolicy extends VFSClassLoaderPolicy
 {
+   private Map<String, URL> libraryMap = new HashMap<String, URL>();
+   
    public OSGiClassLoaderPolicy(OSGiBundleState bundleState, VirtualFile[] roots)
    {
       super(roots);
+      
       if (bundleState == null)
          throw new IllegalArgumentException("Null bundleState");
 
@@ -61,4 +73,25 @@
       setBlackListable(vfsModule.isBlackListable());
       setDelegates(vfsModule.getDelegates());
    }
+
+   public Map<String, URL> getLibraryMapppings()
+   {
+      return Collections.unmodifiableMap(libraryMap);
+   }
+
+   public void addLibraryMapping(String libname, URL liburl)
+   {
+      libraryMap.put(libname, liburl);
+   }
+
+   public String findLibrary(String libname)
+   {
+      URL liburl = libraryMap.get(libname);
+      
+      // [TODO] why does the TCK use 'Native' to mean 'libNative' ? 
+      if (liburl == null)
+         liburl = libraryMap.get("lib" + libname);
+         
+      return (liburl != null ? liburl.toExternalForm() : null);
+   }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderSystem.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderSystem.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderSystem.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -24,8 +24,10 @@
 import org.jboss.classloader.plugins.filter.PatternClassFilter;
 import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
 import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
 import org.jboss.classloader.spi.ClassLoaderSystem;
 import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.base.BaseClassLoader;
 import org.jboss.classloader.spi.filter.ClassFilterUtils;
 import org.jboss.classloader.spi.filter.RecursivePackageClassFilter;
 import org.jboss.osgi.framework.bundle.AbstractBundleState;
@@ -60,4 +62,10 @@
    {
       return new ClassLoaderDomain(name);
    }
+
+   @Override
+   protected BaseClassLoader createClassLoader(ClassLoaderPolicy policy)
+   {
+      return new OSGiBundleClassLoader(policy);
+   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -191,7 +191,7 @@
       if (reqVersionRange.isInRange(capVersion) == false)
          return false;
 
-      OSGiMetaData metaData = bundleState.getMetaData();
+      OSGiMetaData osgiMetaData = bundleState.getOSGiMetaData();
       PackageAttribute capParameters = exportPackage;
       PackageAttribute reqParameters = packageRequirement.getPackageMetaData();
 
@@ -223,13 +223,13 @@
 
                if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(name))
                {
-                  if (otherValue.equals(metaData.getBundleSymbolicName()) == false)
+                  if (otherValue.equals(osgiMetaData.getBundleSymbolicName()) == false)
                      validMatch = false;
                }
                else if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name))
                {
                   VersionRange range = (VersionRange)AbstractVersionRange.valueOf(otherValue);
-                  if (range.isInRange(metaData.getBundleVersion()) == false)
+                  if (range.isInRange(osgiMetaData.getBundleVersion()) == false)
                      validMatch = false;
                }
                else if (Constants.PACKAGE_SPECIFICATION_VERSION.equals(name) || Constants.VERSION_ATTRIBUTE.equals(name))

Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleClassLoadingDeployer.java (from rev 98016, projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoadingDeployer.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleClassLoadingDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleClassLoadingDeployer.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -0,0 +1,156 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.deployers;
+
+// $Id: $
+
+import java.util.List;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.RequirementsMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.classloading.OSGiBundleCapability;
+import org.jboss.osgi.framework.classloading.OSGiBundleRequirement;
+import org.jboss.osgi.framework.classloading.OSGiPackageCapability;
+import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.PackageAttribute;
+import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
+import org.jboss.osgi.framework.plugins.SystemPackagesPlugin;
+
+/**
+ * OSGiBundleClassLoadingDeployer.<p>
+ * 
+ * This deployer maps osgi metadata into our classloading metadata.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleClassLoadingDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
+{
+   private ClassLoaderDomain domain;
+   private ClassLoaderFactory factory;
+   
+   /**
+    * Create a new OSGiBundleClassLoadingDeployer.
+    */
+   public OSGiBundleClassLoadingDeployer()
+   {
+      super(OSGiMetaData.class);
+      addInput(OSGiBundleState.class);
+      setOutput(ClassLoadingMetaData.class);
+      setStage(DeploymentStages.POST_PARSE);
+      setTopLevelOnly(true);
+   }
+
+   public void setDomain(ClassLoaderDomain domain)
+   {
+      this.domain = domain;
+   }
+
+   public void setFactory(ClassLoaderFactory factory)
+   {
+      this.factory = factory;
+   }
+
+   @Override
+   public void deploy(DeploymentUnit unit, OSGiMetaData osgiMetaData) throws DeploymentException
+   {
+      if (unit.isAttachmentPresent(ClassLoadingMetaData.class))
+         return;
+
+      OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+      if (bundleState == null)
+         throw new IllegalStateException("No bundle state");
+      
+      OSGiBundleManager bundleManager = bundleState.getBundleManager();
+      
+      ClassLoadingMetaData classLoadingMetaData = new ClassLoadingMetaData();
+      classLoadingMetaData.setName(bundleState.getSymbolicName());
+      classLoadingMetaData.setVersion(bundleState.getVersion());
+      classLoadingMetaData.setDomain(domain != null ? domain.getName() : null);
+
+      CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
+      RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
+      
+      OSGiBundleCapability capability = OSGiBundleCapability.create(bundleState);
+      capabilities.addCapability(capability);
+      
+      List<ParameterizedAttribute> requireBundles = osgiMetaData.getRequireBundles();
+      if (requireBundles != null && requireBundles.isEmpty() == false)
+      {
+         for (ParameterizedAttribute requireBundle : requireBundles)
+         {
+            OSGiBundleRequirement requirement = OSGiBundleRequirement.create(requireBundle);
+            requirements.addRequirement(requirement);
+         }
+      }
+      
+      List<PackageAttribute> exported = osgiMetaData.getExportPackages();
+      if (exported != null && exported.isEmpty() == false)
+      {
+         for (PackageAttribute packageAttribute : exported)
+         {
+            OSGiPackageCapability packageCapability = OSGiPackageCapability.create(bundleState, packageAttribute); 
+            capabilities.addCapability(packageCapability);
+         }
+      }
+      
+      List<PackageAttribute> imported = osgiMetaData.getImportPackages();
+      if (imported != null && imported.isEmpty() == false)
+      {
+         SystemPackagesPlugin syspackPlugin = bundleManager.getPlugin(SystemPackagesPlugin.class);
+         for (PackageAttribute packageAttribute : imported)
+         {
+            String packageName = packageAttribute.getAttribute();
+            
+            // [TODO] Should system packages be added as capabilities?
+            boolean isSystemPackage = syspackPlugin.isSystemPackage(packageName);
+            if (isSystemPackage == false)
+            {
+               OSGiPackageRequirement requirement = OSGiPackageRequirement.create(bundleState, packageAttribute); 
+               requirements.addRequirement(requirement);
+            }
+         }
+      }
+      
+      // Add the OSGi ClassLoaderFactory if configured
+      if (factory != null)
+         unit.addAttachment(ClassLoaderFactory.class, factory);
+      
+      // [TODO] dynamic imports
+      
+      unit.addAttachment(ClassLoadingMetaData.class, classLoadingMetaData);
+      
+      // AnnotationMetaDataDeployer.ANNOTATION_META_DATA_COMPLETE
+      unit.addAttachment("org.jboss.deployment.annotation.metadata.complete", Boolean.TRUE);
+   }
+}

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -0,0 +1,211 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.deployers;
+
+// $Id: $
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.classloading.OSGiClassLoaderPolicy;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.Parameter;
+import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
+import org.osgi.framework.Constants;
+
+/**
+ * A deployer that takes care of loading native code libraries.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 19-Dec-2009
+ */
+public class OSGiBundleNativeCodeDeployer extends AbstractRealDeployer
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(OSGiBundleNativeCodeDeployer.class);
+
+   /** Maps an alias to an OSGi processor name */
+   private static Map<String, String> processorAlias = new HashMap<String, String>();
+   static
+   {
+      processorAlias.put("pentium", "x86");
+      processorAlias.put("i386", "x86");
+      processorAlias.put("i486", "x86");
+      processorAlias.put("i586", "x86");
+      processorAlias.put("i686", "x86");
+      processorAlias.put("amd64", "x86-64");
+      processorAlias.put("em64t", "x86-64");
+      processorAlias.put("x86_64", "x86-64");
+   }
+   
+   /** Maps an alias to an OSGi osname */
+   private static Map<String, String> osAlias = new HashMap<String, String>();
+   static
+   {
+      osAlias.put("SymbianOS", "Epoc32");
+      osAlias.put("hp-ux", "HPUX");
+      osAlias.put("Mac OS", "MacOS");
+      osAlias.put("Mac OS X", "MacOSX");
+      osAlias.put("OS/2", "OS2");
+      osAlias.put("procnto", "QNX");
+      osAlias.put("Win95", "Windows95");
+      osAlias.put("Windows 95", "Windows95");
+      osAlias.put("Win32", "Windows95");
+      osAlias.put("Win98", "Windows98");
+      osAlias.put("Windows 98", "Windows98");
+      osAlias.put("Win32", "Windows98");
+      osAlias.put("WinNT", "WindowsNT");
+      osAlias.put("Windows NT", "WindowsNT");
+      osAlias.put("Win32", "WindowsNT");
+      osAlias.put("WinCE", "WindowsCE");
+      osAlias.put("Windows CE", "WindowsCE");
+      osAlias.put("Win2000", "Windows2000");
+      osAlias.put("Windows 2000", "Windows2000");
+      osAlias.put("Win32", "Windows2000");
+      osAlias.put("Win2003", "Windows2003");
+      osAlias.put("Windows 2003", "Windows2003");
+      osAlias.put("Win32", "Windows2003");
+      osAlias.put("Windows Server 2003", "Windows2003");
+      osAlias.put("WinXP", "WindowsXP");
+      osAlias.put("Windows XP", "WindowsXP");
+      osAlias.put("Win32", "WindowsXP");
+      osAlias.put("WinVista", "WindowsVista");
+      osAlias.put("Windows Vista", "WindowsVista");
+      osAlias.put("Win32", "WindowsVista");
+   }
+   
+   public OSGiBundleNativeCodeDeployer()
+   {
+      setInput(ClassLoaderFactory.class);
+      addInput(ClassLoaderPolicy.class);
+      addInput(OSGiBundleState.class);
+      setStage(DeploymentStages.CLASSLOADER);
+      setTopLevelOnly(true);
+   }
+
+   @Override
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+      if (bundleState == null)
+         throw new IllegalStateException("No bundle state");
+
+      OSGiMetaData osgiMetaData = bundleState.getOSGiMetaData();
+      List<ParameterizedAttribute> nativeCodeParams = osgiMetaData.getBundleNativeCode();
+      if (nativeCodeParams == null)
+         return;
+      
+      OSGiBundleManager bundleManager = bundleState.getBundleManager();
+      String fwOSName = bundleManager.getProperty(Constants.FRAMEWORK_OS_NAME);
+      String fwProcessor = bundleManager.getProperty(Constants.FRAMEWORK_PROCESSOR);
+      //String fwOSVersion = bundleManager.getProperty(Constants.FRAMEWORK_OS_VERSION);
+      
+      List<ParameterizedAttribute> matchedParams = new ArrayList<ParameterizedAttribute>();
+      for (ParameterizedAttribute param : nativeCodeParams)
+      {
+         // Only select the native code clauses for which the following expressions all evaluate to true
+         //  * osname ~= [org.osgi.framework.os.name]
+         //  * processor ~= [org.osgi.framework.processor]
+         //  * osversion range includes [org.osgi.framework.os.version] or osversion is not specified
+         //  * language ~= [org.osgi.framework.language] or language is not specified
+         //  * selection-filter evaluates to true when using the values of the system properties or selection-filter is not specified
+
+         Parameter osnameParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_OSNAME);
+         Parameter procParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_PROCESSOR);
+         //Parameter osversionParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_OSVERSION);
+         
+         boolean match = (osnameParam != null);
+         
+         // osname ~= [org.osgi.framework.os.name]
+         if (match && osnameParam != null)
+         {
+            String osname = (String)osnameParam.getValue();
+            match = (osname.equals(fwOSName) || osname.equals(osAlias.get(fwOSName)));
+         }
+         
+         // processor ~= [org.osgi.framework.processor]
+         match &= (procParam != null);
+         if (match && procParam != null)
+         {
+            String processor = (String)procParam.getValue();
+            match = (processor.equals(fwProcessor) || processor.equals(processorAlias.get(fwProcessor)));
+         }
+         
+         // [TODO] osversion range includes [org.osgi.framework.os.version] or osversion is not specified
+         // [TODO] language ~= [org.osgi.framework.language] or language is not specified
+         // [TODO] selection-filter evaluates to true when using the values of the system properties or selection-filter is not specified
+         
+         if (match == true)
+            matchedParams.add(param);
+      }
+      
+      // If no native clauses were selected in step 1, this algorithm is terminated
+      // and a BundleException is thrown if the optional clause is not present
+      if (matchedParams.size() == 0)
+      {
+         // [TODO] optional
+         throw new DeploymentException("No native clauses selected from: " + nativeCodeParams);
+      }
+      
+      // The selected clauses are now sorted in the following priority order:
+      //  * osversion: floor of the osversion range in descending order, osversion not specified
+      //  * language: language specified, language not specified
+      //  * Position in the Bundle-NativeCode manifest header: lexical left to right
+      if (matchedParams.size() > 1)
+      {
+         // [TODO] selected clauses are now sorted
+      }
+
+      // The first clause of the sorted clauses from step 3 must be used as the selected native code clause
+      ParameterizedAttribute selectedParams = matchedParams.get(0);
+      log.debug("Selected native code clause: " + selectedParams);
+      
+      String nativeLib = selectedParams.getAttribute();
+      URL entryURL = bundleState.getEntry(nativeLib);
+      
+      // If a native code library in a selected native code clause cannot be found
+      // within the bundle then the bundle must fail to resolve
+      if (entryURL == null)
+         throw new DeploymentException("Cannot find native library: " + nativeLib);
+
+      // Get the library name key
+      String libname = new File(nativeLib).getName();
+      libname = libname.substring(0, libname.lastIndexOf('.'));
+      
+      // Add the native library mapping to the OSGiClassLoaderPolicy
+      OSGiClassLoaderPolicy policy = (OSGiClassLoaderPolicy)unit.getAttachment(ClassLoaderPolicy.class);
+      policy.addLibraryMapping(libname, entryURL);
+   }
+}

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiManifestParsingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiManifestParsingDeployer.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiManifestParsingDeployer.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -50,25 +50,25 @@
    @Override
    protected OSGiMetaData createMetaData(Manifest manifest) throws Exception
    {
-      AbstractOSGiMetaData metaData = new AbstractOSGiMetaData(manifest);
+      AbstractOSGiMetaData osgiMetaData = new AbstractOSGiMetaData(manifest);
       
       // At least one of these manifest headers must be there
       // Note, in R3 and R4 there is no common mandatory header
-      String bundleName = metaData.getBundleName();
-      String bundleVersion = metaData.getBundleVersion();
-      String bundleSymbolicName = metaData.getBundleSymbolicName();
+      String bundleName = osgiMetaData.getBundleName();
+      String bundleVersion = osgiMetaData.getBundleVersion();
+      String bundleSymbolicName = osgiMetaData.getBundleSymbolicName();
       if (bundleName == null && bundleVersion == null && bundleSymbolicName == null)
-         metaData = null;
+         osgiMetaData = null;
       
-      return metaData;
+      return osgiMetaData;
    }
 
    @Override
-   protected void init(VFSDeploymentUnit unit, OSGiMetaData metaData, VirtualFile file) throws Exception
+   protected void init(VFSDeploymentUnit unit, OSGiMetaData osgiMetaData, VirtualFile file) throws Exception
    {
-      super.init(unit, metaData, file);
+      super.init(unit, osgiMetaData, file);
 
-      String symbolicName = metaData.getBundleSymbolicName();
+      String symbolicName = osgiMetaData.getBundleSymbolicName();
       if (symbolicName != null)
       {
          // Add a marker that this is an R4 OSGi deployment

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolverBundleImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolverBundleImpl.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolverBundleImpl.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -37,16 +37,16 @@
  */
 public class ResolverBundleImpl extends AbstractResolverBundle
 {
-   private OSGiMetaData metaData;
+   private OSGiMetaData osgiMetaData;
 
    public ResolverBundleImpl(Bundle bundle)
    {
       super(bundle);
       
-      this.metaData = OSGiBundleState.assertBundleState(bundle).getMetaData();
+      this.osgiMetaData = OSGiBundleState.assertBundleState(bundle).getOSGiMetaData();
 
       // Initialize exported packages
-      List<PackageAttribute> exportPackages = metaData.getExportPackages();
+      List<PackageAttribute> exportPackages = osgiMetaData.getExportPackages();
       if (exportPackages != null)
       {
          for (PackageAttribute attr : exportPackages)
@@ -57,7 +57,7 @@
       }
 
       // Initialize imported packages
-      List<PackageAttribute> importPackages = metaData.getImportPackages();
+      List<PackageAttribute> importPackages = osgiMetaData.getImportPackages();
       if (importPackages != null)
       {
          for (PackageAttribute attr : importPackages)
@@ -68,7 +68,7 @@
       }
 
       // Initialize required bundles
-      List<ParameterizedAttribute> requireBundles = metaData.getRequireBundles();
+      List<ParameterizedAttribute> requireBundles = osgiMetaData.getRequireBundles();
       if (requireBundles != null)
       {
          for (ParameterizedAttribute attr : requireBundles)
@@ -82,6 +82,6 @@
 
    public boolean isSingleton()
    {
-      return metaData.isSingleton();
+      return osgiMetaData.isSingleton();
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java	2009-12-19 23:46:53 UTC (rev 98038)
@@ -405,7 +405,7 @@
       // The Require-Bundle header specifies that all exported packages from
       // another bundle must be imported, effectively requiring the public interface
       // of another bundle
-      OSGiMetaData osgiMetaData = bundle.getMetaData();
+      OSGiMetaData osgiMetaData = bundle.getOSGiMetaData();
       List<ParameterizedAttribute> requireBundles = osgiMetaData.getRequireBundles();
       if (requireBundles != null)
       {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2009-12-19 23:46:38 UTC (rev 98037)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2009-12-19 23:46:53 UTC (rev 98038)
@@ -142,6 +142,7 @@
   <bean name="OSGiBundleStateRemoveDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateRemoveDeployer">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiBundleNativeCodeDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleNativeCodeDeployer" />
   <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer" />
   <bean name="OSGiContextTrackerDeployer" class="org.jboss.osgi.framework.deployers.OSGiContextTrackerDeployer" />
 
@@ -162,7 +163,7 @@
   <bean name="OSGiClassLoaderFactory" class="org.jboss.osgi.framework.classloading.OSGiClassLoaderFactory" >
     <property name="system"><inject bean="OSGiClassLoaderSystem"/></property>
   </bean>
-  <bean name="OSGiBundleClassLoadingDeployer" class="org.jboss.osgi.framework.classloading.OSGiBundleClassLoadingDeployer">
+  <bean name="OSGiBundleClassLoadingDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleClassLoadingDeployer">
     <property name="domain"><inject bean="OSGiClassLoaderDomain"/></property>
     <property name="factory"><inject bean="OSGiClassLoaderFactory"/></property>
   </bean>




More information about the jboss-cvs-commits mailing list