+ public OsgiBundle installModule(Distribution distribution) {
+ if (!(distribution instanceof StreamReadable))
+ throw new UnsupportedException("distribution", distribution);
+
+ StreamReadable sr = (StreamReadable) distribution;
+ Bundle bundle;
+ try {
+ bundle = bundleContext.installBundle(sr.toString(), sr
+ .getInputStream());
+ } catch (BundleException e) {
+ throw new SlcException(
+ "Cannot install OSGi bundle " + distribution, e);
+ }
+ return new OsgiBundle(bundle);
+ }
+
+ public void uninstallModule(NameVersion nameVersion) {
+ Bundle bundle = findBundle(nameVersion);
+ try {
+ bundle.uninstall();
+ } catch (BundleException e) {
+ throw new SlcException("Cannot uninstall " + bundle, e);
+ }
+ }
+
+ public void startModule(NameVersion nameVersion) {
+ Bundle bundle = findBundle(nameVersion);
+ try {
+ bundle.start();
+ // TODO: use bundle manager
+ } catch (BundleException e) {
+ throw new SlcException("Cannot uninstall " + bundle, e);
+ }
+ }
+
+ protected Bundle findBundle(NameVersion nameVersion) {
+ Bundle[] bundles = bundleContext.getBundles();
+ for (Bundle bundle : bundles) {
+ OsgiBundle osgiBundle = new OsgiBundle(bundle);
+ if (osgiBundle.equals(nameVersion)) {
+ return bundle;
+ }
+ }
+ throw new SlcException("Could not find bundle " + nameVersion);
+ }
+
+ public void shutdown() {
+ throw new UnsupportedException();
+ }
+