Exemplo n.º 1
0
  public static JaggeryContext clonedJaggeryContext(ServletContext context) {
    JaggeryContext shared = sharedJaggeryContext(context);
    RhinoEngine engine = shared.getEngine();
    Scriptable sharedScope = shared.getScope();
    Context cx = Context.getCurrentContext();
    ScriptableObject instanceScope = (ScriptableObject) cx.newObject(sharedScope);
    instanceScope.setPrototype(sharedScope);
    instanceScope.setParentScope(null);

    JaggeryContext clone = new JaggeryContext();
    clone.setEngine(engine);
    clone.setTenantId(shared.getTenantId());
    clone.setScope(instanceScope);

    clone.addProperty(Constants.SERVLET_CONTEXT, shared.getProperty(Constants.SERVLET_CONTEXT));
    clone.addProperty(LogHostObject.LOG_LEVEL, shared.getProperty(LogHostObject.LOG_LEVEL));
    clone.addProperty(
        FileHostObject.JAVASCRIPT_FILE_MANAGER,
        shared.getProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER));
    clone.addProperty(
        Constants.JAGGERY_CORE_MANAGER, shared.getProperty(Constants.JAGGERY_CORE_MANAGER));
    clone.addProperty(Constants.JAGGERY_INCLUDED_SCRIPTS, new HashMap<String, Boolean>());
    clone.addProperty(Constants.JAGGERY_INCLUDES_CALLSTACK, new Stack<String>());
    clone.addProperty(Constants.JAGGERY_REQUIRED_MODULES, new HashMap<String, ScriptableObject>());

    CommonManager.setJaggeryContext(clone);

    return clone;
  }