1 package org
.argeo
.slc
.osgi
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.osgi
.framework
.Bundle
;
11 import org
.osgi
.framework
.BundleContext
;
12 import org
.osgi
.framework
.BundleException
;
13 import org
.springframework
.osgi
.context
.BundleContextAware
;
15 public class BundlesManager
implements BundleContextAware
{
16 private final static Log log
= LogFactory
.getLog(BundlesManager
.class);
18 private BundleContext bundleContext
;
20 private List
<String
> urlsToInstall
;
24 if (urlsToInstall
!= null) {
25 Map
<String
, Bundle
> installedBundles
= new HashMap
<String
, Bundle
>();
26 for (Bundle bundle
: bundleContext
.getBundles())
27 installedBundles
.put(bundle
.getLocation(), bundle
);
29 for (String url
: urlsToInstall
)
32 if (installedBundles
.containsKey(url
)) {
33 Bundle bundle
= installedBundles
.get(url
);
35 log
.debug("Bundle " + bundle
.getSymbolicName()
36 + " already installed from " + url
);
38 Bundle bundle
= bundleContext
.installBundle(url
);
39 log
.debug("Installed bundle "
40 + bundle
.getSymbolicName() + " from " + url
);
42 } catch (BundleException e
) {
43 log
.warn("Could not install bundle from " + url
+ ": "
50 public void setBundleContext(BundleContext bundleContext
) {
51 this.bundleContext
= bundleContext
;
54 public void setUrlsToInstall(List
<String
> urlsToInstall
) {
55 this.urlsToInstall
= urlsToInstall
;