]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/admin/OpenSession.java
Update headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.detached / src / main / java / org / argeo / slc / detached / admin / OpenSession.java
index 11966a97563af5371c5f156e68d92b80d611440f..48275c75b486ca88267b8bc9fde369a7ad66e484 100644 (file)
@@ -1,6 +1,24 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.argeo.slc.detached.admin;
 
+import java.util.List;
+import java.util.ArrayList;
 import java.util.Properties;
+import java.util.StringTokenizer;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -10,13 +28,13 @@ import org.argeo.slc.detached.DetachedRequest;
 import org.argeo.slc.detached.DetachedSession;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
 
 public class OpenSession implements DetachedAdminCommand {
        private final static Log log = LogFactory.getLog(OpenSession.class);
 
        public DetachedSession execute(DetachedRequest request,
                        BundleContext bundleContext) {
+               
                DetachedSession session = new DetachedSession();
                session.setUuid(Long.toString(System.currentTimeMillis()));
 
@@ -28,30 +46,36 @@ public class OpenSession implements DetachedAdminCommand {
                String refreshedBundles = props
                                .getProperty("slc.detached.refreshedBundles");
                if (refreshedBundles != null) {
-                       Bundle[] bundles = bundleContext.getBundles();
-                       Bundle bundle = null;
-                       for (int i = 0; i < bundles.length; i++) {
-                               if (bundles[i].getSymbolicName().equals(refreshedBundles)) {
-                                       bundle = bundles[i];
-                               }
-                       }
+                       
+                       List refreshedBundleNames = new ArrayList();
+                       StringTokenizer st = new StringTokenizer(refreshedBundles, ",");
+                       while (st.hasMoreTokens()) {
+                               refreshedBundleNames.add(st.nextElement());
+                       }                       
+
+                       Bundle[] allBundles = bundleContext.getBundles();
+                       Bundle[] bundlesToRefresh = new Bundle[refreshedBundleNames.size()];                                            
 
-                       if (bundle != null) {
-                               try {
-                                       bundle.stop();
-                                       bundle.update();
-                                       bundle.start();
-                                       log.info("Refreshed bundle " + bundle.getSymbolicName());
-                               } catch (BundleException e) {
-                                       throw new DetachedException("Could not refresh bundle "
-                                                       + bundle.getSymbolicName(), e);
-                               }
-                       } else {
-                               log.warn("Did not find bundle to refresh " + refreshedBundles);
+                       log.debug("Bundles to refresh for DetachedSession:");
+                       
+                       for(int i = 0; i < bundlesToRefresh.length; ++i) {
+                               bundlesToRefresh[i] = getBundleForName((String)refreshedBundleNames.get(i), allBundles);
+                               if(log.isDebugEnabled())
+                                       log.debug(" " + refreshedBundleNames.get(i));
                        }
 
+                       (new MinimalBundlesManager(bundleContext)).upgradeSynchronous(bundlesToRefresh);
                }
 
                return session;
        }
+       
+       private Bundle getBundleForName(String symbolicName, Bundle[] bundles) {
+               for (int i = 0; i < bundles.length; i++) {
+                       if (symbolicName.equals(bundles[i].getSymbolicName())) {
+                               return bundles[i];
+                       }
+               }
+               throw new DetachedException("No Bundle found for symbolic name " + symbolicName);
+       }
 }