Example usage for jdk.nashorn.internal.runtime ScriptObject putAll

List of usage examples for jdk.nashorn.internal.runtime ScriptObject putAll

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime ScriptObject putAll.

Prototype

public void putAll(final Map<?, ?> otherMap, final boolean strict) 

Source Link

Document

Put several properties in the ScriptObject given a mapping of their keys to their values (java.util.Map-like method to help ScriptObjectMirror implementation)

Usage

From source file:com.threecrickets.scripturian.adapter.NashornAdapter.java

License:LGPL

/**
 * Gets the Nashorn global scope associated with the execution context,
 * creating it if it doesn't exist. Each execution context is guaranteed to
 * have its own global scope.//from w  w w.  ja  v  a  2 s.  co  m
 * 
 * @param executionContext
 *        The execution context
 * @return The global scope
 */
public ScriptObject getGlobalScope(ExecutionContext executionContext) {
    ScriptObject globalScope = (ScriptObject) executionContext.getAttributes().get(NASHORN_GLOBAL_SCOPE);

    boolean init = false;
    if (globalScope == null) {
        globalScope = context.createGlobal();
        executionContext.getAttributes().put(NASHORN_GLOBAL_SCOPE, globalScope);
        init = true;
    }

    Context.setGlobal(globalScope);

    // Define services as properties in scope
    globalScope.putAll(executionContext.getServices(), false);

    if (init) {
        ScriptFunction script = context.compileScript(
                Source.sourceFor(getClass().getCanonicalName() + ".getGlobalScope", INIT_SOURCE), globalScope);
        ScriptRuntime.apply(script, globalScope);
    }

    return globalScope;
}