]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/init/a2/OsgiContext.java
Introduce CMS-specific user APIs, based at this stage on OSGi UserAdmin
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / init / a2 / OsgiContext.java
1 package org.argeo.init.a2;
2
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;
8
9 /** A running OSGi bundle context seen as a {@link AbstractProvisioningSource}. */
10 class OsgiContext extends AbstractProvisioningSource {
11 private final BundleContext bc;
12
13 public OsgiContext(BundleContext bc) {
14 super(false);
15 this.bc = bc;
16 }
17
18 public OsgiContext() {
19 super(false);
20 Bundle bundle = FrameworkUtil.getBundle(OsgiContext.class);
21 if (bundle == null)
22 throw new IllegalArgumentException(
23 "OSGi Boot bundle must be started or a bundle context must be specified");
24 this.bc = bundle.getBundleContext();
25 }
26
27 void load() {
28 A2Contribution runtimeContribution = getOrAddContribution( A2Contribution.RUNTIME);
29 for (Bundle bundle : bc.getBundles()) {
30 // OsgiBootUtils.debug(bundle.getDataFile("/"));
31 String componentId = bundle.getSymbolicName();
32 Version version = bundle.getVersion();
33 A2Component component = runtimeContribution.getOrAddComponent(componentId);
34 A2Module module = component.getOrAddModule(version, bundle);
35 if (OsgiBootUtils.isDebug())
36 OsgiBootUtils.debug("Registered " + module + " (location id: " + bundle.getLocation() + ")");
37 }
38
39 }
40 }