1 package org
.argeo
.init
.osgi
;
3 import java
.util
.Optional
;
5 import org
.osgi
.framework
.Bundle
;
6 import org
.osgi
.framework
.BundleContext
;
7 import org
.osgi
.framework
.wiring
.BundleWiring
;
10 * A {@link ClassLoader} based on a {@link Bundle} from another OSGi runtime.
12 class ForeignBundleClassLoader
extends ClassLoader
{// implements BundleReference {
13 private BundleContext localBundleContext
;
14 private Bundle foreignBundle
;
16 public ForeignBundleClassLoader(BundleContext localBundleContext
, Bundle foreignBundle
) {
17 super("Foreign bundle " + foreignBundle
.toString(), Optional
.ofNullable(foreignBundle
.adapt(BundleWiring
.class))
18 .map((bw
) -> bw
.getClassLoader()).orElse(null));
19 this.localBundleContext
= localBundleContext
;
20 this.foreignBundle
= foreignBundle
;
24 protected Bundle
getBundle() {
25 return localBundleContext
.getBundle(foreignBundle
.getLocation());
29 // public URL getResource(String resName) {
30 // URL res = super.getResource(resName);
35 // protected URL findResource(String resName) {
36 // Bundle localBundle = getBundle();
37 // if (localBundle != null) {
38 // URL res = localBundle.getEntry(resName);