Example usage for jdk.nashorn.internal.objects Global Global

List of usage examples for jdk.nashorn.internal.objects Global Global

Introduction

In this page you can find the example usage for jdk.nashorn.internal.objects Global Global.

Prototype

public Global(final Context context) 

Source Link

Document

Constructor

Usage

From source file:capframework.http.core.ConfigFileParser.java

License:Apache License

void parse() {
    if (isConfigFileExist()) {
        try {/*from  ww  w .j  av  a 2  s  . com*/
            FileInputStream inputStream = new FileInputStream(file);
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            int len;
            byte[] buffer = new byte[1024];
            while ((len = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, len);
            }
            String src = outputStream.toString();
            Context context = new Context(new Options("cap"), new ErrorManager(), loader);
            JSONParser jsonParser = new JSONParser(src, new Global(context), true);
            json = (JD) jsonParser.parse();
            configs = (JD) json.get("ApplicationConfig");
            resources = (JD) json.get("ResourceMapping");
            errors = (NativeArray) json.get("ErrorHandlerMapping");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:IDE.SyntaxTree.JWebParser.java

public JWebParser(String source) {

    strSource = source;//from w w  w .  jav a 2  s.  co m

    Options opt = new Options("nashorn");
    opt.set("anon.functions", true);
    //   opt.set("parse.only", true);
    opt.set("scripting", true);

    Context context = new Context(opt, em, Thread.currentThread().getContextClassLoader());
    Context.setGlobal(new Global(context));
    Source textSource = Source.sourceFor("mySource", source);

    env = context.getEnv();//new ScriptEnvironment(opt, new PrintWriter(OutWriter), new PrintWriter(ErrorWriter) );

    nashornParser = new jdk.nashorn.internal.parser.Parser(env, textSource, em);

    // jdk.nashorn.internal.ir.FunctionCall

}