Search in sources :

Example 1 with SlingContextFactory

use of org.apache.sling.scripting.javascript.helper.SlingContextFactory in project sling by apache.

the class RhinoJavaScriptEngineFactory method activate.

// ---------- SCR integration
@Activate
protected void activate(final ComponentContext context, final RhinoJavaScriptEngineFactoryConfiguration configuration) {
    Dictionary<?, ?> props = context.getProperties();
    boolean debugging = getProperty("org.apache.sling.scripting.javascript.debug", props, context.getBundleContext(), false);
    optimizationLevel = readOptimizationLevel(configuration);
    // setup the wrap factory
    wrapFactory = new SlingWrapFactory();
    // initialize the Rhino Context Factory
    SlingContextFactory.setup(this);
    Context cx = Context.enter();
    setEngineName(getEngineName() + " (" + cx.getImplementationVersion() + ")");
    languageVersion = String.valueOf(cx.getLanguageVersion());
    Context.exit();
    setExtensions(ECMA_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
    setMimeTypes("text/javascript", "application/ecmascript", "application/javascript");
    setNames("javascript", ECMA_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
    final ContextFactory contextFactory = ContextFactory.getGlobal();
    if (contextFactory instanceof SlingContextFactory) {
        ((SlingContextFactory) contextFactory).setDebugging(debugging);
    }
    // set the dynamic class loader as the application class loader
    final DynamicClassLoaderManager dclm = this.dynamicClassLoaderManager;
    if (dclm != null) {
        contextFactory.initApplicationClassLoader(dynamicClassLoaderManager.getDynamicClassLoader());
    }
    log.info("Activated with optimization level {}", optimizationLevel);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Context(org.mozilla.javascript.Context) BundleContext(org.osgi.framework.BundleContext) SlingContextFactory(org.apache.sling.scripting.javascript.helper.SlingContextFactory) ContextFactory(org.mozilla.javascript.ContextFactory) SlingContextFactory(org.apache.sling.scripting.javascript.helper.SlingContextFactory) SlingWrapFactory(org.apache.sling.scripting.javascript.helper.SlingWrapFactory) DynamicClassLoaderManager(org.apache.sling.commons.classloader.DynamicClassLoaderManager) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with SlingContextFactory

use of org.apache.sling.scripting.javascript.helper.SlingContextFactory in project sling by apache.

the class RhinoJavaScriptEngineFactory method dropRootScope.

private void dropRootScope() {
    // ensure the debugger is closed if the root scope will
    // be replaced to ensure no references to the old scope
    // and context remain
    ContextFactory contextFactory = ContextFactory.getGlobal();
    if (contextFactory instanceof SlingContextFactory) {
        ((SlingContextFactory) contextFactory).exitDebugger();
    }
    // drop the scope
    rootScope = null;
}
Also used : SlingContextFactory(org.apache.sling.scripting.javascript.helper.SlingContextFactory) ContextFactory(org.mozilla.javascript.ContextFactory) SlingContextFactory(org.apache.sling.scripting.javascript.helper.SlingContextFactory)

Aggregations

SlingContextFactory (org.apache.sling.scripting.javascript.helper.SlingContextFactory)2 ContextFactory (org.mozilla.javascript.ContextFactory)2 DynamicClassLoaderManager (org.apache.sling.commons.classloader.DynamicClassLoaderManager)1 SlingWrapFactory (org.apache.sling.scripting.javascript.helper.SlingWrapFactory)1 Context (org.mozilla.javascript.Context)1 BundleContext (org.osgi.framework.BundleContext)1 ComponentContext (org.osgi.service.component.ComponentContext)1 Activate (org.osgi.service.component.annotations.Activate)1