1 package org
.argeo
.init
.osgi
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import java
.util
.Collections
;
7 import java
.util
.Dictionary
;
10 import java
.util
.Optional
;
11 import java
.util
.function
.Function
;
12 import java
.util
.stream
.Collectors
;
14 import org
.osgi
.framework
.Bundle
;
15 import org
.osgi
.framework
.BundleContext
;
16 import org
.osgi
.framework
.connect
.ConnectContent
;
19 * A {@link ConnectContent} based on a {@link Bundle} from another OSGi runtime.
21 class ForeignBundleConnectContent
implements ConnectContent
{
22 private final Bundle foreignBundle
;
23 private final ClassLoader classLoader
;
25 public ForeignBundleConnectContent(BundleContext localBundleContext
, Bundle foreignBundle
) {
26 this.foreignBundle
= foreignBundle
;
27 this.classLoader
= new ForeignBundleClassLoader(localBundleContext
, foreignBundle
);
31 public Optional
<Map
<String
, String
>> getHeaders() {
32 Dictionary
<String
, String
> dict
= foreignBundle
.getHeaders();
33 List
<String
> keys
= Collections
.list(dict
.keys());
34 Map
<String
, String
> dictCopy
= keys
.stream().collect(Collectors
.toMap(Function
.identity(), dict
::get
));
35 return Optional
.of(dictCopy
);
39 public Iterable
<String
> getEntries() throws IOException
{
40 List
<String
> lst
= Collections
.list(foreignBundle
.findEntries("", "*", true)).stream().map((u
) -> u
.getPath())
46 public Optional
<ConnectEntry
> getEntry(String path
) {
47 URL u
= foreignBundle
.getEntry(path
);
49 u
= foreignBundle
.getEntry("bin/" + path
);
50 // System.err.println(u2);
53 if ("plugin.xml".equals(path
))
54 return Optional
.empty();
55 if (path
.startsWith("META-INF/versions/"))
56 return Optional
.empty();
57 System
.err
.println(foreignBundle
.getSymbolicName() + " " + path
+ " not found");
58 return Optional
.empty();
61 ConnectEntry urlConnectEntry
= new ConnectEntry() {
64 public String
getName() {
69 public long getLastModified() {
70 return foreignBundle
.getLastModified();
74 public InputStream
getInputStream() throws IOException
{
75 return url
.openStream();
79 public long getContentLength() {
83 return Optional
.of(urlConnectEntry
);
87 public Optional
<ClassLoader
> getClassLoader() {
89 // cl = bundle.adapt(BundleWiring.class).getClassLoader();
91 // cl = subFrameworkClassLoader;
93 return Optional
.of(cl
);
94 // return Optional.empty();
98 public void open() throws IOException
{
102 public void close() throws IOException
{