]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/kernel/Activator.java
Fix typo in string validation
[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.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.osgi.framework.BundleActivator;
8 import org.osgi.framework.BundleContext;
9
10 /**
11 * Activates the {@link Kernel} from the provided {@link BundleContext}. Gives
12 * access to kernel information for the rest of the bundle (and only it)
13 */
14 public class Activator implements BundleActivator {
15 public final static String SYSTEM_KEY_PROPERTY = "argeo.security.systemKey";
16 private final Log log = LogFactory.getLog(Activator.class);
17
18 private final static String systemKey;
19 static {
20 systemKey = UUID.randomUUID().toString();
21 System.setProperty(SYSTEM_KEY_PROPERTY, systemKey);
22 }
23
24 private static BundleContext bundleContext;
25 private static Kernel kernel;
26
27 @Override
28 public void start(BundleContext context) throws Exception {
29 assert bundleContext == null;
30 assert kernel == null;
31 bundleContext = context;
32 try {
33 kernel = new Kernel();
34 kernel.init();
35 } catch (Exception e) {
36 log.error("Cannot boot kernel", e);
37 }
38 }
39
40 @Override
41 public void stop(BundleContext context) throws Exception {
42 kernel.destroy();
43 kernel = null;
44 bundleContext = null;
45 }
46
47 /**
48 * Singleton interface to the {@link BundleContext} related to the calling
49 * thread.
50 *
51 * @BundleScope
52 */
53 public static BundleContext getBundleContext() {
54 return bundleContext;
55 }
56
57 public static KernelHeader getKernelHeader() {
58 return kernel;
59 }
60
61 /**
62 * @return a String which is guaranteed to be unique between and constant
63 * within a Java static context (typically a VM launch)
64 * @BundleScope
65 */
66 public final static String getSystemKey() {
67 return systemKey;
68 }
69 }