Thanks Jeff, that's exactly what I was looking for!
... and it works!

Le 21/11/2012 17:00, Jeff Emanuel a écrit :
I've included code snippets below.  getBundles() returns the Bundles that
I want to allow access to from Jython.  I don't deal with Bundle
unloading or reloading. 


    Bundle[] bundles = getBundles(context);
    savePackageNames(bundles);
    _bundlesClassLoader = new BundlesClassLoader(bundles,
                                                 getClass().getClassLoader());

    // Later for each required interpreter:

      PySystemState.initialize(System.getProperties(),postProps,
                               new String[]{""}, bundlesClassLoader);

      _interp = new PythonInterpreter();

      // Add packages from plugin to interpreter.  These are packages available
      // to the bundlesClassLoader.
      String[] packageNames = plugin.getPackageNames();  // _packageNames below.
      for (int i=0;i<packageNames.length;++i) {
        PySystemState.add_package(packageNames[i]);
      }




  private String[] _packageNames;
  private void savePackageNames(Bundle[] bundles) {
    ArrayList<String> names = new ArrayList<String>();
    for (int i=0;i<bundles.length;++i) {
      Dictionary headers = bundles[i].getHeaders();
      String packages=(String)headers.get("Provide-Package");
      addPackageNames(packages,names);
      packages=(String)headers.get("Export-Package");
      addPackageNames(packages,names);
    }
    _packageNames = names.toArray(new String[names.size()]);
  }


class BundlesClassLoader extends ClassLoader {

  private Bundle[] _bundles;
  public BundlesClassLoader(Bundle[] bundles, ClassLoader parent) {
    super(parent);
    _bundles=bundles;
  }
  protected Class findClass(String className)
    throws ClassNotFoundException {
    try {
      return super.findClass(className);
    } catch (ClassNotFoundException e) {
      // Look for the class from the bundles.
      for (int i=0;i<_bundles.length;++i) {
        try {
          return _bundles[i].loadClass(className);
        } catch (ClassNotFoundException e2) {         
        }
      }
      // Didn't find the class anywhere, rethrow e.
      throw e;
    }
  }
}