X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fkernel%2FActivator.java;h=5ec9f5087649474b1fc9284a502a8956070412ef;hb=f2688921e89c75ee626ff79b64105c577c415cca;hp=4d166eaf63db619ed0b761034299a154f30cfd39;hpb=63446804f4954bfedd50d8c692bde0fab13aa1ec;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/Activator.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/Activator.java index 4d166eaf6..5ec9f5087 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/Activator.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/Activator.java @@ -1,15 +1,27 @@ package org.argeo.cms.internal.kernel; +import java.util.UUID; + import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +/** + * Activates the {@link Kernel} from the provided {@link BundleContext}. Gives + * access to kernel information for the rest of the bundle (and only it) + */ public class Activator implements BundleActivator { + private final static String systemKey = UUID.randomUUID().toString(); + + private static BundleContext bundleContext; private Kernel kernel; @Override public void start(BundleContext context) throws Exception { + assert bundleContext == null; assert kernel == null; - kernel = new Kernel(context); + + bundleContext = context; + kernel = new Kernel(bundleContext); kernel.init(); } @@ -17,6 +29,23 @@ public class Activator implements BundleActivator { public void stop(BundleContext context) throws Exception { kernel.destroy(); kernel = null; + bundleContext = null; + } + + /** + * Singleton interface to the {@link BundleContext} related to the calling + * thread. Can be used only within the CMS bundle. + */ + public static BundleContext getBundleContext() { + return bundleContext; + } + + /** + * @return a String which is guaranteed to be unique between and constant + * within a Java static context (typically a VM launch) + */ + public final static String getSystemKey() { + return systemKey; } }