2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.detached
.admin
;
18 import java
.util
.List
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Properties
;
21 import java
.util
.StringTokenizer
;
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
;
32 public class OpenSession
implements DetachedAdminCommand
{
33 private final static Log log
= LogFactory
.getLog(OpenSession
.class);
35 public DetachedSession
execute(DetachedRequest request
,
36 BundleContext bundleContext
) {
38 DetachedSession session
= new DetachedSession();
39 session
.setUuid(Long
.toString(System
.currentTimeMillis()));
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
));
46 String refreshedBundles
= props
47 .getProperty("slc.detached.refreshedBundles");
48 if (refreshedBundles
!= null) {
50 List refreshedBundleNames
= new ArrayList();
51 StringTokenizer st
= new StringTokenizer(refreshedBundles
, ",");
52 while (st
.hasMoreTokens()) {
53 refreshedBundleNames
.add(st
.nextElement());
56 Bundle
[] allBundles
= bundleContext
.getBundles();
57 Bundle
[] bundlesToRefresh
= new Bundle
[refreshedBundleNames
.size()];
59 log
.debug("Bundles to refresh for DetachedSession:");
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
));
67 (new MinimalBundlesManager(bundleContext
)).upgradeSynchronous(bundlesToRefresh
);
73 private Bundle
getBundleForName(String symbolicName
, Bundle
[] bundles
) {
74 for (int i
= 0; i
< bundles
.length
; i
++) {
75 if (symbolicName
.equals(bundles
[i
].getSymbolicName())) {
79 throw new DetachedException("No Bundle found for symbolic name " + symbolicName
);