]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Factorize bundles management
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 13 Jun 2009 19:45:06 +0000 (19:45 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 13 Jun 2009 19:45:06 +0000 (19:45 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2549 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/BundlesManager.java

index 3ac12603eeb9c9775da76c9908866d6359b4be57..445fdf98cdcd3eac6bc7ef7113b057eca22d1113 100644 (file)
@@ -1,5 +1,8 @@
 package org.argeo.slc.osgi;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
@@ -12,8 +15,10 @@ import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContext;
 import org.springframework.osgi.context.BundleContextAware;
 
+/** Wraps access to a {@link BundleContext} */
 public class BundlesManager implements BundleContextAware, FrameworkListener,
                InitializingBean {
        private final static Log log = LogFactory.getLog(BundlesManager.class);
@@ -127,6 +132,24 @@ public class BundlesManager implements BundleContextAware, FrameworkListener,
                }
        }
 
+       public List<ApplicationContext> listPublishedApplicationContexts(
+                       String filter) {
+               try {
+                       List<ApplicationContext> lst = new ArrayList<ApplicationContext>();
+                       ServiceReference[] sfs = bundleContext.getServiceReferences(
+                                       ApplicationContext.class.getName(), filter);
+                       for (int i = 0; i < sfs.length; i++) {
+                               ApplicationContext applicationContext = (ApplicationContext) bundleContext
+                                               .getService(sfs[i]);
+                               lst.add(applicationContext);
+                       }
+                       return lst;
+               } catch (InvalidSyntaxException e) {
+                       throw new SlcException(
+                                       "Cannot list published application contexts", e);
+               }
+       }
+
        public ServiceReference[] getServiceRefSynchronous(String clss,
                        String filter) throws InvalidSyntaxException {
                if (log.isTraceEnabled())