]> git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/runtime/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/admin/OpenSession.java
Clean up directories
[gpl/argeo-slc.git] / legacy / runtime / org.argeo.slc.detached / src / main / java / org / argeo / slc / detached / admin / OpenSession.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.detached.admin;
17
18 import java.util.List;
19 import java.util.ArrayList;
20 import java.util.Properties;
21 import java.util.StringTokenizer;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.argeo.slc.detached.DetachedAdminCommand;
26 import org.argeo.slc.detached.DetachedException;
27 import org.argeo.slc.detached.DetachedRequest;
28 import org.argeo.slc.detached.DetachedSession;
29 import org.osgi.framework.Bundle;
30 import org.osgi.framework.BundleContext;
31
32 public class OpenSession implements DetachedAdminCommand {
33 private final static Log log = LogFactory.getLog(OpenSession.class);
34
35 public DetachedSession execute(DetachedRequest request,
36 BundleContext bundleContext) {
37
38 DetachedSession session = new DetachedSession();
39 session.setUuid(Long.toString(System.currentTimeMillis()));
40
41 Properties props = request.getProperties();
42 if (props.containsKey(DetachedSession.PROP_DO_IT_AGAIN_POLICY))
43 session.setDoItAgainPolicy(props
44 .getProperty(DetachedSession.PROP_DO_IT_AGAIN_POLICY));
45
46 String refreshedBundles = props
47 .getProperty("slc.detached.refreshedBundles");
48 if (refreshedBundles != null) {
49
50 List refreshedBundleNames = new ArrayList();
51 StringTokenizer st = new StringTokenizer(refreshedBundles, ",");
52 while (st.hasMoreTokens()) {
53 refreshedBundleNames.add(st.nextElement());
54 }
55
56 Bundle[] allBundles = bundleContext.getBundles();
57 Bundle[] bundlesToRefresh = new Bundle[refreshedBundleNames.size()];
58
59 log.debug("Bundles to refresh for DetachedSession:");
60
61 for(int i = 0; i < bundlesToRefresh.length; ++i) {
62 bundlesToRefresh[i] = getBundleForName((String)refreshedBundleNames.get(i), allBundles);
63 if(log.isDebugEnabled())
64 log.debug(" " + refreshedBundleNames.get(i));
65 }
66
67 (new MinimalBundlesManager(bundleContext)).upgradeSynchronous(bundlesToRefresh);
68 }
69
70 return session;
71 }
72
73 private Bundle getBundleForName(String symbolicName, Bundle[] bundles) {
74 for (int i = 0; i < bundles.length; i++) {
75 if (symbolicName.equals(bundles[i].getSymbolicName())) {
76 return bundles[i];
77 }
78 }
79 throw new DetachedException("No Bundle found for symbolic name " + symbolicName);
80 }
81 }