]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/kernel/Activator.java
- Improve CMS login (HTTP session now supported)
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / Activator.java
1 package org.argeo.cms.internal.kernel;
2
3 import java.util.UUID;
4
5 import org.argeo.security.SystemAuthentication;
6 import org.osgi.framework.BundleActivator;
7 import org.osgi.framework.BundleContext;
8
9 /**
10 * Activates the {@link Kernel} from the provided {@link BundleContext}. Gives
11 * access to kernel information for the rest of the bundle (and only it)
12 */
13 public class Activator implements BundleActivator {
14 private final static String systemKey;
15 static {
16 systemKey = UUID.randomUUID().toString();
17 System.setProperty(SystemAuthentication.SYSTEM_KEY_PROPERTY, systemKey);
18 }
19
20 private static BundleContext bundleContext;
21 private Kernel kernel;
22
23 @Override
24 public void start(BundleContext context) throws Exception {
25 assert bundleContext == null;
26 assert kernel == null;
27 bundleContext = context;
28 kernel = new Kernel();
29 kernel.init();
30 }
31
32 @Override
33 public void stop(BundleContext context) throws Exception {
34 kernel.destroy();
35 kernel = null;
36 bundleContext = null;
37 }
38
39 /**
40 * Singleton interface to the {@link BundleContext} related to the calling
41 * thread.
42 *
43 * @BundleScope
44 */
45 public static BundleContext getBundleContext() {
46 return bundleContext;
47 }
48
49 /**
50 * @return a String which is guaranteed to be unique between and constant
51 * within a Java static context (typically a VM launch)
52 * @BundleScope
53 */
54 public final static String getSystemKey() {
55 return systemKey;
56 }
57 }