GenuineSounds

Script Bindings

Jun 11th, 2014
342
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package com.genuinevm.nashorn;
  2.  
  3. import javax.script.*;
  4.  
  5. public class Nashorn {
  6.  
  7.     public static void main(String[] args) throws Throwable {
  8.         ScriptEngineManager engineManager = new ScriptEngineManager();
  9.         ScriptEngine engine = engineManager.getEngineByName("nashorn");
  10.  
  11.         engine.setContext(new SimpleScriptContext());
  12.         engine.createBindings();
  13.  
  14.         Bindings scopeBindingsEngine = engine.getBindings(ScriptContext.ENGINE_SCOPE);
  15.         Bindings scopeBindingsGlobal = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
  16.  
  17.         if (scopeBindingsEngine != null) {
  18.             System.out.println("Engine Scope is enabled");
  19.             System.out.println("Size: " + scopeBindingsEngine.size());
  20.             scopeBindingsEngine.forEach((s, o) -> System.out.println(s + ": " + o));
  21.         } else
  22.             System.out.println("Global Scope is disabled");
  23.  
  24.         if (scopeBindingsGlobal != null) {
  25.             System.out.println("Global Scope is enabled");
  26.             System.out.println("Size: " + scopeBindingsGlobal.size());
  27.             scopeBindingsGlobal.forEach((s, o) -> System.out.println(s + ": " + o));
  28.         } else
  29.             System.out.println("Global Scope is disabled");
  30.     }
  31. }
  32.  
  33. // Output:
  34. // Engine Scope is enabled
  35. // Size: 0
  36. // Global Scope is disabled
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment