1 package org
.argeo
.init
.a2
;
3 import org
.argeo
.init
.osgi
.OsgiBootUtils
;
4 import org
.osgi
.framework
.Bundle
;
5 import org
.osgi
.framework
.BundleContext
;
6 import org
.osgi
.framework
.FrameworkUtil
;
7 import org
.osgi
.framework
.Version
;
10 * A running OSGi bundle context seen as a {@link AbstractProvisioningSource}.
12 class OsgiContext
extends AbstractProvisioningSource
{
13 private final BundleContext bc
;
15 private A2Contribution runtimeContribution
;
17 public OsgiContext(BundleContext bc
) {
20 runtimeContribution
= getOrAddContribution(A2Contribution
.RUNTIME
);
23 public OsgiContext() {
25 Bundle bundle
= FrameworkUtil
.getBundle(OsgiContext
.class);
27 throw new IllegalArgumentException(
28 "OSGi Boot bundle must be started or a bundle context must be specified");
29 this.bc
= bundle
.getBundleContext();
33 for (Bundle bundle
: bc
.getBundles()) {
34 registerBundle(bundle
);
39 void registerBundle(Bundle bundle
) {
40 String componentId
= bundle
.getSymbolicName();
41 Version version
= bundle
.getVersion();
42 A2Component component
= runtimeContribution
.getOrAddComponent(componentId
);
43 A2Module module
= component
.getOrAddModule(version
, bundle
);
44 if (OsgiBootUtils
.isDebug())
45 OsgiBootUtils
.debug("Registered bundle module " + module
+ " (location id: " + bundle
.getLocation() + ")");